Skip to content

Instantly share code, notes, and snippets.

@MauroEldritch
Created December 4, 2020 15:08
Show Gist options
  • Save MauroEldritch/9ed15c3f41dc4bf460bac4ba98262731 to your computer and use it in GitHub Desktop.
Save MauroEldritch/9ed15c3f41dc4bf460bac4ba98262731 to your computer and use it in GitHub Desktop.
Telegram_Bot.rb
#!/usr/bin/ruby
require 'telegram/bot'
$api_telegram = "" #Your bot API. You need to enter Telegram and ask Botfather to create a Bot. He will guide you.
Telegram::Bot::Client.run($api_telegram) do |bot|
bot.listen do |message|
#Messages. I use an expression to make it case insensitive.
case message.text
when /\/start/i
begin
bot.api.send_message(chat_id: message.chat.id, text: "Hello!")
rescue
end
when /bye/i
begin
bot.api.send_message(chat_id: message.chat.id, text: "Bye then!")
rescue
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment