Tourmaline

Crystal Telegram Bot Framework


Quickstart

Tourmaline uses Crystal to communicate with the Telegram Bot API. Therefore to use Tourmaline you should be familiar with how Crystal works.

Once inside of a Crystal project, add Tourmaline to your shard.yml file and run shards install to install it.

For more information, see the getting started page.

Using Annotations

require "tourmaline"

class EchoBot < Tourmaline::Client
  @[Command("echo")]
  def echo_command(ctx)
    ctx.message.reply(ctx.text)
  end
end

bot = EchoBot.new(bot_token: "YOUR_API_TOKEN")
bot.poll

More Procedural

require "tourmaline"
include Tourmaline # To shorten things

bot = Client.new(bot_token: "YOUR_API_TOKEN")

echo_handler = Handlers::CommandHandler.new("echo") do |ctx|
  ctx.message.reply(ctx.text)
end

bot.add_event_handler(echo_handler)
bot.poll