Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. # coding: UTF-8
  2. require 'telegram/bot'
  3. require 'dotenv/load'
  4. require 'open-uri'
  5. require 'webp-ffi'
  6.  
  7. TOKEN = ENV['TELEGRAM_BOT_API_TOKEN'].freeze
  8.  
  9. Telegram::Bot::Client.run(TOKEN) do |bot|
  10. bot.listen do |rqst|
  11. Thread.start(rqst) do |rqst|
  12. case rqst.text
  13. when '/start', '/start start'
  14. bot.api.send_message(chat_id: rqst.chat.id, text: "Hi, #{rqst.from.first_name} \nSend me sticker to get PNG file")
  15. when '/stop'
  16. bot.api.send_message(chat_id: rqst.chat.id, text: "Bye, #{rqst.from.first_name}")
  17. else
  18. sticker = rqst.sticker
  19. if sticker
  20. sticker_path = bot.api.get_file(file_id: sticker.file_id)['result']['file_path']
  21. f = open("https://api.telegram.org/file/bot#{TOKEN}/#{sticker_path}")
  22. File.write('sticker.png', f.read)
  23. f.close
  24. else
  25. bot.api.send_message(chat_id: rqst.chat.id, text: "That was not a sticker....try again!")
  26. end
  27. end
  28. end
  29. end
  30. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement