Is a lightweigth Crystal wrapper for Telegram Bot API.
-
Add the dependency to your
shard.yml
:dependencies: telegram: github: LeeCrey/telegram
-
Run
shards install
require "telegram"
token = "place-your-bot's-token-here"
bot = Telegram::Client.new(token)
me = bot.get_me
puts "first name: #{me["first_name"]}"
puts "user name: #{me["username"]}"
puts "id: #{me["id"]}"
There are two ways to get update from Telegram Server.
- polling
- webhook
#!/usr/bin/ruby
# frozen_string_literal: true
require 'teleruby'
@token = %q{place-your-bot's-token-here}
@bot = Telegram::Client.new(token: @token)
updates = @bot.get_updates
puts updates.inspect
NB: The default number of updates to be retrieved is 10, but you can add yours like.
@bot = Telegram::Client.new(token: @token)
updates = @bot.get_updates(limit: 80)
Here 10 shows, 80 updates to be retrieved. Max limit is 100. You can also limit type of updates!.
up_dates = ['message', 'channel_post']
@bot = Telegram::Client.new(token: @token)
updates = @bot.get_updates(limit: 80, type: up_dates)
In the above case bot will retrive 80 updates and only looks message and channel post notifications.
If you wanna create specific purpose bot, limiting type of request would be better!.
require "telegram"
token = "place-your-bot's-token-here"
bot = Telegram::Client.new(token)
bot.do_polling do
updates = bot.get_updates
updates.each do |update|
if update.msg?
message = update.message
if message.text_msg?
chat = message.chat
bot.send_message(chat.id, message.text)
end
end
end
end
- Fork it
- 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
- Solomon Boloshe - creator and maintainer
The library is available as open source under the terms of the GPLv3+.