Telegram Bot Development

May 4, 2022 · 2 min read · 244 Words · -Views -Comments

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