B4J Library [BETA] jTelegramBot - Create your own Telegram Bot

jTelegramBot is a partially wrapper build on this github project.
This project is licensed under The MIT License (MIT). See LICENSE for more details.

Note that the development has stopped. If you miss something in the lib you need to add it by yourself. The Source is attached to this post.

links about Telegram Bots

JTelegramBot
Author:
DonManfred (Wrapper)
Version: 0.31

Setup:
- To get the Example running you first need to adapt the Initialize line with your Bots Name and ApiToken.
B4X:
Sub AppStart (Args() As String)
    jtb.Initialize("JTB","yourbotname","youtbottoken")
    glmap.Initialize
    jtb.startAsync
    StartMessageLoop
End Sub
- The Example is using Static Filenames for the Document, MP3, Photo, Sticker send.
Make sure to adapt the path and Filenames to match Files you want to use.

B4X:
    If message.Text = "/buttons" Then
        Dim mark As InlineKeyboardMarkup
        mark.initialize(jtb.CreateDummyKeyboard)
        Dim buttons As Message = jtb.sendMessage(jtb.byId(from.Id),"Click the Button!","MARKDOWN",False,False,message.MessageId,mark)
        glmap.Put(buttons.MessageId,buttons)
    else If message.Text = "/location" Then
        jtb.sendChatAction(jtb.byId(from.Id),jtb.ChatActionFIND_LOCATION)
        jtb.sendLocation(jtb.byId(from.Id),50.8337006,6.441118,False,message.MessageId,Null)
    else If message.Text = "/url" Then
        jtb.sendMessage(jtb.byId(from.Id),"[jTelegramBot Thread](https://www.b4x.com/android/forum/threads/jtelegrambot.103778/#post-650611)","MARKDOWN",False,False,message.MessageId,Null)
    else If message.Text = "/plainurl" Then
        bld.sendMessage(chat.Id,"Link without Preview [jTelegramBot Thread](https://www.b4x.com/android/forum/threads/jtelegrambot.103778/#post-650611)",message.MessageId,False,True,Null,jtb.parsemodeMARKDOWN)
    else If message.Text = "/text" Then
        jtb.sendMessage(jtb.byId(from.Id),$"Testtext <b>Bold</b>, <i>Italic</i>
    new row..."$,"HTML",True,False,message.MessageId,Null)
    else If message.Text = "/document" Then
        jtb.sendChatAction(jtb.byId(from.Id),jtb.ChatActionUPLOAD_DOCUMENT)
        jtb.sendDocument(jtb.byId(from.Id),jtb.MediaByFile(File.DirApp,"mydocument.zip"),"DocumentCaption",False,message.MessageId,Null)
    else If message.Text = "/photo" Then
        jtb.sendChatAction(jtb.byId(from.Id),jtb.ChatActionUPLOAD_PHOTO)
        jtb.sendPhoto(jtb.byId(from.Id),jtb.MediaByFile(File.DirApp,"myimage.png"),"DocumentCaption",False,message.MessageId,replbld.forceReply)
    else If message.Text = "/audio" Then
        jtb.sendChatAction(jtb.byId(from.Id),jtb.ChatActionUPLOAD_VIDEO)
        jtb.sendAudio(jtb.byId(from.Id),jtb.MediaByFile(File.DirApp,"myaudio.mp3"),223,"Fleedwood Mac","Eyes of the World",False,message.MessageId,replbld.forceReply)
    else If message.Text = "/sticker" Then
        jtb.sendSticker(jtb.byId(from.Id),jtb.MediaByFile(File.DirApp,"mysticker.webp"),False,message.MessageId,Null)
    else If message.Text = "/start" Then
        jtb.sendMessage(jtb.byId(from.Id),$" Hello ${chat.Username}
`Command   | Result
----------|-------------------------
/location | Returns a Locationobject
/document | Returns a Document
/photo    | Returns a Photo
/audio    | Returns a Audiofile
/url      | Returns a URL with Preview
/plainurl | Returns a URL without Preview
/buttons  | Shows some buttons To Click on
`
Thank you For choosing Me :-)"$,"MARKDOWN",False,False,message.MessageId,Null)

In this example you need to replace the following Filereferences:
- mydocument.zip
- myimage.png
- myaudio.mp3
- mysticker.webp

Due to the Size of the needed Additional JARs they can be downloaded
HERE.

For any Question/Issue you have please Create a new Thread in the B4J Questionsforum.
 

Attachments

  • BotExample.zip
    2.5 KB · Views: 1,124
  • JTelegramBotV0.31.zip
    256.4 KB · Views: 890
  • src.zip
    188 KB · Views: 797
Last edited:

DonManfred

Expert
Licensed User
Longtime User
how can pinn a message ???
missing pin message method
1. You should always create a new thread in the b4j questionsforum for any Question you have. Just make sure to note that you are using jTelegramBot library version xx

See my comment from #1!
For any Question/Issue you have please Create a new Thread in the B4J Questionsforum.


2. Seems it is not implemented in the Github project. I could not find anything about Pinning in the Sources.
 

ivanomonti

Expert
Licensed User
Longtime User
Hi, sorry in advance, I'm reading a lot of posts and I got confused, what I need to install and how to start using this library?
 

DonManfred

Expert
Licensed User
Longtime User
As written in #1 of this thread you should create a new Thread for any question/issue you have in the Questionsforum.

The answer is:
An example is attached to the 1st post,
the library is there too. You need to copy it to the additional libs folder.
Also note to download the additional files (See the DOWNLOAD link in #1) and copy them to the additional libs folder too.
 

js1234

Member
Licensed User
Longtime User
Hi
Can bot read messages from Privat Telegram channel (only read channel)?
 

DonManfred

Expert
Licensed User
Longtime User
Can bot read messages from Privat Telegram channel (only read channel)?
1. You should ALWAYS(!) create a new thread in the Questionsforum for any question/issie you have! Posting to existing threads is a Mistake.
2. If the bot is added to a channel then he gets all Messages in this channel. If you send a private message to the bot the bot can read this private message and respond to it using the channel id.
 

jinyistudio

Well-Known Member
Licensed User
Longtime User
Hi
what is message.MessageId ?

Next version will have a possibility to change the InlineKeyboard. In the 1st version only a dummykeyboard is generated inside the library which could not be changed.

B4X:
        Dim ibld As InlineKeyboardButtonBuilder
        Dim mark As InlineKeyboardMarkup
        mark.initialize(ibld.Initialize.newRow.newButton("1").withCallbackData("BTN1").newButton("2").withCallbackData("BTN2").newButton("3").withCallbackData("BTN3").newRow.newButton("Google").withUrl("https://www.google.com").newRow.build)
        Dim buttons As Message = jtb.sendMessage(jtb.byId(from.Id),"Click the Button!","MARKDOWN",False,False,message.MessageId,mark)

tbanswer021.png
 

prajinpraveen

Active Member
Licensed User
Longtime User
Hello @DonManfred , Firstly thank you for wrapping this library. I have been playing around with this for the last 3 days and I believe there are a lot of things that could be done using a bot.

Question if I may ask. the Original library is about 4 years since any changes (not complaining :)) and I am not sure if the Author is maintaining it. I would love to integrate this into my application. Would you still recommend using it for a long term client-facing production application?

Thank you for the source, just checking if it is the latest?

Have a nice day!
 

DonManfred

Expert
Licensed User
Longtime User
in v 0.31
bad class file: C:\Program Files (x86)\Anywhere Software\B4J\libraries\jtelegrambot.jar(de/donmanfred/JTBwrapper.class)
class file has wrong version 55.0, should be 52.0
Please remove or make sure it appears in the correct subdirectory of the classpath.

help please
 

Toky Olivier

Active Member
Licensed User
Longtime User
Hello, I tried your bot in Telegram, is it normal like this please? No response from the bot. It's the first time I used Telegram.
IMG_20200721_042148.jpg
Thank you
 

DonManfred

Expert
Licensed User
Longtime User
Hello, I tried your bot in Telegram, is it normal like this please?
The Bot example does not have any UI.
You need to check the log for any events which are raised.

Based on the Screenshot the messages did arrived at the Bot. I expect it to be a Screenshot from Telegramclient.

Run the Bot from the Ide and monitor the logs, see what message is coming in and how your Bot is handling this Message.

I can not help more as you did not provided any useful informations.

Away from that you should ALWAYS create a new Thread for any Question/Issue you have in the Quetionsforum.
Make sure to post all relevant code from your Bot to see what you are doing and how.
Best is to upload a small project (without your token)....
 
Last edited:
Top