class Telegrambot::Api
- Telegrambot::Api
- Reference
- Object
Defined in:
telegrambot/api.crConstructors
-
.new(token : String)
Create an instance of the API with the token
Instance Method Summary
- #client=(client : HTTP::Client)
-
#get_updates(offset : Int)
Get updates from the bot sice the last offset
- #headers=(headers : HTTP::Headers)
-
#listen(offset : Int, &block)
Listen for updates and use the block on each message
-
#send_message(chat_id : Int, message : String)
Sends a message to the chat with the chat_id specified
Constructor Detail
def self.new(token : String)
#
Create an instance of the API with the token
Telegrambot::Api.new token
You can also get the token from env
Telegrambot::Api.new ENV["TELEGRAM_BOT_TOKEN"]
Instance Method Detail
def get_updates(offset : Int)
#
Get updates from the bot sice the last offset
Get all updates
api.get_updates 0 # => 13171, [Messages]
Get since offset
api.get_updates offset: 1231796 # => 1231886, [Messages]
def listen(offset : Int, &block)
#
Listen for updates and use the block on each message
api.listen(0) do |message|
puts message.text # => Hello
end
def send_message(chat_id : Int, message : String)
#
Sends a message to the chat with the chat_id specified
api.send_message chat_id: 1231241, message: "Hello" # => true