The simplest way to start a bot is using Telegram::Bot::Client.run. This method starts a long-polling loop that listens for updates. Inside the block, you can use bot.listen to handle incoming messages.
Note that bot.api implements the Telegram Bot API methods directly. You can call these methods using either snake_case or camelCase.
To run in development/test mode, pass environment: :test to the run method.
require 'telegram/bot'
token = 'YOUR_TELEGRAM_BOT_API_TOKEN'
Telegram::Bot::Client.run(token) do |bot|
bot.listen do |message|
case message.text
when '/start'
bot.api.send_message(chat_id: message.chat.id, text: "Hello, #{message.from.first_name}")
when '/stop'
bot.api.send_message(chat_id: message.chat.id, text: "Bye, #{message.from.first_name}")
end
end
end