Telegram is a popular messaging app that offers a variety of solid clients and features, including chatbots. In this blog post, we will explore how to create a Telegram chatbot that we can communicate with, in Rye language - yeah, we’re fans :=).
Starting with an Echo Bot
Our first step in creating a Telegram chatbot will be to create a simple Echo bot. An Echo bot simply echoes back whatever message it receives. This is a good starting point for learning how to create more complex bots.
Setting up a new bot in Telegram involves interacting with the
BotFather on Telegram itself to get a token, which you’ll save in a .token
file.
Rye uses Go’s telegram-bot-api library quite direct. With a few helper functions the example code could be shorter and more high level, but this better shows us what is going on behind the scenes.
So we load the API token, create an instance of the Telegram-bot and define its on-update method. In it we parse the ‘Message’ out of the JSON message we received, and Chat ID out of that. We need ID to create a reply message, with Text the same as it was in the incoming message. And we send it.
This is just 1/3 of the blogpost, continue on our new blog:
https://ryelang.org/blog/posts/rye-telegram-bot/
Komentarji
Objavite komentar