B4J Question several apps with the same jTelegramBot

peacemaker

Expert
Licensed User
Longtime User
Hi, All

If we need to send notification to users from a B4J app by Telegram - we need a bot app.
We should collect chat_ids of each user.
But if the project has several sections (maybe topics) - each user may need to be registered also in these several sections, separately.
So, messages to each user should be from different sections (at least different subjects).

1) How should this structure be released in the single project bot ?
2) Is it possible to build the same bot (the same API key) into ... several B4J apps that each sends messages only regarding its topic ?
 

MichalK73

Well-Known Member
Licensed User
Longtime User
1) How should this structure be released in the single project bot ?
I have it done that when I first initiate the interaction with the bot /start, it reads the chat_id and writes to various databases (in your case, to every other project). You can do this physically, e.g. to a SQLite database on your machine, or through the project's API mechanism.
Sending a message to the bot for a given user by chat_id is done by the https telegram API.
B4X:
public Sub sendToBot(tid As String,message As String)
    If tid.Length > 3 Then
        Dim tok As String = Main.config.Get("API_TELEGRAM")
        Dim web As HttpJob
        web.Initialize("",Me)
        web.Download2($"https://api.telegram.org/bot${tok}/sendMessage"$, Array As String("chat_id", tid, "text",message))
        Wait For (web) JobDone(web As HttpJob)
        If web.Success Then
            web.Release
        Else
            web.Release
            Log(GetDateAndTime & web.GetString)
        End If
    Else
        Log(GetDateAndTime& $" blad wysylania bot, tid:${tid}, mes:${message}"$)
    End If
End Sub
2) Is it possible to build the same bot (the same API key) into ... several B4J apps that each sends messages only regarding its topic ?
bot token can be used only in one localization, you can not run 4 instances of the same bot on the same token.
 
Upvote 0

MichalK73

Well-Known Member
Licensed User
Longtime User
I no longer use the B4X code for the bot, as I guess this library is a bit underdeveloped or not very up-to-date with the new version. I had frequent conflicts with it, problems, hanging, bot not responding, etc.
I now use python to do bot telegram.
 
Upvote 0
Top