Telegram APIs - green-cani/green_tracker GitHub Wiki
Visiting https://core.telegram.org/bots/api the API reference for Telegram is found. Basic commands are
https://api.telegram.org/bot_id:bot_token/getme
which returns bot idshttps://api.telegram.org/bot_id:bot_token/getupdates
to get bot's last activityhttps://api.telegram.org/bot_id:bot_token/sendmessage?text=...&chat_id=...
to send a message to a chat from bot
Webhooks
A webhook is an API command which sets the automatic forwarding of a JSON (containing messages' information) to a specific URL (so that it can be handled):
https://api.telegram.org/bot_id:bot_token/setWebhook?url=https://your_domain.com/where-the-script-will-be/bot-script
The most straightforward way to use a webhook is to trigger some responses to events in the script. For instance, one can set an if
conditional to match the text of the forwarded message as in this tutorial.
In the current project, this handling is done with bot-telegram-bot-api and in particular with
bot.onText(/\/echo (.+)/, (msg, match) => { ... }
for text and
bot.on('message', (msg) => { ... }
for general purpose.
Keeping the Heroku app "awaken"
Weebhooks can be useful to keep the dyno up: if the parameter url
is set equal to the heroku app site, the web-hook forwarding will wake the app up; then the message will be processed by the bot.