简体   繁体   中英

Send XMPP message with custom element in message stanza using SleekXMPP

I'm developing a XMPP bot that will send/reply a message to the sender with a addition element as following

<message to="user1@example.com" from="user2@example.com">
  <my_element_1>foo</my_element_1> 
  <my_element_2>bar</my_element_2>
  <body>Hi!</body>
</message>

I've tried to used SleekXMPP Object , Iq , Message but not able to achieve the target. Beside, I also tried to use send_message method.

I'm not sure if my googling keyword is not correct but I'm not able to find any documentation or guide related to this. However, I did found guide that might be helpful for this related to plugin creation. Will be much appreciated if someone could help me on this.

Thank you

I just realised that my understanding is not correct. Technically, to achieve this, I just need to do the following.

# create XML for element 1
element1 = ET.Element('my_element_1')
element1.text = 'foo'

# create XML for element 2
element2 = ET.Element('my_element_2')
element2.text = 'foo'

If needed, I can simply add child for the xml.

child = ET.Element('child-key')
child.text = 'child-value'
media.append(child)

In the Message object, I would just append as following

msg = self.Message()
msg.appendxml(element1)
msg.appendxml(element2)
msg.send()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM