File

Ruby wrapper for Telegram’s Bot API.

Installation

Add following line to your Gemfile:

And then execute:

Or install it system-wide:

Usage

First things first, you need to obtain a token for your bot. Then create your Telegram bot like this:

Note that 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.

Webhooks

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.

Custom keyboards

You can use your own custom keyboards. Here is an example:

Furthermore, you can ask user to share location or phone number using KeyboardButton:

Inline keyboards

Bot API 2.0 brought us new inline keyboards. Example:

Inline bots

If you are going to create inline bot, check the example below:

Now, with 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.

Using answer_inline_query you can send query results to user. results field must be an array of query result objects.

File upload

Your bot can even upload files (photos, audio, documents, stickers, video) to Telegram servers. Just like this:

Logging

By default, bot doesn’t log anything (uses NullLoger). You can change this behavior and provide your own logger class. See example below:

Connection adapters

Since version 0.5.0 we rely on faraday under the hood. You can use any of supported adapters (for example, net/http/persistent):

Boilerplates

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

Contributing

Leave a Reply

Your email address will not be published. Required fields are marked *