· 2 分钟阅读时长 · 278 字 · -阅读 -评论

title: “Telegram Bot Development” tags:

  • Communication Tools slug: cf0bbf94 date: 2022-05-04 11:19:20 summary: “An introduction to building a Telegram Bot, covering setup with BotFather, command configuration, useful Node.js libraries, common pitfalls, and deployment notes.”

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

Alan H
Authors
开发者,数码产品爱好者,喜欢折腾,喜欢分享,喜欢开源