Crystal wrapper for Telegram's Bot API.
Add this to your application's shard.yml
:
dependencies:
telegrambot:
github: xosmond/telegrambot
And then execute:
$ shards install
First things first, you need to obtain a token for your bot. Then create your Telegram bot like this:
require "telegrambot"
token = "YOUR_TELEGRAM_BOT_API_TOKEN"
bot = Telegrambot::Api.new token
bot.listen(0) do |message|
case message.text
when "/start"
bot.send_message(chat_id: message.chat.id, message: "Hello, #{message.from.first_name}")
when "/stop"
bot.send_message(chat_id: message.chat.id, message: "Bye, #{message.from.first_name}")
end
end
Note that Telegrambot::Api
only implements send_message
, get_updates
and listen
for continues updates. As you can see methods are implemented with the snake_case notation.
About message
object - it implements only the mandatory data, for extra data, you can make a PR.
- Basic API for recieve and send messages
- Complete Message object for access all possible data
- Logging
- Webhooks
- File uploads
- Custom keyboards
- Fork it ( https://github.com/xosmond/telegrambot/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
- xosmond Jordano Moscoso - creator, maintainer