Android Question Telegram DatabaseLibrary (tdlib) error message

kostefar

Active Member
Licensed User
Longtime User
Dear All,

DonManfred asked me to create a new thread for this question, originally asked in https://www.b4x.com/android/forum/t...telegram-databaselibrary-tdlib.91640/#content so here we go:

I had a quick look at this project. I created an app_id and app_hash and added those into the example project. Also changed the phone number to the one used with my telegram account. These are the only things I changed.
But then when running it, I get:

B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
java.lang.Exception: Sub sdk_onresult signature does not match expected signature.
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:188)
    at anywheresoftware.b4a.BA$2.run(BA.java:360)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6077)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

He did however also tell me what had to be done:

B4X:
Sub SDK_onResult(tlo As Object, methodname As String)

should replace

B4X:
Sub SDK_onResult(tlo As Object)

Now I get no errors, just some data I need to look into how can be interpretated.
Was there any way I could´ve known about the updated signature? I just downloaded the files from
the other thread.
 

DonManfred

Expert
Licensed User
Longtime User
just some data I need to look into how can be interpretated.

This should give you some light....
B4X:
Sub SDK_onResult(tlo As Object, methodname As String)
    Log($"SDK_onResult(${methodname})"$)
    If methodname = "Error" Then
        Dim err As Error = tlo
        Log($"Error ${err.Code} -> ${err.message}"$)
    End If
    If tlo Is AuthorizationState Then
        Dim state As AuthorizationState = tlo
        Dim name As String = state.toString
        'name = name.Replace($"{${CRLF}}"$,"")
        name = name.SubString2(0,name.IndexOf("{")).Trim

        Log($"${state.Constructor} -> ${name}"$)
        '904720988 -> AuthorizationStateWaitTdlibParameters
        ' -1834871737 -> AuthorizationStateReady
        ' AuthorizationStateWaitTdlibParameters
        ' Send the Parameters
        If state.Constructor = 904720988 Then
            Log("Sending Parameters...")
            sdk.sendParameters(params)
        End If
        If state.Constructor = -1834871737 Then
            ' AuthorizationStateReady
            ' Login is now finished.....
            
        End If
    else if tlo Is Users Then
        Dim users As Users = tlo
        Dim usrids As List = users.userIds
        Log(usrids)
    else if tlo Is Chats Then
        Dim chats As Chats = tlo
        Dim chatids As List = chats.chatIds
        Log(chatids)
    else if tlo Is tdMessages Then
        Dim msgs As tdMessages = tlo
        If msgs.messages.Length > 0 Then
            For i = 0 To msgs.messages.Length -1
                Dim msg As Message = msgs.Messages(i)
                Log($"${msg.chatId} -> ${msg.Id}"$)
            Next
        End If
    else if tlo Is UpdateChatLastMessage Then
        Dim UpdChatLastMessage As UpdateChatLastMessage = tlo
        Log($"${UpdChatLastMessage.chatId}"$)
        Dim UpdateChatLastMessagemsg As Message = UpdChatLastMessage.lastMessage
    else if tlo Is UpdateBasicGroup Then
    else if tlo Is UpdateBasicGroupFullInfo Then
    else if tlo Is UpdateCall Then
    else if tlo Is UpdateChatLastMessage Then
    else if tlo Is UpdateFile Then   
        Dim updFile As UpdateFile = tlo
    else if tlo Is UpdateChatPhoto Then
    else if tlo Is UpdateChatTitle Then
    else if tlo Is UpdateMessageContent Then
    else if tlo Is UpdateMessageContentOpened Then
    else if tlo Is UpdateMessageEdited Then
    else if tlo Is UpdateMessageMentionRead Then
    else if tlo Is UpdateMessageSendFailed Then
    else if tlo Is UpdateMessageSendSucceeded Then
    else if tlo Is UpdateMessageViews Then
    else if tlo Is UpdateSecretChat Then
    else if tlo Is UpdateServiceNotification Then
    else if tlo Is UpdateSupergroup Then
    else if tlo Is UpdateSupergroupFullInfo Then
    else if tlo Is UpdateUnreadMessageCount Then
    else if tlo Is UpdateUserFullInfo Then
    else if tlo Is UpdateUserStatus Then
    else if tlo Is UpdateChatOrder Then
        Dim chatorder As UpdateChatOrder = tlo
        Log($"UpdateChatOrder(${chatorder.chatId}, ${chatorder.order})"$)
        sdk.GetChat(chatorder.chatId)
    else if tlo Is UserProfilePhotos Then
    else if tlo Is TdUser Then
        Dim usr As TdUser = tlo
        Log(usr)
        
    else if tlo Is UpdateNewCallbackQuery Then
        Dim qry As UpdateNewCallbackQuery = tlo
        Log($"CallbackQuery: ${qry.chatId} ${qry.Payload}"$)
        Dim payl As CallbackQueryPayloadData = qry.Payload
        Log(bc.StringFromBytes(payl.data,"utf8"))
    else if tlo Is UpdateNewChat Then
        Dim newchat As UpdateNewChat = tlo
        Log(newchat.Chat)
        'UpdateNotificationSettings
    else if tlo Is UpdateNotificationSettings Then
        Dim set As UpdateNotificationSettings = tlo
        If set.scope Is NotificationSettingsScopeChat Then
            'Dim scope As NotificationSettingsScopeChat
            'Log("Scope for ChatId: "&scope.chatId)
        End If
        If set.scope Is NotificationSettingsScopeAllChats Then
            Dim scopeall As NotificationSettingsScopeAllChats
            'Log("Scope for All Chats")
        End If
        If set.scope Is NotificationSettingsScopeBasicGroupChats Then
            Dim scopebasic As NotificationSettingsScopeBasicGroupChats
            'Log("Scope for BasicGroup Chats")
        End If
        If set.scope Is NotificationSettingsScopePrivateChats Then
            Dim scopeprivate As NotificationSettingsScopePrivateChats
            'Log("Scope for Private Chats")
        End If
        Dim setting As NotificationSettings = set.notificationSettings
        
        Log($"Setting: ${setting.toString}"$)
    else if tlo Is UpdateOption Then
        Dim optval As UpdateOption = tlo
        Dim opt As Map = optval.Value
        Log(opt)
        Log($"${optval.Name} -> ${opt.Get(optval.Name)}"$)
        tdOptions.Put(optval.Name,opt.Get(optval.Name))
        lvOptions.AddTwoLines2(optval.Name,opt.Get(optval.Name),opt)
        
    else if tlo Is UpdateNewMessage Then
        Dim newmsg As UpdateNewMessage = tlo
        Dim msg As Message = newmsg.Message
        Log(msg)
        Log(msg.senderUserId)
        Log(msg.Content)
        'senderUserId = 561471526
        If msg.senderUserId = 561471526 Then
            
        End If
    else if tlo Is UpdateUser Then
        Dim upduser As UpdateUser = tlo
        Dim user As TdUser = upduser.User
        Log(user.Username)
    else if tlo Is UpdateAuthorizationState Then
        Dim state2 As UpdateAuthorizationState = tlo
        Dim state As AuthorizationState = state2.AuthorizationState
        Dim name As String = state.toString
        name = name.SubString2(0,name.IndexOf("{")).Trim
        Log($"${state.Constructor} -> ${name}"$)
        '612103496 -> AuthorizationStateWaitEncryptionKey
        If state.Constructor = 612103496 Then
            Log("Request for DB-Encryption-Key")
            sdk.sendDatabaseEncryptionKey
        End If
        '306402531 -> AuthorizationStateWaitPhoneNumber
        If state.Constructor = 306402531 Then
            Log("Requesting Phonenumber...")
            ' Send Bottoken to login as a Bot...
            'sdk.CheckAuthenticationBotToken("561471526:AAFU63ckJ_IJBWM-ilm7q05ycwPL7kKkr0M")
            
            btnPhone.Enabled = True
            edtPhonenumber.RequestFocus
        End If
        '-483510157 -> AuthorizationStateWaitCode
        If state.Constructor = -483510157 Then
            Log("Requesting Code...")
            btnCode.Enabled = True
            edtCode.RequestFocus
        End If
        
    End If
End Sub

Was there any way I could´ve known about the updated signature?
 
Upvote 0

kostefar

Active Member
Licensed User
Longtime User
Thanks, but was that video available somewhere where I have missed it?
For the code you just posted, it´s missing references to tdoptions, bc (I get that oughta be byteconverter), chatorder, users and chats. I think I need a more recent version of the TDLex project than the one linked to in the initial thread.

Btw, should sdk.dbKey = "xcnffh43" be changed to something else, and if so what?
 
Upvote 0

kostefar

Active Member
Licensed User
Longtime User
You can use anything you want. You just can leave it. It is the password for the encryption of the underlying database where the tdlib saves everything
I do not remember tdoptions. Maybe a map or a listview

Ok thanks, I guess it´ll take a while to understand how to get this stuff working but I´ll get there!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…