use OOB for relaying images XMPP->TG

This commit is contained in:
2019-03-10 17:13:53 +01:00
parent 09c69468a8
commit 2ea7c29c64

View File

@@ -59,6 +59,7 @@ class XMPPTelegram(ComponentXMPP):
self.register_plugin('xep_0030') # Service discovery
self.register_plugin('xep_0054') # VCard-temp
self.register_plugin('xep_0172') # NickNames
self.register_plugin('xep_0066') # OOB
self.add_event_handler('message', self.message)
self.add_event_handler('presence_unsubscribe', self.event_presence_unsub)
@@ -164,16 +165,19 @@ class XMPPTelegram(ComponentXMPP):
result = None
# detect media
#TODO: fix
#TODO: implement OOB for images
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], "Image")
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.')
if "oob" in msg:
logging.debug("Found OOB content in message")
if "url" in msg['oob']:
url = msg['oob']['url']
logging.debug("Found OOB URL: {}".format(url))
if url.split('.')[-1] in self.config['media_external_formats']:
logging.debug("Media found")
media = InputMediaPhotoExternal(url, "Image")
try:
result = self.tg_connections[jid].invoke(SendMediaRequest(tg_peer, media, "Image", random_id = generate_random_long(), reply_to_msg_id = reply_mid))
except Exception:
print('Media upload failed.')
# media send failed. #
if not result: