Commit 9e70954a authored by Maxime Buquet's avatar Maxime Buquet

example-bot: attempt at returning encrypted messages

Signed-off-by: Maxime Buquet's avatarMaxime “pep” Buquet <>
parent af8c7313
......@@ -36,6 +36,8 @@ class EchoBot(ClientXMPP):
slixmpp repository.
eme_ns = 'eu.siacs.conversations.axolotl'
def __init__(self, jid, password):
ClientXMPP.__init__(self, jid, password)
......@@ -140,9 +142,30 @@ class EchoBot(ClientXMPP):
async def encrypted_reply(self, original_msg, body) -> None:
"""Helper to reply with encrypted messages"""
# TODO: Send the message encrypted.
return await self.plain_reply(msg, body)
mto = original_msg['from']
mtype = original_msg['type']
msg = self.make_message(mto=mto, mtype=mtype)
msg['eme']['namespace'] = self.eme_ns
msg['eme']['name'] = self['xep_0380'].mechanisms[self.eme_ns]
while True:
# `encrypt_message` excepts the plaintext to be sent, a list of
# bare JIDs to encrypt to, and optionally a dict of problems to
# expect per bare JID.
recipients = [mto]
encrypt = await self['xep_0384'].encrypt_message(body, recipients)
return msg.send()
except UndecidedException as exn:
# The library prevents us from sending a message to an
# untrusted/undecided barejid, so we need to make a decision here.
# This is where you prompt your user to ask what to do.
self['xep_0384'].trust(exn.bare_jid, exn.device, exn.ik)
except Exception as exn:
return None
if __name__ == '__main__':
# Setup the command line arguments.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment