如何仅使用 Twisted 向 XMPP 服务器发送消息?

问题描述 投票:0回答:1

我需要向 XMPP 服务器发送消息。仅发送 - 我不需要处理回复、创建机器人或类似的东西。当使用

xmpppy
模块时,它是这样的:

from xmpp import Client
from xmpp.protocol import JID, Message


jabberid = '[email protected]'
password = 'secret'
receiver = '[email protected]'
message = 'Hello world!'

jid = JID(jabberid)
connection = Client(server=jid.getDomain(), debug=None)
connection.connect()
connection.auth(user=jid.getNode(), password=password, resource=jid.getResource())
connection.send(Message(to=receiver, body=message))

但是,我需要使用 Twisted 来完成此操作。不幸的是,该文档大多无用(似乎是机器生成的),我完全不知道我应该做什么。 :-(

也许类似

from twisted.words.protocols.jabber.jid import JID
from twisted.words.protocols.jabber.client import XMPPAuthenticator

jabberid = '[email protected]'
password = 'secret'

jid = JID(jabberid)
XMPPAuthenticator(jid, password)

但是然后呢?

python xmpp twisted
1个回答
0
投票

https://twisted.org/ 单击“查看文档”按钮,然后从左侧索引中选择“Twisted Words (IRC 和 XMPP)”,然后在结果页面上选择“示例”,然后下载xmpp_client.py 示例。

在此示例中,您将了解如何使用反应器使客户端连接到服务器、如何使用引导 API 处理基本连接管理事件以及如何进行基本状态管理。

之后,这取决于您要发送的消息的“种类”(例如,通过发送消息来管理状态)。 如果您想发送 XEP-0045“群聊”消息,如 https://xmpp.org/extensions/xep-0045.html#message 中所述,请使用 xish API 构造一条消息并发送,而不是发送或连同您的状态消息。

© www.soinside.com 2019 - 2024. All rights reserved.