Images via Telegram Bot
This is the link for the telegram project. Sending a message through telegram, now if i want to send an image to telegram using the bot from the linux command line how do i do it??
I want to send a raw image or even an image from a file path, any ideas on how the “def” of this program changes??

Like messages you can send images as well using telegram bot. Please follow the steps below

telegram_chan_id = “@smarthome_kirupa#Replace with yours “@${Channel_id}”
telegram_bot_id = “bot1150761023:AAHAgV5laxCoKlUYAUb4YUhzn1DFvf5J8nw” #Replace with “bot${your bot id}”

def send_telegram_alert(photo, caption):
“”“Sends message via Telegram”""
url = “” + telegram_bot_id + “/sendPhoto”
data = {
“chat_id”: telegram_chan_id,
“caption”: caption
files = {‘photo’: open(photo, ‘rb’)}
response = requests.request(
#print(“This is the Telegram URL”)
print(“This is the Telegram response”)
telegram_data = json.loads(response.text)
return telegram_data[“ok”]
except Exception as e:
print(“An error occurred in sending the alert message via Telegram”)
return False

1 Like