B4J Question jtelegram bot "newContactButton" problem

behnam_tr

Member
hi

in jtelegrambot lib

i use this code for get user phone number

B4X:
Dim ib As KeyboardButtonBuilder
        ib.Initialize
        Dim mark As ReplyKeyboardMarkup
        mark.initialize(ib.newRow.newButton("").newContactButton("send phone").newRow.build,True,True,False)
but after user send i cant split phone number because

Dim tell As Message =message.Contact get error

log(message.Contact) is ok and
result >>> Contact{phoneNumber='+98xxxxxxxxx', firstName='-----', lastName='null', userId=105526931}

i think should be like this > Dim tell As contact =message.Contact but contact is missing

thanks for all helps
 
Last edited:

behnam_tr

Member
i receive this message on b4j with this code "log(message.Contact)"

Contact{phoneNumber='+98xxxxxxxxx', firstName='-----', lastName='null', userId=105526931}

i want to split and put in string varible coantact.phoneNumber

how can i do this ??
 

behnam_tr

Member
thanks
after use i get this error

B4X:
Dim c As Contact
    c.Initialize("")
    c=message.Contact
    Dim tell As String= c.PhoneNumber
B4X:
java.lang.RuntimeException: Object should first be initialized (Contact).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:32)
    at de.donmanfred.Contactwrapper.getPhoneNumber(Contactwrapper.java:48)
    at b4j.example.main._jtb_onmessagereceived(main.java:228)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
    at anywheresoftware.b4a.BA$3.run(BA.java:247)
    at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
    at java.lang.Thread.run(Thread.java:748)
 

DonManfred

Expert
Licensed User
this is working for me. i send a contact to my bot

B4X:
    If message.Contact <> Null Then
        Log($"MessageContact: ${message.Contact}"$)
        Dim cont As Contact = message.Contact
        Log($"ContactFirstname: ${cont.FirstName}"$)
        Log($"ContactLastName: ${cont.LastName}"$)
        Log($"ContactPhoneNumber: ${cont.PhoneNumber}"$)
        Log($"ContactUserId: ${cont.UserId}"$)
    End If
 
Top