summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--itests/test_quickresponse.py59
-rw-r--r--slixmpp/plugins/xep_0439/quickresponse.py42
-rw-r--r--tests/test_stanza_xep_0444.py6
3 files changed, 101 insertions, 6 deletions
diff --git a/itests/test_quickresponse.py b/itests/test_quickresponse.py
new file mode 100644
index 00000000..972659f3
--- /dev/null
+++ b/itests/test_quickresponse.py
@@ -0,0 +1,59 @@
+import unittest
+from slixmpp.test.integration import SlixIntegration
+from slixmpp.plugins.xep_0439 import stanza
+
+
+class TestQuickResponse(SlixIntegration):
+ async def asyncSetUp(self):
+ self.add_client(
+ self.envjid('CI_ACCOUNT1'),
+ self.envstr('CI_ACCOUNT1_PASSWORD'),
+ )
+ self.add_client(
+ self.envjid('CI_ACCOUNT2'),
+ self.envstr('CI_ACCOUNT2_PASSWORD'),
+ )
+ self.register_plugins(['xep_0439'])
+ await self.connect_clients()
+
+ async def test_quickresponse(self):
+ """Send and receive actions and responses"""
+ actions = [
+ ('id1', 'Action 1'),
+ ('id2', 'Action 2'),
+ ]
+ self.clients[0]['xep_0439'].ask_for_actions(
+ self.clients[1].boundjid.full,
+ "Action 1 or 2 ?",
+ actions
+ )
+ msg = await self.clients[1].wait_until('action_received')
+ actions_recv = [
+ (st['id'], st['label']) for st in msg if isinstance(st, stanza.Action)
+ ]
+ self.assertEqual(
+ actions,
+ actions_recv,
+ )
+
+ reply = self.clients[1].make_message(
+ mto=self.clients[0].boundjid.full
+ )
+ reply['action_selected']['id'] = 'id1'
+ reply.send()
+
+ reply_recv = await self.clients[0].wait_until('action_selected')
+ self.assertEqual(
+ reply_recv['action_selected']['id'],
+ 'id1',
+ )
+
+ self.clients[0]['xep_0439'].ask_for_response(
+ self.clients[1].boundjid.full,
+ "Reply with action 1 or 2 (id1/id2) ?",
+ actions
+ )
+ msg = await self.clients[1].wait_until('responses_received')
+
+
+suite = unittest.TestLoader().loadTestsFromTestCase(TestQuickResponse)
diff --git a/slixmpp/plugins/xep_0439/quickresponse.py b/slixmpp/plugins/xep_0439/quickresponse.py
index 74e299d6..f6836731 100644
--- a/slixmpp/plugins/xep_0439/quickresponse.py
+++ b/slixmpp/plugins/xep_0439/quickresponse.py
@@ -11,9 +11,12 @@ from typing import (
Tuple,
)
-from slixmpp import JID
+from slixmpp import JID, Message
from slixmpp.plugins import BasePlugin
from slixmpp.plugins.xep_0439 import stanza
+from slixmpp.xmlstream.matcher import StanzaPath
+from slixmpp.xmlstream.handler import Callback
+
class XEP_0439(BasePlugin):
@@ -27,11 +30,40 @@ class XEP_0439(BasePlugin):
def plugin_init(self) -> None:
stanza.register_plugins()
+ self.xmpp.register_handler(Callback(
+ 'Action received',
+ StanzaPath('message/action'),
+ self._handle_action,
+ ))
+ self.xmpp.register_handler(Callback(
+ 'Response received',
+ StanzaPath('message/response'),
+ self._handle_response,
+ ))
+ self.xmpp.register_handler(Callback(
+ 'ActionSelected received',
+ StanzaPath('message/action_selected'),
+ self._handle_action_selected,
+ ))
+
+ def plugin_send(self):
+ self.xmpp.remove_handler('Action received')
+ self.xmpp.remove_handler('Response received')
+ self.xmpp.remove_handler('ActionSelected received')
+
+ def _handle_response(self, msg: Message):
+ self.xmpp.event('responses_received', msg)
+
+ def _handle_action(self, msg: Message):
+ self.xmpp.event('action_received', msg)
+
+ def _handle_action_selected(self, msg: Message):
+ self.xmpp.event('action_selected', msg)
- def ask_for_responses(self, mto: JID, body: str,
- responses: Iterable[Tuple[str, str]],
- mtype: str = 'chat', lang: Optional[str] = None, *,
- mfrom: Optional[JID] = None):
+ def ask_for_response(self, mto: JID, body: str,
+ responses: Iterable[Tuple[str, str]],
+ mtype: str = 'chat', lang: Optional[str] = None, *,
+ mfrom: Optional[JID] = None):
"""
Send a message with a set of responses.
diff --git a/tests/test_stanza_xep_0444.py b/tests/test_stanza_xep_0444.py
index b4d5739b..276460c5 100644
--- a/tests/test_stanza_xep_0444.py
+++ b/tests/test_stanza_xep_0444.py
@@ -43,7 +43,11 @@ class TestReactions(SlixTest):
def testCreateReactionsUnrestricted(self):
"""Testing creating Reactions with the extra all_chars arg."""
-
+ try:
+ import emoji
+ except ImportError:
+ # No emoji package: this test does not make sense
+ return
xmlstring = """
<message>
<reactions xmlns="urn:xmpp:reactions:0" id="abcd">