diff --git a/xmpp_tg/__init__.py b/xmpp_tg/__init__.py index 573e21c..1874bf8 100644 --- a/xmpp_tg/__init__.py +++ b/xmpp_tg/__init__.py @@ -1,3 +1,3 @@ from xmpp_tg.xmpp import XMPPTelegram -__version__ = '0.3.3' +__version__ = '0.3.4' diff --git a/xmpp_tg/xmpp.py b/xmpp_tg/xmpp.py index 3e740ab..8eed3fe 100644 --- a/xmpp_tg/xmpp.py +++ b/xmpp_tg/xmpp.py @@ -146,14 +146,20 @@ class XMPPTelegram(ComponentXMPP): tg_peer = InputPeerChannel(tg_id, self.tg_dialogs[jid]['supergroups'][tg_id].access_hash) if tg_peer: + result = None + # detect media if msg.startswith('http') and re.match(r'(?:http\:|https\:)?\/\/.*\.(?:' + self.config['media_external_formats'] + ')', msg): urls = re.findall(r'(?:http\:|https\:)?\/\/.*\.(?:' + self.config['media_external_formats'] + ')', msg) message = msg.replace(urls[0], '') media = InputMediaPhotoExternal(urls[0]) - result = self.tg_connections[jid].invoke(SendMediaRequest(tg_peer, media, message, random_id = generate_random_long(), reply_to_msg_id = reply_mid)) - # no media — plain message # - else: + try: + result = self.tg_connections[jid].invoke(SendMediaRequest(tg_peer, media, message, random_id = generate_random_long(), reply_to_msg_id = reply_mid)) + except Exception: + print('Media upload failed.') + + # media send failed. # + if not result: result = self.tg_connections[jid].invoke(SendMessageRequest(tg_peer, msg, generate_random_long(), reply_to_msg_id=reply_mid)) msg_id = None