B4A Library Telegram Bots API

The same library here compiled for B4A .
SMMTeleBot
Author:
SMM
Version: 1.12
  • AnswerInlineQuery
    Methods:
    • Initialize (inlineQueryId As java.lang.String, results As smm.telebot.InlineQueryResultWrapper[]) As smm.telebot.AnswerInlineQueryWrapper
    • nextOffset (nextOffset As java.lang.String) As smm.telebot.AnswerInlineQueryWrapper
    • cacheTime (cacheTime As int) As smm.telebot.AnswerInlineQueryWrapper
    • isPersonal (isPersonal As boolean) As smm.telebot.AnswerInlineQueryWrapper
    • switchPmText (switchPmText As java.lang.String) As smm.telebot.AnswerInlineQueryWrapper
    • switchPmParameter (switchPmParameter As java.lang.String) As smm.telebot.AnswerInlineQueryWrapper
    • IsInitialized As boolean
  • BaseRequest
    Methods:
    • Initialize (ba As anywheresoftware.b4a.BA) As void
    • IsInitialized As boolean
  • BaseResponse
    Methods:
    • Initialize As void
    • description As java.lang.String
    • isOk As boolean
    • errorCode As int
    • parameters As com.pengrad.telegrambot.model.ResponseParameters
    • IsInitialized As boolean
  • CallbackQuery
    Methods:
    • message As smm.telebot.cMessage
    • id As java.lang.String
    • Initialize As smm.telebot.CallbackQueryWrapper
    • gameShortName As java.lang.String
    • chatInstance As java.lang.String
    • inlineMessageId As java.lang.String
    • data As java.lang.String
    • from As smm.telebot.cUser
    • IsInitialized As boolean
  • Audio
    Methods:
    • fileSize As java.lang.Integer
    • fileId As java.lang.String
    • Initialize (ba As anywheresoftware.b4a.BA) As void
    • title As java.lang.String
    • duration As java.lang.Integer
    • performer As java.lang.String
    • mimeType As java.lang.String
    • IsInitialized As boolean
  • Chat
    Methods:
    • id As java.lang.Long
    • Initialize (ba As anywheresoftware.b4a.BA) As void
    • lastName As java.lang.String
    • title As java.lang.String
    • username As java.lang.String
    • firstName As java.lang.String
    • type As java.lang.String
    • IsInitialized As boolean
  • Contact
    Methods:
    • Initialize (ba As anywheresoftware.b4a.BA) As void
    • lastName As java.lang.String
    • phoneNumber As java.lang.String
    • userId As java.lang.Integer
    • firstName As java.lang.String
    • IsInitialized As boolean
  • Document
    Methods:
    • fileSize As java.lang.Integer
    • fileId As java.lang.String
    • Initialize (ba As anywheresoftware.b4a.BA) As void
    • fileName As java.lang.String
    • thumb As smm.telebot.cPhotoSize
    • mimeType As java.lang.String
    • IsInitialized As boolean
  • Location
    Methods:
    • Initialize (ba As anywheresoftware.b4a.BA) As void
    • longitude As java.lang.Float
    • latitude As java.lang.Float
    • IsInitialized As boolean
  • Message
    Methods:
    • voice As smm.telebot.cVoice
    • location As smm.telebot.cLocation
    • newChatMember As smm.telebot.cUser
    • migrateFromChatId As java.lang.Long
    • chat As smm.telebot.cChat
    • from As smm.telebot.cUser
    • date As java.lang.Integer
    • contact As smm.telebot.cContact
    • migrateToChatId As java.lang.Long
    • newChatTitle As java.lang.String
    • channelChatCreated As java.lang.Boolean
    • document As smm.telebot.cDocument
    • replyToMessage As smm.telebot.cMessage
    • video As smm.telebot.cVideo
    • IsInitialized As boolean
    • Initialize (ba As anywheresoftware.b4a.BA) As void
    • text As java.lang.String
    • supergroupChatCreated As java.lang.Boolean
    • newChatPhoto As anywheresoftware.b4a.objects.collections.List
    • audio As smm.telebot.cAudio
    • deleteChatPhoto As java.lang.Boolean
    • caption As java.lang.String
    • photo As com.pengrad.telegrambot.model.PhotoSize[]
    • forwardDate As java.lang.Integer
    • forwardFrom As smm.telebot.cUser
    • sticker As smm.telebot.cSticker
    • leftChatParticipant As smm.telebot.cUser
    • messageId As java.lang.Integer
    • groupChatCreated As java.lang.Boolean
  • PhotoSize
    Methods:
    • fileSize As java.lang.Integer
    • fileId As java.lang.String
    • Initialize (ba As anywheresoftware.b4a.BA) As void
    • height As java.lang.Integer
    • width As java.lang.Integer
    • IsInitialized As boolean
  • sendResponse
    Methods:
    • message As com.pengrad.telegrambot.model.Message
    • Initialize (ba As anywheresoftware.b4a.BA) As void
    • isOk As boolean
    • IsInitialized As boolean
  • Sticker
    Methods:
    • fileSize As java.lang.Integer
    • fileId As java.lang.String
    • Initialize (ba As anywheresoftware.b4a.BA) As void
    • height As java.lang.Integer
    • width As java.lang.Integer
    • thumb As smm.telebot.cPhotoSize
    • IsInitialized As boolean
  • Update
    Methods:
    • Initialize (ba As anywheresoftware.b4a.BA) As void
    • updateId As java.lang.Integer
    • editedChannelPost As smm.telebot.cMessage
    • callbackQuery As smm.telebot.CallbackQueryWrapper
    • message As smm.telebot.cMessage
    • editedMessage As smm.telebot.cMessage
    • inlineQuery As smm.telebot.InlineQueryWrapper
    • chosenInlineResult As com.pengrad.telegrambot.model.ChosenInlineResult
    • channelPost As smm.telebot.cMessage
    • IsInitialized As boolean
  • User
    Methods:
    • id As java.lang.Integer
    • Initialize (ba As anywheresoftware.b4a.BA) As void
    • lastName As java.lang.String
    • username As java.lang.String
    • firstName As java.lang.String
    • IsInitialized As boolean
  • Video
    Methods:
    • Initialize (ba As anywheresoftware.b4a.BA) As void
    • width As java.lang.Integer
    • fileId As java.lang.String
    • fileSize As java.lang.Integer
    • duration As java.lang.Integer
    • height As java.lang.Integer
    • thumb As smm.telebot.cPhotoSize
    • mimeType As java.lang.String
    • IsInitialized As boolean
  • Voice
    Methods:
    • fileSize As java.lang.Integer
    • fileId As java.lang.String
    • Initialize (ba As anywheresoftware.b4a.BA) As void
    • duration As java.lang.Integer
    • mimeType As java.lang.String
    • IsInitialized As boolean
  • InlineKeyboardButton
    Methods:
    • Initialize (text As java.lang.String) As smm.telebot.InlineKeyboardButtonWrapper
    • url (url As java.lang.String) As smm.telebot.InlineKeyboardButtonWrapper
    • switchInlineQueryCurrentChat (switchInlineQueryCurrentChat As java.lang.String) As smm.telebot.InlineKeyboardButtonWrapper
    • callbackGame (callbackGame As java.lang.String) As smm.telebot.InlineKeyboardButtonWrapper
    • switchInlineQuery (switchInlineQuery As java.lang.String) As smm.telebot.InlineKeyboardButtonWrapper
    • callbackData (callbackData As java.lang.String) As smm.telebot.InlineKeyboardButtonWrapper
    • IsInitialized As boolean
  • InlineKeyboardMarkup
    Methods:
    • Initialize (keyboard As smm.telebot.InlineKeyboardButtonWrapper[]) As void
    • IsInitialized As boolean
  • InlineQueryResultArticle
    Methods:
    • Initialize (id As java.lang.String, title As java.lang.String, messageText As java.lang.String) As void
    • hideUrl (hideUrl As java.lang.Boolean) As smm.telebot.InlineQueryResultArticleWrapper
    • url (url As java.lang.String) As smm.telebot.InlineQueryResultArticleWrapper
    • thumbHeight (thumbHeight As int) As smm.telebot.InlineQueryResultArticleWrapper
    • description (description As java.lang.String) As smm.telebot.InlineQueryResultArticleWrapper
    • thumbUrl (thumbUrl As java.lang.String) As smm.telebot.InlineQueryResultArticleWrapper
    • thumbWidth (thumbWidth As int) As smm.telebot.InlineQueryResultArticleWrapper
    • IsInitialized As boolean
  • InlineQueryResultPhoto
    Methods:
    • Initialize (id As java.lang.String, photoUrl As java.lang.String, thumbUrl As java.lang.String) As void
    • photoHeight (photoHeight As int) As smm.telebot.InlineQueryResultPhotoWrapper
    • caption (caption As java.lang.String) As smm.telebot.InlineQueryResultPhotoWrapper
    • title (title As java.lang.String) As smm.telebot.InlineQueryResultPhotoWrapper
    • description (description As java.lang.String) As smm.telebot.InlineQueryResultPhotoWrapper
    • photoWidth (photoWidth As int) As smm.telebot.InlineQueryResultPhotoWrapper
    • IsInitialized As boolean
  • InlineQueryResult
    Methods:
    • Initialize (type As java.lang.String, id As java.lang.String) As void
    • replyMarkup (replyMarkup As smm.telebot.InlineKeyboardMarkupWrapper) As smm.telebot.InlineQueryResultWrapper
    • inputMessageContent (inputMessageContent As smm.telebot.InputMessageContentWrapper) As smm.telebot.InlineQueryResultWrapper
    • IsInitialized As boolean
  • InlineQuery
    Methods:
    • id As java.lang.String
    • Initialize As void
    • location As smm.telebot.cLocation
    • query As java.lang.String
    • from As smm.telebot.cUser
    • offset As java.lang.String
    • IsInitialized As boolean
  • InputMessageContent
    Methods:
    • Initialize As void
    • IsInitialized As boolean
  • InputTextMessageContent
    Fields:
    • PARSEMODE_HTML As java.lang.String
    • PARSEMODE_MARKDOWN As java.lang.String
    Methods:
    • Initialize (messageText As java.lang.String) As void
    • parseMode (parseMode As java.lang.String) As smm.telebot.InputTextMessageContentWrapper
    • disableWebPagePreview (disableWebPagePreview As java.lang.Boolean) As smm.telebot.InputTextMessageContentWrapper
    • IsInitialized As boolean
  • KeyboardButton
    Methods:
    • requestContact (requestContact As boolean) As smm.telebot.KeyboardButtonWrapper
    • Initialize (ba As anywheresoftware.b4a.BA, text As java.lang.String) As void
    • requestLocation (requestLocation As boolean) As smm.telebot.KeyboardButtonWrapper
    • IsInitialized As boolean
  • ReplyKeyboardMarkup
    Methods:
    • resizeKeyboard (resizeKeyboard As boolean) As smm.telebot.ReplyKeyboardMarkupWrapper
    • Initialize (ba As anywheresoftware.b4a.BA, keyboard As java.lang.String[]) As smm.telebot.ReplyKeyboardMarkupWrapper
    • selective (selective As boolean) As smm.telebot.ReplyKeyboardMarkupWrapper
    • oneTimeKeyboard (oneTimeKeyboard As boolean) As smm.telebot.ReplyKeyboardMarkupWrapper
    • IsInitialized As boolean
  • SMMTeleBot
    Events:
    • sent (result As Message)
    • _updates (updates As List)
    Fields:
    • PARSEMODE_HTML As java.lang.Object
    • CHAT_ACTION_UPLOAD_DOCUMENT As com.pengrad.telegrambot.model.request.ChatAction
    • CHAT_ACTION_RECORD_AUDIO As com.pengrad.telegrambot.model.request.ChatAction
    • CHAT_ACTION_TYPING As com.pengrad.telegrambot.model.request.ChatAction
    • CHAT_ACTION_FIND_LOCATION As com.pengrad.telegrambot.model.request.ChatAction
    • CHAT_ACTION_UPLOAD_AUDIO As com.pengrad.telegrambot.model.request.ChatAction
    • CHAT_ACTION_UPLOAD_VIDEO As com.pengrad.telegrambot.model.request.ChatAction
    • CHAT_ACTION_RECORD_VIDEO As com.pengrad.telegrambot.model.request.ChatAction
    • PARSEMODE_MARKDOWN As java.lang.Object
    • CHAT_ACTION_UPLOAD_PHOTO As com.pengrad.telegrambot.model.request.ChatAction
    Methods:
    • Initialize (ba As anywheresoftware.b4a.BA, Token As java.lang.String, EventName As java.lang.String, connectTimeout As int, writeTimeout As int, readTimeout As int) As void
    • sendVideo (chatId As java.lang.String, folder As java.lang.String, filename As java.lang.String, caption As java.lang.String, reply_to_message_id As java.lang.Integer, bForceReply As boolean, bReplyKeyboardHide As boolean, duration As int) As void
    • AnswerCallbackQuery (callbackQueryId As java.lang.String, text As java.lang.String, url As java.lang.String, showAlert As boolean, cacheTime As int) As smm.telebot.BaseResponseWrapper
    • removeGetUpdatesListener As void
    • SendChatAction (chatId As java.lang.Object, action As java.lang.String) As void
    • sendMessage (chatId As java.lang.String, MessageText As java.lang.String, replyToMessageId As int, parsemode As java.lang.String, replyMarkup As smm.telebot.InlineKeyboardMarkupWrapper) As void
    • AnswerInlineQuery (inlineQuery As smm.telebot.InlineQueryWrapper, r1 As smm.telebot.InlineQueryResultWrapper, cacheTime As int, isPersonal As boolean, offset As java.lang.String, pmParam As java.lang.String, pmText As java.lang.String) As smm.telebot.BaseResponseWrapper
    • CreateInlineKeyboardMarkup (keys As smm.telebot.InlineKeyboardButtonWrapper[]) As smm.telebot.InlineKeyboardMarkupWrapper
    • sendPhoto (chatId As java.lang.String, folder As java.lang.String, filename As java.lang.String, caption As java.lang.String, reply_to_message_id As int, bForceReply As boolean, bReplyKeyboardHide As boolean) As void
    • SetWebhookListener (url As java.lang.String, allowedUpdates As java.lang.String, maxConnections As int) As void
    • GetUpdatesList (offset As int, limit As int, timeout As int) As void
    • sendMessage2 (chatId As java.lang.String, MessageText As java.lang.String, replyToMessageId As int, parsemode As java.lang.String, replyMarkup As smm.telebot.ReplyKeyboardMarkupWrapper) As void
 

Attachments

  • B4ASMMTeleBot112.zip
    294.2 KB · Views: 1,054
  • SMMTeleBot13.zip
    35.8 KB · Views: 905
Last edited:

PhiloSophical

Member
Licensed User
Longtime User
Is there anyone out there willing to share a demo app showing how this library can be used together with the necessary parameters to establish connections/registrations messaging etc?

A Hello World type app maybe?

Tutorial?

Thanks
 

Ohanian

Active Member
Licensed User
Longtime User
Hi,

First of all create a bot and get your token from @BotFahter

then compile and run the sample.
Join your newly created bot and send some message.

Here's a hello world sample :
B4X:
AddPermission(android.permission.INTERNET) 

#Region  Project Attributes 
    #ApplicationLabel: TeleBot
    #VersionCode: 1
    #VersionName: 1.0
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes 
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

    Dim Bot As SMMTeleBot
   
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")

    Bot.Initialize(YOUR_TOKEN_FROM_BOTFATHER, "BOT", 120, 120, 120)   
    Bot.getUpdatesList(0,20,60)
   
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub BOT_updates(updates As List)
    If updates.IsInitialized Then
        Try
            Log(updates.Size)
           
            For up = 0 To updates.Size - 1
                Dim Update As Update = updates.Get(up)
                Dim Message As Message = Update.message
                Bot.sendMessage(Message.chat.id, "Hello World", 0, 0, Null)
            Next       
        Catch
            Log(LastException)
        End Try       
    End If   
End Sub

Sub BOT_sent(result As Message)
   
End Sub
 

PhiloSophical

Member
Licensed User
Longtime User
Couple of things that are problems on the Hello World example

AddPermission(android.permission.INTERNET) - causes an undeclared variable error
I presume this is a function in your own shared code somewhere.

If I get rid of this by commenting out I am left with a compiler error:-
Cannot find: C:\Program Files\Anywhere Software\Basic4android\libraries\okhttp-3.3.1.jar

I have solved this by finding okhttp-3.3.1.jar in Github and installing in the Internal Libraries folder.

This now works.

Having had a look at the functionality of the SMMTelebot - it seems to be a small fraction of the Telegram API so doesn't lend itself to build a real world app around it - maybe someone has the skills to build on this. I sadly haven't.

Thanks Anyway.
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
This is my testing not good sample from B4J
I think you can learn from it
Please note event name is process instead of updates and that event is for webhook
B4X:
'Non-UI application (console / server application)
#Region Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
#End Region

Sub Process_Globals
    Dim server As Server
    Private domain As String="mydomain.duckdns.org"
    Private token As String="mydomaintoken"
    Private time ,update As Timer
    Private tele As SMMTeleBot
    Private smmtoken As String="telegrambottoken"
    Private off As Long
    Private allin As Map
    Dim thum As String
End Sub

Sub AppStart (Args() As String)
    allin.Initialize
    tele.Initialize(smmtoken,"tg",10000,10000,10000)
    tele.SetWebhookListener("127.0.0.1:8080","" , 40)

    SetLoggingLevel("OFF")
    time.Initialize("UpdateIp",1000*60*10)

    server.Initialize("server")
    server.Port=51051
    
    server.Start
    UpdateIp_Tick

    StartMessageLoop
    
    
    
    
    
End Sub

Sub getUp_tick
    tele.GetUpdatesList( off+1,1000,9000  )
    Log("ticking and off = "&off)
End Sub
Sub tg_sent(m As Message)
    Log("tg_sent"&m.chat.id)
    Log("tg_sent"&m.messageId)
'    If m.IsInitialized Then
        
    
    If m.replyToMessage.IsInitialized Then
        
    
        If m.replyToMessage.text.Length<3 Then
            If m.replyToMessage.from.username="shujamu" Then
                Log("here")
            
            End If
            Dim btn,btn2 As InlineKeyboardButton
            btn.Initialize("good").callbackData("returnedthing")
            btn2.Initialize("one"&"").callbackData("nothing")
            Dim kk As InlineKeyboardMarkup
            kk.Initialize(Array As InlineKeyboardButton(btn,btn2))
            tele.sendMessage( m.chat.id,DateTime.Time(DateTime.Now), m.messageId ,"HTML",kk)
            Log("tg_sent "&m)
        End If
        tele.DeleteMessage(m.chat.id ,m.messageId)
    End If
'    End If
End Sub
Sub tg_process(updates As List)
    #IgnoreWarnings :7
    
    If updates.IsInitialized Then
        For up = 0 To updates.Size-1
            Dim u As Update=updates.Get(up)
            Log("Update: "&u)
        
            If u.callbackQuery.IsInitialized Then
                Dim callbackquer As CallbackQuery =u.callbackQuery
                Log("Query Back is "&callbackquer)
                Log(callbackquer.chatInstance)
                If IsNumber(callbackquer.data) Then
                
                End If

                Log(callbackquer.from.id)
                tele.sendMessage(callbackquer.from.id,DateTime.Time(DateTime.Now), -1 ,tele.PARSEMODE_MARKDOWN,Null)
                Log(callbackquer.gameShortName)
                Log(callbackquer.id)
                Log(callbackquer.inlineMessageId)
                Log(callbackquer.message)
                tele.AnswerCallbackQuery(callbackquer.id,"","",False,1)
            
            End If
            If u.IsInitialized Then
                off=u.updateId
                If u.inlineQuery.IsInitialized Then
                    Log("u.inlineQuery")

            
                    

                    Log("Inline query: "&u.inlineQuery.query)
                    Dim q As String =u.inlineQuery.query.Trim
                    If q.Length>0 Then

                        doload_article(q.Replace(" ","%20"),u.inlineQuery)
                    End If


                End If
            
            End If
            If u.message.IsInitialized Then
            
            
                If u.message.text<>Null Then
                    If u.message.replyToMessage.IsInitialized=True Then
                        Log(u.message.replyToMessage.from.username)
                        If u.message.replyToMessage.from.username="SMMtelebot" Then
                            Log("YES")
                            tele.EditMessageText(  u.message.replyToMessage.chat.id,u.message.replyToMessage.messageId,"WAS edited",tele.PARSEMODE_HTML,False)
                        Else
                            Log("NO")
                        End If
                
                    End If
                    If u.updateId>= off Then
                        off=u.updateId
                        If   u.message.text.Contains("butons") Then
                            Log(u.message.text)
                            Dim kbtn,kbtn2 As KeyboardButton
                            kbtn.Initialize("good"&"")
                            
                            kbtn2.Initialize("one"&"\u26BD")
            
                            Dim g As ReplyKeyboardMarkup
                            g.Initialize(Array   As String  ("A","B","C")).oneTimeKeyboard(True).selective(False).resizeKeyboard(True)
                            tele.sendMessage2(u.message.chat.id ,""  , 0,tele.PARSEMODE_HTML,  g)'
                        Else
                            Log("Not butons")
                            Dim btn,btn2,btn3 As InlineKeyboardButton
                            btn.Initialize("ClickMe").callbackData("returnedthing")
                            btn2.Initialize("Cancel").url("https://telegram.org").callbackData("callback_data")
                            btn3.Initialize("What?").callbackData("nothing")
            
                            tele.sendMessage( u.message.chat.id,  "BotMessage here", 0 ,"HTML",tele.CreateInlineKeyboardMarkup(Array As InlineKeyboardButton (btn,btn2,btn3)))
                        End If
'       
'       
                    End If
                End If
            End If
        Next
    End If
End Sub



Sub doload_article(q As String,il As InlineQuery)
    thum ="https://telegram.org/img/t_logo.png"
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Tag=il

    Dim rul As String="https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts|pageimages&exintro=&explaintext=&titles="&q.Replace(" ","%20")
    j.Download(rul)
    Wait For(j) JobDone(j As HttpJob)
    If j.Success Then
        
        
        Dim inline As InlineQuery=j.Tag
        Dim art As InlineQueryResultArticle
        Dim jsn As JSONParser
        jsn.Initialize(j.GetString)
        Log(j.GetString)
        Dim jnmap As Map =jsn.NextObject
        If jnmap.IsInitialized Then
                
            Dim querymap As Map=jnmap.Get("query")
            Dim pagesmap As Map=querymap.Get("pages")
            Dim numbersmap As Map=pagesmap.Get(pagesmap.GetKeyAt(0))
            
            For Each k In numbersmap.Keys
                Log(k)
            Next

            Dim thing As String= ""
            If numbersmap.ContainsKey("extract") Then
            
                thing=numbersmap.Get("extract")
                Log(numbersmap.Get("title"))

            End If
            If numbersmap.ContainsKey("thumbnail")  Then
                Dim thumbmap As Map =numbersmap.Get("thumbnail")
                thum= thumbmap.Get("source")
            End If
            If thing.Length>0  Then
'                    Log("thing "&thing)
                Dim title As String =thing'.SubString2(0,Min(thing.Length,10))
                art.Initialize(inline.id,title ,thing.Replace(CRLF," "))
                art.thumbUrl(thum)
            Else
                
                art.Initialize(inline.id, "Found nothing","Nothin)
                art.thumbUrl(thum)
            End If
                
        Else
            Log("Else")
            art.Initialize(inline.id,thing,thing)

        End If
            

        
            
        tele.AnswerInlineQuery(  inline,art  ,  3000,True  ,"","", "" )

        
        
        
        
        
        
    End If
    j.Release
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub


Sub SetLoggingLevel(level As String)
    '  Log("Set Logging Level to " & level.ToUpperCase)
    If level.Length = 0 Then Return
    Dim joJ As JavaObject  'Jetty Object
    Dim joP As JavaObject  'Properties Object
    joP.InitializeNewInstance("java.util.Properties", Null)
    joP.RunMethod("setProperty", Array("org.eclipse.jetty.LEVEL", level.ToUpperCase))
    joJ.InitializeNewInstance("org.eclipse.jetty.util.log.StdErrLog", Array("JettyLog", joP))
End Sub


Sub UpdateIp_Tick
    Log("UpdateIp_Tick")
    Dim j As HttpJob
    j.Initialize("j", Me)
    j.Tag=Null
    Try
        j.Download2("http://www.duckdns.org/update", Array As String("domains", domain, "token", token, _
        "ip", ""))
    Catch
        Log(LastException)
    End Try
    
End Sub
 

Nickle

Member
Licensed User
Longtime User
Great Work. Is there a Similar Library for FaceBook Bot or can same library be used for Facebook.
 

Erind Jushaj

Member
Licensed User
Is there a way to use the DeleteMessage command? I want to delete some messages my bot send to a certain reciever but I DeleteMessage is not part of the library it seems..
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Is there a way to use the DeleteMessage command? I want to delete some messages my bot send to a certain reciever but I DeleteMessage is not part of the library it seems..
Really sorry
I worked on this library a bit more but did not publish the update although I think I have added DeleteMessage
Now my laptop is not working :( I will try to have some time to fix it and publish the latest update .
 

Erind Jushaj

Member
Licensed User
Please check version SMMTeleBot13.zip on first post

Thanks a lot. Now I dont know wheather I should ask it here or open a new thread but I cant seem to make the DeleteMessage method work.
I think I am doing something wrong. I would like to delete for example all last 10 messages my Bot sent to my own Telegramaccount "xxxx".
Do you have a short example of how this method should work?

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim bot As SMMTeleBot
'    Private Button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
    bot.Initialize("yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy", "BOT", 120, 120, 120)
    bot.sendMessage("xxxxxxxxx", "test", 0, 0, Null)
    bot.DeleteMessage("xxxxxxxxx",2)
    
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
I guess you are getting a MessageId back when you post a Message.
Remember the IDs. Also remember the ChatID

Based on #5 of this thread:

Both are needed to Delete
B4X:
 tele.DeleteMessage(m.chat.id ,m.messageId)
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Thanks a lot. Now I dont know wheather I should ask it here or open a new thread but I cant seem to make the DeleteMessage method work.
I think I am doing something wrong. I would like to delete for example all last 10 messages my Bot sent to my own Telegramaccount "xxxx".
Do you have a short example of how this method should work?

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim bot As SMMTeleBot
'    Private Button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
    bot.Initialize("yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy", "BOT", 120, 120, 120)
    bot.sendMessage("xxxxxxxxx", "test", 0, 0, Null)
    bot.DeleteMessage("xxxxxxxxx",2)
   
End Sub
When a message is sent it is returned to eventname_sent event you can for example add it or (its id ) to a list so you can delete when you want
 

Erind Jushaj

Member
Licensed User
Please check version SMMTeleBot13.zip on first post

Hi I think you forgot to wrap something in the new library.

I get the following error when I try to use your new library: Cannot find: "C:\Program Files (x86)\Anywhere Software\Basic4android\libraries\java-telegram-bot-api-full.jar"
Also when I opened the .jar file with Winrar I noticed that the Okhhtp3 and Com maps are missing which were present in your first 112 version. Do you please mind to have a look at this?

Many thanks
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Hi I think you forgot to wrap something in the new library.

I get the following error when I try to use your new library: Cannot find: "C:\Program Files (x86)\Anywhere Software\Basic4android\libraries\java-telegram-bot-api-full.jar"
Also when I opened the .jar file with Winrar I noticed that the Okhhtp3 and Com maps are missing which were present in your first 112 version. Do you please mind to have a look at this?

Many thanks
Sorry

https://drive.google.com/file/d/1t6b8j77POKhcgo_cuT9pwkx_Ne0MgygG/view?usp=sharing
 

Blueforcer

Well-Known Member
Licensed User
Longtime User
Thank you for this lib!.
At the moment its hard to understand how to use it correctly.
For now im able to send messages. But i dont know how to recieve some, so i can control my App via telegram.
Do i need to always ask for updates via timer to get the last message?
Or can i do this with Webhooks?
Any example available?
 
Last edited:

Blueforcer

Well-Known Member
Licensed User
Longtime User
Thank you, So now im getting the latest message once, shortly after sending

B4X:
Sub tele_updates(updates As List)
    If updates.IsInitialized Then
        Dim update As Update=updates.Get(updates.size-1)
         Dim Message As Message = update.message
         ID=update.updateId
         Log(Message.text)
    End If
End Sub

Sub update_tick
    bot.GetUpdatesList(ID+1,1,9000)
End Sub

But after that, each call of GetUpdatesList throws an catched error
Exception in getting updates :null

That wouldn't be so bad if the log wasn't saved to a file and is visible in another menu. So the user sees every 1 second this errors in the log. can this somehow be switched off? Or is it possible to prevent this error?
 
Top