Telegram Bot Development

An introduction to building a Telegram Bot, covering setup with BotFather, command configuration, useful Node.js libraries, common pitfalls, and deployment notes.

May 4, 2022 · 2 min read · 244 Words · -Views -Comments · Programming
Communication Tools
Read with AI

Choose an AI assistant

ChatGPT Open in a new tab with the article link and prompt
Claude Copy the prompt, then open Claude

Open Claude
Trouble reading the article?

If the prompt is missing, copy the full prompt below into your AI assistant. If the AI cannot read the article, paste the visible passage you want to discuss and add your question.

For technical and non-technical problems I encounter, besides writing blog summaries, I often record them as GitHub issues in alanhg/others-note and alanhg/coding-note. Searching across repos is inefficient, so I decided to build a Telegram Bot to search issues across repos. I didn’t find an existing solution, so I implemented one myself.

Current Result

Use the repoadd command to add target repositories, then enter any keyword to search issues across multiple repos. Demo:

https://static.1991421.cn/2022/2022-05-04-114501.gif

Bot link: GitHub Issue Bot

Bot Development

I hit a few bumps while building the bot; here’s a summary:

  1. Create the bot with @BotFather and follow the interactive setup.

    • Configure bot name/avatar and command list in BotFather.
    • Keep the bot_token safe; it identifies your bot and authorizes messaging.
    • To create a command list, use BotFather’s “Edit Commands” for the target bot. Notes:
      • Avoid hyphens in command names.
      • Don’t include a leading / in the definition; the slash is only for invocation.
        https://static.1991421.cn/2022/2022-05-04-115842.jpeg
      • You can’t add commands incrementally; enter the full set each time.
  2. There are solid helper libraries to get started.

  3. Bots support markdown/html message formats, which simplifies layout.

  4. To update a “searching…” message with results, use bot.editMessageText with explicit message_id and chat_id.

  5. To listen for replies to a specific message, use bot.onReplyToMessage.

  6. Deploy the bot on a publicly reachable host; you may also need a proxy during testing.

Final Thoughts

With this bot, I can simply enter a keyword to check for similar issues across repos.

References

Authors
Developer, digital product enthusiast, tinkerer, sharer, open source lover