All examples suitable for Mac or Ubuntu OS.
Finally, I will show 1-line cron command with use of curl.
You will use unix terminal.
- Telegram bot token (e.g. https://www.siteguarding.com/en/how-to-get-telegram-bot-api-token)
- Chat id you will use
- 1-line poll command on curl (curl is a standard tool on Ubuntu and Mac)
- Scheduler (I will use crontab - standard tool on Ubuntu and Mac)
To get the chat id:
- Type something to your bot from the chat you choosed
- Open browser and with your bot token (replace
<YOUR TOKEN HERE>) past this url and press enter:
https://api.telegram.org/bot<YOUR TOKEN HERE>/getUpdates
You will get JSON with last messages send to bot - find your message and the find chat id in the message.
E.g. I got in browser in 1 line:
{"ok":true,"result":[{"update_id":21417078, "message":{"message_id":1923,"from":{"id":219904600,"is_bot":false,"first_name":"Ivan","last_name":"Ivan","username":"Ivan","language_code":"en"},"chat":{"id":211904600,"first_name":"Ivan","last_name":"Ivan","username":"Ivan","type":"private"},"date":1680618949,"text":"this is the message"}}]}And I found that message this is the message linked to 211904600
Next command consits of the question I wonder if you could play volleyball with me? and options: yes or tamm and with <YOUR TOKEN HERE>
curl -d chat_id="269904600" -d question="I wonder if you could play volleyball with me?" -d options="[\"yes\", \"tamm\"]" -d is_anonymous="False" https://api.telegram.org/bot<YOUR TOKEN HERE>/sendPoll
Take a not that in the command above I shiels quates around variant with
\
At this step you could even check if it works by using cntrl+c and cntrl+v in your terminal
The command I will add to crontab to make a poll every monday at 11:00 is the next:
0 11 * * 1 curl -d chat_id="269904600" -d question="I wonder if you could play volleyball with me?" -d options="[\"yes\", \"tamm\"]" -d is_anonymous="False" https://api.telegram.org/bot<YOUR TOKEN HERE>/sendPoll > /dev/null 2>&1
this command consists of cron notation. Here you could compose your own cron https://crontab.guru/#0_11_*_*_1
The last step is to add this 1-line cron command: https://unix.stackexchange.com/questions/21297/how-do-i-add-an-entry-to-my-crontab