Skip to content

Instantly share code, notes, and snippets.

@eplt
Created September 21, 2020 11:10
Show Gist options
  • Save eplt/6166349430636ef3fd47fe00330947dc to your computer and use it in GitHub Desktop.
Save eplt/6166349430636ef3fd47fe00330947dc to your computer and use it in GitHub Desktop.
To create a Telegram Bot
Step 1: Get a bot id and keys
Add botfather to your telegram account. Follow the interactive mode to choose the id, and you will get key (sample below, use your own key!).
https://t.me/botfather
------
Done! Congratulations on your new bot. You will find it at t.me/sample_bot. You can now add a description, about section and profile picture for your bot, see /help for a list of commands. By the way, when you've finished creating your cool bot, ping our Bot Support if you want a better username for it. Just make sure the bot is fully operational before you do this.
Use this token to access the HTTP API:
1338113001:AALZqz4svWKBGeGehAnU1hgHUnYmpmUCpEk
Keep your token secure and store it safely, it can be used by anyone to control your bot.
For a description of the Bot API, see this page: https://core.telegram.org/bots/api
------
Step 2: Add your bot to the channel/group you want to use the bot in.
Assuming that you are the group admin, you can add the bot to the channel/group. Just search for the bot name (from the message above "sample_bot"), it is unique. And make sure you grant it admin rights, so it can send/receive messages.
Step 3: Run curl from commandline to get the channel/group id.
Send a few messages to your bot in the channel/group. Then run the following command.
curl -X POST "https://api.telegram.org/bot1338113001:AALZqz4svWKBGeGehAnU1hgHUnYmpmUCpEk/getUpdates"
Now search through the JSON output and look for the message and note this part of the message:
chat":{"id":-1001292231786,"title":"<Your Channel/Group Name",...
In this case, the id of the group is -1001292231786
Step 4: Send yourself a message using the bot account now.
Run the following command:
curl -X POST "https://api.telegram.org/bot1338113001:AALZqz4svWKBGeGehAnU1hgHUnYmpmUCpEk/sendMessage" -d "chat_id=-1001292231786&text=my sample text"
Done. Now you can write something cool with this. You can read and write from the channel/group now.
@faraz4020
Copy link

Happy with you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment