From c4c64fe7b5000cb9e3b66b862441ec1ee5977741 Mon Sep 17 00:00:00 2001 From: rexdivakar Date: Sat, 17 Oct 2020 21:19:33 +0530 Subject: [PATCH] added send_image --- setup.py | 2 +- telegram/notifly.py | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index cd23c7e..68059cf 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ setup( name='notifly', - version='1.1', + version='1.1.1', description='Telegram Bot Notifier', long_description=long_description, long_description_content_type='text/x-rst', diff --git a/telegram/notifly.py b/telegram/notifly.py index 12ee98b..3f322ae 100644 --- a/telegram/notifly.py +++ b/telegram/notifly.py @@ -5,6 +5,7 @@ token = '' # Token of your bot + class BotHandler: def __init__(self, token): self.token = token @@ -25,8 +26,19 @@ def push_notification_msg(self, chat_id, text): resp = requests.post(self.api_url + method, params) return resp - def send_message(self,msg): + def send_message(self, msg): fetch_updates = self.get_updates() chat_id = fetch_updates[0]['message']['chat']['id'] + print(chat_id) update_id = fetch_updates[0]['update_id'] return self.push_notification_msg(chat_id=chat_id, text=msg) + + def send_file(self,img_path): + fetch_updates = self.get_updates() + chat_id = fetch_updates[0]['message']['chat']['id'] + method = 'sendPhoto?'+'chat_id='+str(chat_id) + + files ={'photo':open(img_path, 'rb')} + + resp = requests.post(self.api_url+method,files=files) +