Images via Telegram Bot

https://trainings.boltiot.com/courses/429176/lectures/10237357
Hey,
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 = “https://api.telegram.org/” + telegram_bot_id + “/sendPhoto”
data = {
“chat_id”: telegram_chan_id,
“caption”: caption
}
files = {‘photo’: open(photo, ‘rb’)}
try:
response = requests.request(
“POST”,
url,
params=data,
files=files
)
#print(“This is the Telegram URL”)
#print(url)
print(“This is the Telegram response”)
print(response.text)
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”)
print(e)
return False

1 Like