Skip to content

Instantly share code, notes, and snippets.

@iNPUTmice
Last active June 30, 2021 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iNPUTmice/b139db84a9462f4c13d49e3977c941f6 to your computer and use it in GitHub Desktop.
Save iNPUTmice/b139db84a9462f4c13d49e3977c941f6 to your computer and use it in GitHub Desktop.
Send an image in a chat message with SleekXMPP
import logging
import threading
import sleekxmpp
logging.basicConfig(level=logging.DEBUG)
class Bot(sleekxmpp.ClientXMPP):
def __init__(self, jid, password):
super(Bot, self).__init__(jid, password)
self.ready = threading.Event()
self.register_plugin('xep_0030')
self.register_plugin('xep_0066') # OOB
self.add_event_handler('session_start', self.session_start)
def session_start(self, event):
self.get_roster()
self.send_presence()
self.ready.set()
def send_image_oob(self, jid, img_url):
m = self.Message()
m['to'] = jid
m['type'] = 'chat'
m['body'] = img_url #the body must be equal to the URL for Conversations to recognize it as a file
m['oob']['url'] = img_url
m.send()
if __name__ == '__main__':
b = Bot('bot@example.com', 'secret')
b.connect()
b.process(block=False)
b.ready.wait()
b.send_image_oob('someone@example.com', 'http://example.com/image.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment