DEV Community

shushugah
shushugah

Posted on

Creating a telegram bot

I maintain a website which has a signup form for people to get in touch. We also have a private Telegram group chat we maintain, where we add people. In addition, we have a separate moderator/vetting group chat, where we discuss who to add.

  1. First we need to create a Telegram bot, with a unique username. Open up Telegram's official "BotFather" which will prompt you to give your bot a unique username (url) and also visual name. You can later update its photos etc..

  2. Once the bot is created, you will get a token which looks something like 434348934:AAEWdklsdjskljdklsd and it will have a username.

  3. Add the bot to your group chat (using the username).

  4. You will also need the channel_id for your group chat. This can be tricky to find. If it is a public group chat with a url format of t.me/group_name it will be @group_name. Otherwise, you will need to open telegram in a web browser on your desktop at web.telegram.org. Open the group chat you want, and look for the url in the browser. It might look like https://web.telegram.org/k/#-406703443746. Note the - sign, which is included. Depending on whether it is new, either -406703443746 will work, or prepending it with 100 so -100406703443746 is the channel_id.

  5. You can use either Zapier, Pipedream, IFTT or n8n to connect your website forms with telegram.

  6. On Pipedream I was able to make it work, using v2 markdown, whereas for Zapier I had to use HTML format, because it didn't parse markdown well. Do note, that the valid HTML elements for Telegram API are <b>, <pre>, <a> and <i> as of November 2023.

Other hiccups I had are "forwarding" telegram messages only refers to forwarding existing telegram messages, as opposed to creating a message.

What other pain points did you discover? I created this blog-post, because I didn't find any one tutorial that helped me. So perhaps this will be useful for you.

Top comments (0)