You are here

How to Create a Telegram Bot in Ruby

Telegram is a free cloud-based messaging app that provides synchronised access to your chats across platforms. The service has opened its code to everyone, allowing developers to build their own tools using the developer API. Another feature of the platform is the ability to build bots that perform any function you program it to via the Telegram Bot API.

These bots are simply Telegram accounts operated by third-party applications, and often boasting AI features, to handle messages automatically. Users can interact with bots by sending messages, commands, or inline requests, to perform a particular task, such as check the weather, translate text, play media or pass commands to IoT devices, among many others.

This tutorial by Ardian Haxha on the SitePoint blog shows followers how to quickly create a Telegram bot in Ruby. The tutorial begins with signing up for an account and creating a new bot, then using the telegram-bot-ruby gem to interact with the bot API. After setting up a dedicated file for the contents, followers must import the gem and add the API token generated earlier.

Followers will then have to search for the bot on the Telegram platform, but it will appear in the search results by name. Hitting the ‘Start’ button initiates  the /start command, which should contain a welcome message and some general information about the bot, such as tasks it performs and commands it understands.

The author set up a /sitepoint command to issue a welcome note and display a link to SitePoint’s website, as well as a /send_location method for marking a point on the map. All code is provided at the end, making this tutorial an ideal starting point for building custom bots to perform almost any function.

Be sure to read the next Bots article: How to Build Your First Slack Bot with Python

Original Article

Quickly Create a Telegram Bot in Ruby