crgram
crgram
Telegram Bot API library for Crystal
Started based on Bot API v9.2
- Note: Under Development.
Installation
-
Add the dependency to your
shard.yml:dependencies: crgram: github: zerohxyz/crgram -
Run
shards install
Usage
require "crgram"
BOT_TOKEN = "BOT_TOKEN"
bot = Crgram::Bot.new(BOT_TOKEN)
bot.on_text_msg do |msg, ctx, text|
if from = msg.from
ctx.reply(from.id, text)
end
end
bot.start
or
require "crgram"
BOT_TOKEN = "BOT_TOKEN"
module MyBot
include Crgram
bot = Bot.new(BOT_TOKEN)
bot.on_text_msg do |msg, ctx, text|
if from = msg.from
ctx.reply(from.id, text)
end
end
bot.start
end
For webhook implementation create bot with webhook options
bot = Crgram::Bot.new(BOT_TOKEN, Crgram::WebhookOptions.new("URL"))
Handlers
Event Handlers
bot.on_{{event_name}} do |event, ctx|
# 'event' type is tied to that specific handler
# for message event it will be of type Crgram::Message
# 'ctx' is Crgram::Core::Context
end
| Handler Method | Yielded Event (Type) |
|---|---|
on_message |
Message |
on_edited_message |
Message |
on_channel_post |
Message |
on_edited_channel_post |
Message |
on_business_connection |
BusinessConnection |
on_business_message |
Message |
on_edited_business_message |
Message |
on_deleted_business_messages |
BusinessMessagesDeleted |
on_message_reaction |
MessageReactionUpdated |
on_message_reaction_count |
MessageReactionCountUpdated |
on_inline_query |
InlineQuery |
on_chosen_inline_result |
ChosenInlineResult |
on_callback_query |
CallbackQuery |
on_shipping_query |
ShippingQuery |
on_pre_checkout_query |
PreCheckoutQuery |
on_purchased_paid_media |
PaidMediaPurchased |
on_poll |
Poll |
on_poll_answer |
PollAnswer |
on_my_chat_member |
ChatMemberUpdated |
on_chat_member |
ChatMemberUpdated |
on_chat_join_request |
ChatJoinRequest |
on_chat_boost |
ChatBoostUpdated |
on_removed_chat_boost |
ChatBoostRemoved |
Message Handlers
bot.on_{{message_subtype_name}}_msg do |msg, ctx, message_subtype|
# msg of type Crgram::Message
# ctx of type Crgram::Core::Context
# message_subtype for sticker is Crgram::Sticker
end
on_text_msgon_sticker_msgon_audio_msgon_video_msgon_document_msgon_animation_msgon_voice_msgon_video_note_msgon_poll_msg
Command Handler
on_command_msg
bot.on_command_msg do |msg, ctx, cmd, args|
# cmd is string ,eg: start
# args is array of string
end
Contributing
- Fork it (https://github.com/zerohxyz/crgram/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
Contributors
- zeroh - creator and maintainer
Repository
crgram
Owner
Statistic
- 0
- 0
- 0
- 0
- 0
- about 4 hours ago
- June 29, 2026
License
MIT License
Links
Synced at
Mon, 29 Jun 2026 02:56:20 GMT
Languages