How to send photos to Telegram in Ruby – Telegram Group

How to send photos to Telegram in Ruby

Photo by Sandra Tan on Unsplash
require: ‘telegram/bot’ 
require: ‘base64’ 
def initialize(chat_id = xxxxx)
@chat_id = chat_id
bot = Telegram::Bot::Api
raise ‘API key for Telegram not set. export TELEGRAM_KEY=[key]’ if ENV[‘TELEGRAM_KEY’].nil? token = ENV[‘TELEGRAM_KEY’]
@client = bot.new(token)
end
def send_photo_message(hash)
caption = hash[:text]
photo = hash[:photo]
photo_stream = create_image_stream(photo)
photo_message(caption, photo_stream)
end
def create_image_stream(photo)
binary = Base64.strict_decode64(photo)
StringIO.new(binary)
end
def photo_message(caption, photo_stream)
@client.send_photo(chat_id: @chat_id, caption: caption,
photo: Faraday::FilePart.new(photo_stream,'image/jpeg'))
end

Ten articles before and after

data-rh=”true”>Explainer: UK News Quiz, a Telegram Bot – Dror Kessler – Medium – Telegram Group

Telegram bot on the cloud. I wanted to create a bot in Telegram… – Telegram Group

Reacting to user feedback in a pet-project. Fast. – Telegram Group

XiongMai IP Camera Motion Detection Alert Snapshot to Telegram Bot – Telegram Group

On-The-Go Tools for Foreign Flow Analysis – Telegram Group

Telegram’da Benim de Bir Tuzum Olsun – Telegram Group

Controlling Light using Telegram Bot – Telegram Group

Делаем бота для учета личных расходов на Python используя Google Spreadsheets (часть 2) – Telegram Group

data-rh=”true”>Telegram Bot и отчётность по проекту – ToBe – Medium – Telegram Group

Делаем бота для учета личных расходов на Python используя Google Spreadsheets – Telegram Group