send image url as OOB
This commit is contained in:
@@ -55,7 +55,7 @@ class TelegramGateClient(TelegramClient):
|
||||
self._del_pts = 0
|
||||
|
||||
|
||||
def xmpp_update_handler(self, update_obj):
|
||||
def tg_update_handler(self, update_obj):
|
||||
|
||||
"""
|
||||
Main function: Telegram update handler.
|
||||
@@ -102,6 +102,7 @@ class TelegramGateClient(TelegramClient):
|
||||
msg = ''
|
||||
fwd_from = ''
|
||||
mid = update_obj.message.id
|
||||
oob_url = None
|
||||
|
||||
|
||||
# detect message type
|
||||
@@ -151,14 +152,14 @@ class TelegramGateClient(TelegramClient):
|
||||
|
||||
# message media #
|
||||
if update_obj.message.media:
|
||||
msg = '{} {}'.format(msg, self._process_media_msg(update_obj.message.media))
|
||||
msg, oob_url = '{} {}'.format(msg, self._process_media_msg(update_obj.message.media))
|
||||
|
||||
# edited #
|
||||
if update_obj.message.edit_date:
|
||||
msg = '[Edited] {}'.format(msg)
|
||||
|
||||
# send message #
|
||||
self.xmpp_send_message(prefix + str(cid), mbody ='[MSG {}] {}{}'.format(mid, fwd_from, msg))
|
||||
self.xmpp_send_message(prefix + str(cid), mbody ='[MSG {}] {}{}'.format(mid, fwd_from, msg), oob_url=oob_url)
|
||||
|
||||
# delivery report
|
||||
if is_supergroup:
|
||||
@@ -184,12 +185,17 @@ class TelegramGateClient(TelegramClient):
|
||||
print('Exception occurs!')
|
||||
print(traceback.format_exc())
|
||||
|
||||
def xmpp_send_message(self, mfrom, mbody):
|
||||
def xmpp_send_message(self, mfrom, mbody, oob_url=None):
|
||||
tg_from = int(mfrom[1:])
|
||||
if not tg_from in self.xmpp_gate.tg_dialogs[self.jid]['users'] and not tg_from in self.xmpp_gate.tg_dialogs[self.jid]['groups'] and not tg_from in self.xmpp_gate.tg_dialogs[self.jid]['supergroups']: # new contact appeared
|
||||
if not tg_from in self.xmpp_gate.tg_dialogs[self.jid]['users']\
|
||||
and not tg_from in self.xmpp_gate.tg_dialogs[self.jid]['groups']\
|
||||
and not tg_from in self.xmpp_gate.tg_dialogs[self.jid]['supergroups']: # new contact appeared
|
||||
self.xmpp_gate.tg_process_dialogs( self.jid )
|
||||
|
||||
self.xmpp_gate.send_message( mto=self.jid, mfrom=mfrom + '@' + self.xmpp_gate.config['jid'], mtype='chat', mbody=mbody)
|
||||
message = self.xmpp_gate.make_message( mto=self.jid, mfrom=mfrom + '@' + self.xmpp_gate.config['jid'], mtype='chat', mbody=mbody)
|
||||
if oob_url is not None:
|
||||
message['oob']['url'] = oob_url
|
||||
message.send()
|
||||
|
||||
def generate_media_link(self, media):
|
||||
"""
|
||||
@@ -270,6 +276,7 @@ class TelegramGateClient(TelegramClient):
|
||||
:return:
|
||||
"""
|
||||
msg = ''
|
||||
url = None
|
||||
|
||||
if type(media) is MessageMediaDocument: # document
|
||||
attributes = media.document.attributes
|
||||
@@ -321,6 +328,7 @@ class TelegramGateClient(TelegramClient):
|
||||
elif type(media) is MessageMediaPhoto: # photo (jpg)
|
||||
g_link = self.generate_media_link(media)
|
||||
msg = g_link['link']
|
||||
url = g_link['link']
|
||||
|
||||
self._media_queue.put({'media': media, 'file': g_link['name']})
|
||||
|
||||
@@ -338,7 +346,7 @@ class TelegramGateClient(TelegramClient):
|
||||
if type(media) is MessageMediaVenue:
|
||||
msg = '[Title: {}|Address: {}|Provider: {}] {}'.format(media.title, media.address, media.provider, msg)
|
||||
|
||||
return msg
|
||||
return msg,url
|
||||
|
||||
def _process_info_msg(self, message, peer):
|
||||
"""
|
||||
|
||||
@@ -397,7 +397,7 @@ class XMPPTelegram(ComponentXMPP):
|
||||
self.tg_process_dialogs(jid, sync_roster = False)
|
||||
|
||||
# Register Telegrap updates handler
|
||||
self.tg_connections[jid].add_update_handler(self.tg_connections[jid].xmpp_update_handler)
|
||||
self.tg_connections[jid].add_update_handler(self.tg_connections[jid].tg_update_handler)
|
||||
|
||||
def roster_exchange(self, tojid, contacts):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user