Ruby wrapper for Telegram’s Bot API.
Add following line to your Gemfile:
And then execute:
Or install it system-wide:
First things first, you need to obtain a token for your bot. Then create your Telegram bot like this:
bot.api object implements Telegram Bot API methods as is. So you can invoke any method inside the block without any problems. All methods are available in both snake_case and camelCase notations.
Same thing about
message object – it implements Message spec, so you always know what to expect from it.
If you are going to use webhooks instead of long polling, you need to implement your own webhook callbacks server. Take a look at this repo as an example.
You can use your own custom keyboards. Here is an example:
Furthermore, you can ask user to share location or phone number using
Bot API 2.0 brought us new inline keyboards. Example:
If you are going to create inline bot, check the example below:
inline mode enabled, your
message object can be an instance of Message, InlineQuery or ChosenInlineResult. That’s why you need to check type of each message and decide how to handle it.
answer_inline_query you can send query results to user.
results field must be an array of query result objects.
Your bot can even upload files (photos, audio, documents, stickers, video) to Telegram servers. Just like this:
By default, bot doesn’t log anything (uses
NullLoger). You can change this behavior and provide your own logger class. See example below:
0.5.0 we rely on faraday under the hood. You can use any of supported adapters (for example,
If you don’t know how to setup database for your bot or how to use it with different languages here are some boilerplates which can help you to start faster:
- Ruby Telegram Bot boilerplate