class Telegrambot::Api

Defined in:

telegrambot/api.cr

Constructors

Instance Method Summary

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"]

[View source]

Instance Method Detail

def client=(client : HTTP::Client) #

[View source]
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]

[View source]
def headers=(headers : HTTP::Headers) #

[View source]
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

[View source]
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

[View source]