summaryrefslogtreecommitdiff
path: root/slixmpp
diff options
context:
space:
mode:
authorLink Mauve <linkmauve@linkmauve.fr>2020-12-04 20:03:32 +0100
committerLink Mauve <linkmauve@linkmauve.fr>2020-12-04 20:03:32 +0100
commit05749c49690c00f2b1794212b2fb9281b6956a89 (patch)
tree06600402c84040badb8c51a84f683a2ca467ca13 /slixmpp
parente592a46c99888594bfb0bf71da99c88755912a37 (diff)
parentc2b09c5c8317d919d7df94b85ac92910de05904a (diff)
downloadslixmpp-05749c49690c00f2b1794212b2fb9281b6956a89.tar.gz
slixmpp-05749c49690c00f2b1794212b2fb9281b6956a89.tar.bz2
slixmpp-05749c49690c00f2b1794212b2fb9281b6956a89.tar.xz
slixmpp-05749c49690c00f2b1794212b2fb9281b6956a89.zip
Merge branch 'more-xeps' into 'master'
Add a batch of newer XEPs See merge request poezio/slixmpp!69
Diffstat (limited to 'slixmpp')
-rw-r--r--slixmpp/plugins/__init__.py6
-rw-r--r--slixmpp/plugins/xep_0359/__init__.py13
-rw-r--r--slixmpp/plugins/xep_0359/stanza.py35
-rw-r--r--slixmpp/plugins/xep_0359/stanzaid.py22
-rw-r--r--slixmpp/plugins/xep_0422/__init__.py13
-rw-r--r--slixmpp/plugins/xep_0422/fastening.py28
-rw-r--r--slixmpp/plugins/xep_0422/stanza.py42
-rw-r--r--slixmpp/plugins/xep_0424/__init__.py13
-rw-r--r--slixmpp/plugins/xep_0424/retraction.py62
-rw-r--r--slixmpp/plugins/xep_0424/stanza.py38
-rw-r--r--slixmpp/plugins/xep_0425/__init__.py13
-rw-r--r--slixmpp/plugins/xep_0425/moderation.py39
-rw-r--r--slixmpp/plugins/xep_0425/stanza.py46
-rw-r--r--slixmpp/plugins/xep_0428/__init__.py13
-rw-r--r--slixmpp/plugins/xep_0428/fallback.py22
-rw-r--r--slixmpp/plugins/xep_0428/stanza.py26
-rw-r--r--slixmpp/plugins/xep_0439/__init__.py13
-rw-r--r--slixmpp/plugins/xep_0439/quickresponse.py91
-rw-r--r--slixmpp/plugins/xep_0439/stanza.py43
19 files changed, 578 insertions, 0 deletions
diff --git a/slixmpp/plugins/__init__.py b/slixmpp/plugins/__init__.py
index f948ead6..02ac3712 100644
--- a/slixmpp/plugins/__init__.py
+++ b/slixmpp/plugins/__init__.py
@@ -86,6 +86,7 @@ __all__ = [
'xep_0325', # IoT Systems Control
'xep_0332', # HTTP Over XMPP Transport
'xep_0353', # Jingle Message Initiation
+ 'xep_0359', # Unique and Stable Stanza IDs
'xep_0363', # HTTP File Upload
'xep_0369', # MIX-CORE
'xep_0377', # Spam reporting
@@ -93,5 +94,10 @@ __all__ = [
'xep_0404', # MIX-Anon
'xep_0405', # MIX-PAM
'xep_0421', # Anonymous unique occupant identifiers for MUCs
+ 'xep_0422', # Message Fastening
+ 'xep_0424', # Message Retraction
+ 'xep_0425', # Message Moderation
+ 'xep_0428', # Message Fallback
+ 'xep_0439', # Quick Response
'xep_0444', # Message Reactions
]
diff --git a/slixmpp/plugins/xep_0359/__init__.py b/slixmpp/plugins/xep_0359/__init__.py
new file mode 100644
index 00000000..dd01ea1e
--- /dev/null
+++ b/slixmpp/plugins/xep_0359/__init__.py
@@ -0,0 +1,13 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2020 Mathieu Pasquet <mathieui@mathieui.net>
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permission.
+"""
+
+from slixmpp.plugins.base import register_plugin
+from slixmpp.plugins.xep_0359.stanza import *
+from slixmpp.plugins.xep_0359.stanzaid import XEP_0359
+
+register_plugin(XEP_0359)
diff --git a/slixmpp/plugins/xep_0359/stanza.py b/slixmpp/plugins/xep_0359/stanza.py
new file mode 100644
index 00000000..db8e9fff
--- /dev/null
+++ b/slixmpp/plugins/xep_0359/stanza.py
@@ -0,0 +1,35 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2020 Mathieu Pasquet <mathieui@mathieui.net>
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permissio
+"""
+
+from slixmpp.stanza import Message
+from slixmpp.xmlstream import (
+ ElementBase,
+ register_stanza_plugin,
+)
+
+
+NS = 'urn:xmpp:sid:0'
+
+
+class StanzaID(ElementBase):
+ namespace = NS
+ name = 'stanza-id'
+ plugin_attrib = 'stanza_id'
+ interfaces = {'id', 'by'}
+
+
+class OriginID(ElementBase):
+ namespace = NS
+ name = 'origin-id'
+ plugin_attrib = 'origin_id'
+ interfaces = {'id'}
+
+
+def register_plugins():
+ register_stanza_plugin(Message, StanzaID)
+ register_stanza_plugin(Message, OriginID)
diff --git a/slixmpp/plugins/xep_0359/stanzaid.py b/slixmpp/plugins/xep_0359/stanzaid.py
new file mode 100644
index 00000000..2235e74b
--- /dev/null
+++ b/slixmpp/plugins/xep_0359/stanzaid.py
@@ -0,0 +1,22 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2020 Mathieu Pasquet <mathieui@mathieui.net>
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permission.
+"""
+from slixmpp.plugins import BasePlugin
+from slixmpp.plugins.xep_0359 import stanza
+
+
+class XEP_0359(BasePlugin):
+ '''XEP-0359: Unique and Stable Stanza IDs'''
+
+ name = 'xep_0359'
+ description = 'Unique and Stable Stanza IDs'
+ dependencies = set()
+ stanza = stanza
+ namespace = stanza.NS
+
+ def plugin_init(self) -> None:
+ stanza.register_plugins()
diff --git a/slixmpp/plugins/xep_0422/__init__.py b/slixmpp/plugins/xep_0422/__init__.py
new file mode 100644
index 00000000..9a1575c1
--- /dev/null
+++ b/slixmpp/plugins/xep_0422/__init__.py
@@ -0,0 +1,13 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2020 Mathieu Pasquet <mathieui@mathieui.net>
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permission.
+"""
+
+from slixmpp.plugins.base import register_plugin
+from slixmpp.plugins.xep_0422.stanza import *
+from slixmpp.plugins.xep_0422.fastening import XEP_0422
+
+register_plugin(XEP_0422)
diff --git a/slixmpp/plugins/xep_0422/fastening.py b/slixmpp/plugins/xep_0422/fastening.py
new file mode 100644
index 00000000..68560e16
--- /dev/null
+++ b/slixmpp/plugins/xep_0422/fastening.py
@@ -0,0 +1,28 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2020 Mathieu Pasquet <mathieui@mathieui.net>
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permission.
+"""
+from slixmpp.plugins import BasePlugin
+from slixmpp.plugins.xep_0422 import stanza
+
+
+class XEP_0422(BasePlugin):
+ '''XEP-0422: Message Fastening'''
+
+ name = 'xep_0422'
+ description = 'Message Fastening'
+ dependencies = {'xep_0030'}
+ stanza = stanza
+ namespace = stanza.NS
+
+ def plugin_init(self) -> None:
+ stanza.register_plugins()
+
+ def session_bind(self, jid):
+ self.xmpp.plugin['xep_0030'].add_feature(feature=stanza.NS)
+
+ def plugin_end(self):
+ self.xmpp.plugin['xep_0030'].del_feature(feature=stanza.NS)
diff --git a/slixmpp/plugins/xep_0422/stanza.py b/slixmpp/plugins/xep_0422/stanza.py
new file mode 100644
index 00000000..a739809e
--- /dev/null
+++ b/slixmpp/plugins/xep_0422/stanza.py
@@ -0,0 +1,42 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2020 Mathieu Pasquet <mathieui@mathieui.net>
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permissio
+"""
+
+from slixmpp.stanza import Message
+from slixmpp.xmlstream import (
+ ElementBase,
+ register_stanza_plugin,
+)
+
+
+NS = 'urn:xmpp:fasten:0'
+
+
+class ApplyTo(ElementBase):
+ namespace = NS
+ name = 'apply-to'
+ plugin_attrib = 'apply_to'
+ interfaces = {'id', 'shell'}
+
+ def set_shell(self, value: bool):
+ if value:
+ self.xml.attrib['shell'] = str(value).lower()
+ else:
+ if 'shell' in self.xml.attrib:
+ del self.xml.attrib['shell']
+
+
+class External(ElementBase):
+ namespace = NS
+ name = 'external'
+ plugin_attrib = 'external'
+ interfaces = {'name'}
+
+
+def register_plugins():
+ register_stanza_plugin(Message, ApplyTo)
+ register_stanza_plugin(ApplyTo, External)
diff --git a/slixmpp/plugins/xep_0424/__init__.py b/slixmpp/plugins/xep_0424/__init__.py
new file mode 100644
index 00000000..0e5dfce1
--- /dev/null
+++ b/slixmpp/plugins/xep_0424/__init__.py
@@ -0,0 +1,13 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2020 Mathieu Pasquet <mathieui@mathieui.net>
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permission.
+"""
+
+from slixmpp.plugins.base import register_plugin
+from slixmpp.plugins.xep_0424.stanza import *
+from slixmpp.plugins.xep_0424.retraction import XEP_0424
+
+register_plugin(XEP_0424)
diff --git a/slixmpp/plugins/xep_0424/retraction.py b/slixmpp/plugins/xep_0424/retraction.py
new file mode 100644
index 00000000..5425a61f
--- /dev/null
+++ b/slixmpp/plugins/xep_0424/retraction.py
@@ -0,0 +1,62 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2020 Mathieu Pasquet <mathieui@mathieui.net>
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permission.
+"""
+from typing import Optional
+
+from slixmpp import JID, Message
+from slixmpp.exceptions import IqError, IqTimeout
+from slixmpp.plugins import BasePlugin
+from slixmpp.plugins.xep_0424 import stanza
+
+
+DEFAULT_FALLBACK = (
+ 'This person attempted to retract a previous message, but your client '
+ 'does not support it.'
+)
+
+
+class XEP_0424(BasePlugin):
+ '''XEP-0424: Message Retraction'''
+
+ name = 'xep_0424'
+ description = 'Message Retraction'
+ dependencies = {'xep_0422', 'xep_0030', 'xep_0359', 'xep_0428', 'xep_0334'}
+ stanza = stanza
+ namespace = stanza.NS
+
+ def plugin_init(self) -> None:
+ stanza.register_plugins()
+
+ def session_bind(self, jid):
+ self.xmpp.plugin['xep_0030'].add_feature(feature=stanza.NS)
+
+ def plugin_end(self):
+ self.xmpp.plugin['xep_0030'].del_feature(feature=stanza.NS)
+
+ def send_retraction(self, mto: JID, id: str, mtype: str = 'chat',
+ include_fallback: bool = True,
+ fallback_text: Optional[str] = None, *,
+ mfrom: Optional[JID] = None):
+ """
+ Send a message retraction
+ :param JID mto: The JID to retract the message from
+ :param str id: Message ID to retract
+ :param str mtype: Message type
+ :param bool include_fallback: Whether to include a fallback body
+ :param Optional[str] fallback_text: The contet of the fallback
+ body. None will set the default value.
+ """
+ if fallback_text is None:
+ fallback_text = DEFAULT_FALLBACK
+ msg = self.xmpp.make_message(mto=mto, mtype=mtype, mfrom=mfrom)
+ if include_fallback:
+ msg['body'] = fallback_text
+ msg.enable('fallback')
+ msg['apply_to']['id'] = id
+ msg['apply_to'].enable('retract')
+ msg.enable('store')
+ msg.send()
diff --git a/slixmpp/plugins/xep_0424/stanza.py b/slixmpp/plugins/xep_0424/stanza.py
new file mode 100644
index 00000000..c55af08c
--- /dev/null
+++ b/slixmpp/plugins/xep_0424/stanza.py
@@ -0,0 +1,38 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2020 Mathieu Pasquet <mathieui@mathieui.net>
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permissio
+"""
+
+from slixmpp.stanza import Message
+from slixmpp.xmlstream import (
+ ElementBase,
+ register_stanza_plugin,
+)
+from slixmpp.plugins.xep_0422.stanza import ApplyTo
+from slixmpp.plugins.xep_0359 import OriginID
+
+
+NS = 'urn:xmpp:message-retract:0'
+
+
+class Retract(ElementBase):
+ namespace = NS
+ name = 'retract'
+ plugin_attrib = 'retract'
+
+
+class Retracted(ElementBase):
+ namespace = NS
+ name = 'retracted'
+ plugin_attrib = 'retracted'
+ interfaces = {'stamp'}
+
+
+def register_plugins():
+ register_stanza_plugin(ApplyTo, Retract)
+ register_stanza_plugin(Message, Retracted)
+
+ register_stanza_plugin(Retracted, OriginID)
diff --git a/slixmpp/plugins/xep_0425/__init__.py b/slixmpp/plugins/xep_0425/__init__.py
new file mode 100644
index 00000000..2effe361
--- /dev/null
+++ b/slixmpp/plugins/xep_0425/__init__.py
@@ -0,0 +1,13 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2020 Mathieu Pasquet <mathieui@mathieui.net>
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permission.
+"""
+
+from slixmpp.plugins.base import register_plugin
+from slixmpp.plugins.xep_0425.stanza import *
+from slixmpp.plugins.xep_0425.moderation import XEP_0425
+
+register_plugin(XEP_0425)
diff --git a/slixmpp/plugins/xep_0425/moderation.py b/slixmpp/plugins/xep_0425/moderation.py
new file mode 100644
index 00000000..e840d80d
--- /dev/null
+++ b/slixmpp/plugins/xep_0425/moderation.py
@@ -0,0 +1,39 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2020 Mathieu Pasquet <mathieui@mathieui.net>
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permission.
+"""
+from typing import Optional
+
+from slixmpp import JID, Message
+from slixmpp.exceptions import IqError, IqTimeout
+from slixmpp.plugins import BasePlugin
+from slixmpp.plugins.xep_0425 import stanza
+
+
+class XEP_0425(BasePlugin):
+ '''XEP-0425: Message Moderation'''
+
+ name = 'xep_0425'
+ description = 'Message Moderation'
+ dependencies = {'xep_0424', 'xep_0421'}
+ stanza = stanza
+ namespace = stanza.NS
+
+ def plugin_init(self) -> None:
+ stanza.register_plugins()
+
+ def session_bind(self, jid):
+ self.xmpp.plugin['xep_0030'].add_feature(feature=stanza.NS)
+
+ def plugin_end(self):
+ self.xmpp.plugin['xep_0030'].del_feature(feature=stanza.NS)
+
+ async def moderate(self, room: JID, id: str, reason: str = '', *,
+ ifrom: Optional[JID] = None, **iqkwargs):
+ iq = self.xmpp.make_iq_set(ito=room.bare, ifrom=ifrom)
+ iq['apply_to']['id'] = id
+ iq['apply_to']['moderate']['reason'] = reason
+ await iq.send(**iqkwargs)
diff --git a/slixmpp/plugins/xep_0425/stanza.py b/slixmpp/plugins/xep_0425/stanza.py
new file mode 100644
index 00000000..9b756953
--- /dev/null
+++ b/slixmpp/plugins/xep_0425/stanza.py
@@ -0,0 +1,46 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2020 Mathieu Pasquet <mathieui@mathieui.net>
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permissio
+"""
+
+from slixmpp.stanza import Message, Iq
+from slixmpp.xmlstream import (
+ ElementBase,
+ register_stanza_plugin,
+)
+from slixmpp.plugins.xep_0422.stanza import ApplyTo
+from slixmpp.plugins.xep_0421.stanza import OccupantId
+from slixmpp.plugins.xep_0424.stanza import Retract, Retracted
+
+
+NS = 'urn:xmpp:message-moderate:0'
+
+
+class Moderate(ElementBase):
+ namespace = NS
+ name = 'moderate'
+ plugin_attrib = 'moderate'
+ interfaces = {'reason'}
+ sub_interfaces = {'reason'}
+
+
+class Moderated(ElementBase):
+ namespace = NS
+ name = 'moderated'
+ plugin_attrib = 'moderated'
+ interfaces = {'reason', 'by'}
+ sub_interfaces = {'reason'}
+
+
+def register_plugins():
+ register_stanza_plugin(Iq, ApplyTo)
+ register_stanza_plugin(ApplyTo, Moderate)
+ register_stanza_plugin(Moderate, Retract)
+
+ register_stanza_plugin(Message, Moderated)
+ register_stanza_plugin(ApplyTo, Moderated)
+ register_stanza_plugin(Moderated, Retracted)
+ register_stanza_plugin(Moderated, OccupantId)
diff --git a/slixmpp/plugins/xep_0428/__init__.py b/slixmpp/plugins/xep_0428/__init__.py
new file mode 100644
index 00000000..864f4ed3
--- /dev/null
+++ b/slixmpp/plugins/xep_0428/__init__.py
@@ -0,0 +1,13 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2020 Mathieu Pasquet <mathieui@mathieui.net>
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permission.
+"""
+
+from slixmpp.plugins.base import register_plugin
+from slixmpp.plugins.xep_0428.stanza import *
+from slixmpp.plugins.xep_0428.fallback import XEP_0428
+
+register_plugin(XEP_0428)
diff --git a/slixmpp/plugins/xep_0428/fallback.py b/slixmpp/plugins/xep_0428/fallback.py
new file mode 100644
index 00000000..61e913e3
--- /dev/null
+++ b/slixmpp/plugins/xep_0428/fallback.py
@@ -0,0 +1,22 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2020 Mathieu Pasquet <mathieui@mathieui.net>
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permission.
+"""
+from slixmpp.plugins import BasePlugin
+from slixmpp.plugins.xep_0428 import stanza
+
+
+class XEP_0428(BasePlugin):
+ '''XEP-0428: Fallback Indication'''
+
+ name = 'xep_0428'
+ description = 'Fallback Indication'
+ dependencies = set()
+ stanza = stanza
+ namespace = stanza.NS
+
+ def plugin_init(self) -> None:
+ stanza.register_plugins()
diff --git a/slixmpp/plugins/xep_0428/stanza.py b/slixmpp/plugins/xep_0428/stanza.py
new file mode 100644
index 00000000..41df80d0
--- /dev/null
+++ b/slixmpp/plugins/xep_0428/stanza.py
@@ -0,0 +1,26 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2020 Mathieu Pasquet <mathieui@mathieui.net>
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permissio
+"""
+
+from slixmpp.stanza import Message
+from slixmpp.xmlstream import (
+ ElementBase,
+ register_stanza_plugin,
+)
+
+
+NS = 'urn:xmpp:fallback:0'
+
+
+class Fallback(ElementBase):
+ namespace = NS
+ name = 'fallback'
+ plugin_attrib = 'fallback'
+
+
+def register_plugins():
+ register_stanza_plugin(Message, Fallback)
diff --git a/slixmpp/plugins/xep_0439/__init__.py b/slixmpp/plugins/xep_0439/__init__.py
new file mode 100644
index 00000000..6fa46cb4
--- /dev/null
+++ b/slixmpp/plugins/xep_0439/__init__.py
@@ -0,0 +1,13 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2020 Mathieu Pasquet <mathieui@mathieui.net>
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permission.
+"""
+
+from slixmpp.plugins.base import register_plugin
+from slixmpp.plugins.xep_0439.stanza import *
+from slixmpp.plugins.xep_0439.quickresponse import XEP_0439
+
+register_plugin(XEP_0439)
diff --git a/slixmpp/plugins/xep_0439/quickresponse.py b/slixmpp/plugins/xep_0439/quickresponse.py
new file mode 100644
index 00000000..74e299d6
--- /dev/null
+++ b/slixmpp/plugins/xep_0439/quickresponse.py
@@ -0,0 +1,91 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2020 Mathieu Pasquet <mathieui@mathieui.net>
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permission.
+"""
+from typing import (
+ Iterable,
+ Optional,
+ Tuple,
+)
+
+from slixmpp import JID
+from slixmpp.plugins import BasePlugin
+from slixmpp.plugins.xep_0439 import stanza
+
+
+class XEP_0439(BasePlugin):
+ '''XEP-0439: Quick Response'''
+
+ name = 'xep_0439'
+ description = 'Quick Response'
+ dependencies = set()
+ stanza = stanza
+ namespace = stanza.NS
+
+ def plugin_init(self) -> None:
+ stanza.register_plugins()
+
+ 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):
+ """
+ Send a message with a set of responses.
+
+ :param JID mto: The JID of the entity which will receive the message
+ :param str body: The message body of the question
+ :param Iterable[Tuple[str, str]] responses: A set of tuples containing
+ (value, label) for each response
+ :param str mtype: The message type
+ :param str lang: The lang of the message (if not use, the default
+ for this session will be used.
+ """
+ if lang is None:
+ lang = self.xmpp.default_lang
+ msg = self.xmpp.make_message(mto=mto, mfrom=mfrom, mtype=mtype)
+ msg['body|%s' % lang] = body
+ values = set()
+ for value, label in responses:
+ if value in values:
+ raise ValueError("Duplicate values")
+ values.add(value)
+ elem = stanza.Response()
+ elem['lang'] = lang
+ elem['value'] = value
+ elem['label'] = label
+ msg.append(elem)
+ msg.send()
+
+ def ask_for_actions(self, mto: JID, body: str,
+ actions: Iterable[Tuple[str, str]],
+ mtype: str = 'chat', lang: Optional[str] = None, *,
+ mfrom: Optional[JID] = None):
+ """
+ Send a message with a set of actions.
+
+ :param JID mto: The JID of the entity which will receive the message
+ :param str body: The message body of the question
+ :param Iterable[Tuple[str, str]] actions: A set of tuples containing
+ (action, label) for each action
+ :param str mtype: The message type
+ :param str lang: The lang of the message (if not use, the default
+ for this session will be used.
+ """
+ if lang is None:
+ lang = self.xmpp.default_lang
+ msg = self.xmpp.make_message(mto=mto, mfrom=mfrom, mtype=mtype)
+ msg['body|%s' % lang] = body
+ ids = set()
+ for id, label in actions:
+ if id in ids:
+ raise ValueError("Duplicate ids")
+ ids.add(id)
+ elem = stanza.Action()
+ elem['lang'] = lang
+ elem['id'] = id
+ elem['label'] = label
+ msg.append(elem)
+ msg.send()
diff --git a/slixmpp/plugins/xep_0439/stanza.py b/slixmpp/plugins/xep_0439/stanza.py
new file mode 100644
index 00000000..e00e1f27
--- /dev/null
+++ b/slixmpp/plugins/xep_0439/stanza.py
@@ -0,0 +1,43 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2020 Mathieu Pasquet <mathieui@mathieui.net>
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permissio
+"""
+
+from slixmpp.stanza import Message
+from slixmpp.xmlstream import (
+ ElementBase,
+ register_stanza_plugin,
+)
+
+
+NS = 'urn:xmpp:tmp:quick-response'
+
+
+class Response(ElementBase):
+ namespace = NS
+ name = 'response'
+ plugin_attrib = 'response'
+ interfaces = {'value', 'label'}
+
+
+class Action(ElementBase):
+ namespace = NS
+ name = 'action'
+ plugin_attrib = 'action'
+ interfaces = {'id', 'label'}
+
+
+class ActionSelected(ElementBase):
+ namespace = NS
+ name = 'action-selected'
+ plugin_attrib = 'action_selected'
+ interfaces = {'id'}
+
+
+def register_plugins():
+ register_stanza_plugin(Message, Action, iterable=True)
+ register_stanza_plugin(Message, ActionSelected)
+ register_stanza_plugin(Message, Response, iterable=True)