B4J Library Telegram Bots API

Payne

New Member
Licensed User
Longtime User
I am new to B4X group. It's very hard for me to start big project. If someone could share a more complete project code , I think all beginners are very appreciate. The beginner can grow up soon by "learn","copy" from giant of you.

thanks advance for all of your help on my B4x road.
 

Blueforcer

Well-Known Member
Licensed User
Longtime User
Yes it would be very nice to have a demo code. Because your "old" sample code only checks the last messages after start. dont know how to send or recieve a message
Also i dont know how to send a message or use the customkeyboards.
It would be also nice , if you documenting you lib. There are so many Methods etc and i dont know what it is and where or how to use it
 

Blueforcer

Well-Known Member
Licensed User
Longtime User
Im getting the latest message once, shortly after sending with

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

'1sec Timer
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

how can i avoid this?
 

DonManfred

Expert
Licensed User
Longtime User
I think you are using it wrong.

GetUpdatelist should be used with the last ID given by a recent Update.
ID=update.updateId
THIS is the id which should be used.

Additionally i would try it with a 10 Seconds interval or so. Just to make sure you get it working correctly. You may lower it when everything is working as expected.
Note that you are sending a lot of requests to Telegram service with this interval (1 sec)...
 

DonManfred

Expert
Licensed User
Longtime User
To not further fill this thread (we should have created a new thread in the questionsforum).
I suggest to switch to questionsforum.

I started playing (wrapping ) with another Botimplementation: jTelegramBot.
It is using a "longpollingBot" which raises an Event if a new Update comes in. (No need for a timer based request!)
This is the progress so far. For any questions/want to try please create a new Thread in the questionsforum and i´ll answer there. It is another library than the one from this thread so we should talk about in another thread ;-)
B4X:
Sub JTB_onMessageReceived(api As Object, id As Int, msg As Object)
    Log($"JTB_onMessageReceived( ${id}, ${msg}"$) 
    Dim message As Message = msg
    Log($"MessageFrom: ${message.From}"$)
    Dim from As User = message.From
    Log($"FromFirstName: ${from.FirstName}"$)
    Log($"FromLastName: ${from.LastName}"$)
    Log($"FromUserName: ${from.Username}"$)
    Log($"FromID: ${from.Id}"$)
    Log($"FromisBot: ${from.isBot}"$)
    Log($"FromLanguageCode: ${from.LanguageCode}"$)
  
    Log($"MessageChat: ${message.Chat}"$)
    Dim chat As Chat = message.Chat
    Log($"ChatFirstName: ${chat.FirstName}"$)
    Log($"ChatFirstName: ${chat.LastName}"$)
    Log($"ChatUserName: ${chat.Username}"$)
    If chat.Title <> Null Then
        Log($"ChatTitle: ${chat.Title}"$)
    End If
    Log($"ChatID: ${chat.Id}"$)

    If message.Caption <> Null Then
        Log($"MessageCaption: ${message.Caption}"$)
    End If
    If message.Contact <> Null Then
        Log($"MessageContact: ${message.Contact}"$)
    End If
        Log($"MessageDate: ${message.Date}"$)
    If message.Entities <> Null Then
        Log($"MessageEntities: ${message.Entities}"$)
    End If
    Log($"MessageText: ${message.Text}"$)
End Sub

PS: Der einfachheit halber evtl. im Deutschen Forum
For the easyness eventually in the german Forum
 
Last edited:

hears

Active Member
Licensed User
Longtime User
Bot.sendMessage(-1001369534349, "Hello World", 0, 0, Null)
i have try send message is ok,do not know how to recieve message

Can you please give me simple example for sending and receiving messages?
 

rasoolarj77

New Member
Thanks
But this method has only two parameters
1-chat id
2-text
I want to use other library but need i see errors for not finding necessary .jar file
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Thanks
But this method has only two parameters
1-chat id
2-text
I want to use other library but need i see errors for not finding necessary .jar file
I have uploaded version 1.15 to the first post
Please download
I work on this wrapper from time to time for my own purposes so I might have added some undocumented changes and features
 

ivanomonti

Expert
Licensed User
Longtime User
Hi, this library could do for me but I see it is dated 2016, I was wondering if it is still valid or Telegram has changed APIWeb?

I should do an implementation on my management and it could be good for me, it would be nice to be able to do it also to WhastApp, but if this works I'd be happy already.

is it possible to have a simplified demo project, login + user list and how to send messages... as well as a simple library installation manual?

B4J 8.10
Java 8
Windows
 
Last edited:

somed3v3loper

Well-Known Member
Licensed User
Longtime User
This is a telegram bot api library I don't think there is a login
I've uploaded version 1.15 to the first post
Please note that this library has a lot of functions and objects and I just wrap part of them

There is a simple demo hers
 

DonManfred

Expert
Licensed User
Longtime User
how send a photo or document with this library?
Start with looking at the available methods in the docu?

 

DonManfred

Expert
Licensed User
Longtime User
no methods to send document file for example zip or txt ...
So i guess sending a DOCUMENT is not implemented in this Library.

You can use
Here you are able to send a Document (ZIP, TXT, XLS, whatever). It is implemented in the Example.
Note that this library is not maintained as i do not use Telegram any longer.
 

seyed_27

Member
Can this Library be used in the b4a?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…