This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def handleIncomingMessage(self, message): | |
self.xmpp.sendMessage(message["from"], message["body"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def handleIncomingXMPPEvent(self, event): | |
msgLocations = {sleekxmpp.stanza.presence.Presence: "status", | |
sleekxmpp.stanza.message.Message: "body"} | |
message = event[msgLocations[type(event)]] | |
user = self.backend.getUserFromJID(event["from"].jid) | |
if user is not None: | |
self.backend.addMessageFromUser(message, user) | |
def handleMessageAddedToBackend(self, message) : |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def handleConfigurationCommand(self, form, sessionId): | |
values = form.getValues() | |
monitorPresence =values["monitorPresence"] | |
jid = self.xmpp.plugin["xep_0050"].sessions[sessionId]["jid"] | |
user = self.backend.getUserFromJID(jid) | |
self.backend.setShouldMonitorPresenceFromUser(user, monitorPresence) | |
def handleIncomingXMPPPresence(self, event): | |
user = self.backend.getUserFromJID(event["from"].jid) | |
if user is not None: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def handleXMPPPresenceProbe(self, event) : | |
self.xmpp.sendPresence(pto = event["from"]) | |
def handleXMPPPresenceSubscription(self, subscription) : | |
if subscription["type"] == "subscribe" : | |
userJID = subscription["from"].jid | |
self.xmpp.sendPresenceSubscription(pto=userJID, ptype="subscribed") | |
self.xmpp.sendPresence(pto = userJID) | |
self.xmpp.sendPresenceSubscription(pto=userJID, ptype="subscribe") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def handleIncomingXMPPMessage(self, event) : | |
message = self.addRecipientToMessage(event["body"], event["to"].jid) | |
user = self.backend.getUserFromJID(event["from"].jid) | |
self.backend.addMessageFromUser(message, user) | |
def handleIncomingXMPPPresence(self, event) : | |
if event["to"].jid == self.componentDomain : | |
user = self.backend.getUserFromJID(event["from"].jid) | |
self.backend.addMessageFromUser(event["status"], user) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def handleMessage(self, msg): | |
print (msg.keys()) # prints (to, from, type, body, subject, mucroom, mucnick) | |
print (msg['body']) # prints the message body | |
msg.reply("Thanks for sending me \"%(body)s\"" % msg).send() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<iq type="set"> | |
<task id="123" xmlns="example:task"> | |
<command>python script.py</command> | |
<cleanup>rm temp.txt</cleanup> | |
<param> | |
<name>foo</name> | |
<value>fizz</value> | |
</param> | |
<param> | |
<name>bar</name> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sleekxmpp | |
from sleekxmpp.xmlstream.stanzabase import ElementBase, ET, JID | |
from sleekxmpp.stanza.iq import Iq | |
class Param(ElementBase): | |
namespace = 'example:task' | |
name = 'param' | |
plugin_attrib = 'param' | |
interfaces = set(('name', 'value')) | |
sub_interfaces = interfaces |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sleekxmpp | |
from sleekxmpp.xmlstream.stanzabase import ElementBase, ET, JID | |
from sleekxmpp.stanza.iq import Iq | |
class Param(ElementBase): | |
namespace = 'example:task' | |
name = 'param' | |
plugin_attrib = 'param' | |
interfaces = set(('name', 'value')) | |
sub_interfaces = interfaces |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If self.xmpp is a SleekXMPP object and Task is a stanza object class | |
# See the wiki page Stanza Objects for details on Task | |
self.xmpp.registerHandler( | |
Callback('Example Handler', | |
MatchXPath('{%s}iq/{%s}task' % (self.xmpp.default_ns, Task.namespace), | |
self.handle_task)) |