If you want to control your Telegram Bot with AutoIt, this is for you!
Telegram UDF is on the official AutoIt Script UDFs list! Check it here!
Important
After over 4 years of inactivity, I am rewriting the library code from scratch with the intention of updating, optimizing it, fixing all the reported issues accumulated over the years, and supporting the latest Telegram features. You can find the development in the dev branch. I appreciate any kind of contribution. Thank you for the support. β€οΈ
Warning
I'd like to inform you that the license for this project has been updated from GPL to MIT. This means that you are now free to use this work in your projects, with the condition that you acknowledge and cite this library within your own work. Thank you for your support and cooperation.
Telegram.au3 is the main file that you have to include in your code, but it also need the include folder. Adjust the path as you want. Include the library in your script with #include "Telegram.au3"
.
First initialize your bot with _InitBot(12345678:AbCdEfGh....)
, then you can use all the bot functions.
Check the @error flag after invoking _InitBot() (or its return value) to make sure everything is working: @error == 1
mean error, and in this case the _InitBot() return False.
After initializing the bot, you can do whatever you need to do. (Almost) all the APIs are coded, read the wiki for details about all the functions. To put the bot in polling state (i.e. wait for incoming messages) read below.
To wait incoming messages you have to put the bot in Polling State. This state is blocking, therefore your script will wait here until it's closed or it exit from the main while, maybe if a certain condition is verified.
While 1 ;Create a While that restart Polling
$msgData = _Polling() ;_Polling function return an array with information about a message
_SendMsg($msgData[2],$msgData[5]) ;Send a message to the same user with the same text
WEnd
For a simple text message, the array returned by _Polling() is:
$msgData[0] = Offset of the current update (used to 'switch' to the next update)
$msgData[1] = Message ID
$msgData[2] = Chat ID, use for interact with the user
$msgData[3] = Username of the user
$msgData[4] = First name of the user
$msgData[5] = Text of the message
If you want to try all the available features, use the Test file into /tests folder. Open it, insert your bot's token, your chat id (make sure you have sent at least one message to the bot) and then execute it.
I'm writing a wiki, you can find it here.
- Thanks to dragana-r (trancexx on AutoIt Forum) for WinHttp UDF/Forum thread
- Thanks to zserge for JSON UDF
- Thanks to J2TeamM for JSON/Base64 UDF
- Thanks to Sergey Flakon for fixing issue #8
- Thanks to RazTK for fixing issue #11 and issue #12
- Thanks to Jefta-387 for fixing issue #13
If you want to donate for support my (future) works, use this: https://www.paypal.me/LCirillo. β€οΈ
For support, just contact me! Enjoy π