You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
get '/' do
require 'telegram/bot'
TOKEN = 'your token'
HOOK_URL = 'https://example.com'
bot = Telegram::Bot::Api.new(TOKEN)
puts bot.set_webhook(url: HOOK_URL)
content_type :json, charset: 'utf-8'
{ webhook: true }.to_json
end
Create a route to execute the telegram bot by webook
post '/' do
request.body.rewind
data = JSON.parse(request.body.read)
@bot = Telegram::Bot::Api.new(TOKEN)
@message = Telegram::Bot::Types::Update.new(data).message
case @message.text
when '/start'
@bot.send_message(chat_id: @message.chat.id, text: "Hi, #{@message.from.first_name}, nice to see you")
when '/stop'
@bot.send_message(chat_id: @message.chat.id, text: "Bye, #{@message.from.first_name}")
when '/help'
@bot.send_message(chat_id: @message.chat.id, text: "some help...")
else
# do something with the message
# maybe check for attachment
if @message.photo.any? then
result = @bot.getFile(file_id: @message.photo.last.file_id)
telegramurl = "#{API}#{ENV['TELEGRAM_BOT_API_TOKEN']}/#{result["result"]["file_path"]}" if result["ok"]
# download photo and process
end
@bot.send_message(chat_id: @message.chat.id, text: "Thank you, #{@message.from.first_name}")
end
status 200
end
Vlw man por compartilhar!!!