Forum > Third party
Telegram bots API Wrapper
bonmario:
Hello,
I subscribed the bot to a group.
I just want to make sure that when I send a message to the bot from my program, the same message is sent to the group.
Hi Mario
Renat.Su:
If I understand you correctly, it's just an example with getMe. In fact, you need to send (redirect) messages to a group on behalf of the bot.
For this, for example, we could use the OnReceiveMessage event. Regardless of how we will use the getting update mode: webhook or long polling.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TYourBot.BotReceiveMessage(ASender: TObject; AMessage: TTelegramMessageObj);var AGroupChatID: Int64;begin AGroupChatID := xxxxxxxx; // Your group chat ID { It must to include the sender's userID checks. On good to override function IsSimpleUser or simply to check if CurrentChatID = xxxx where xxxx is your userID } if AMessage.Text<>EmptyStr then sendMessage(AGroupChatID, AMessage.Text); end; The rest of the code depends on which method of obtaining the update you selected.
If Webhook, then you need to teach the program how the server to receive and process the request from the telegram. As an example, you can see the implementation of the bot as part of the brook-framework (you can use other libraries or the native fcl-web)
If long polling, then you can see an example implementation of LongPollingDesktop.
I hope I missed important moments. If something does not work or it is not clear, write again
bonmario:
Ok.
Thanks, Mario
bonmario:
Hello,
I did a bit of testing, but I still could not make a working program.
Is it possible to have a source such as sending only a message to the bot?
Thanks in advance, Mario
Renat.Su:
--- Quote from: bonmario on July 04, 2018, 11:45:17 am ---Hello,
I did a bit of testing, but I still could not make a working program.
Is it possible to have a source such as sending only a message to the bot?
Thanks in advance, Mario
--- End quote ---
In the previous code is sending only a message, just this is done in the onreceivemessage method. I can show a more extensive piece of code, if you explain what exactly you need and I can put in the examples folder in lib
Navigation
[0] Message Index
[#] Next page
[*] Previous page