Client¶
- class osmxmpp.client.XmppClient(host, port=5222)¶
Bases:
objectXMPP client implementation.
- connect()¶
Connects to the XMPP server.
- Return type:
None
- connect_extension(extension, permissions)¶
Connects the given extension to the XMPP client.
- Parameters:
extension (XmppExtension) – The extension to connect.
permissions (List[XmppPermission] | XmppPermission.ALL) – The permissions to grant.
- Return type:
None
Example
>>> client.connect_extension(SomeExtension(), XmppPermission.ALL)
- connect_extensions(extensions_with_permissions)¶
Connects the given extensions to the XMPP client.
- Parameters:
extensions_with_permissions (List[Tuple[XmppExtension, List[XmppPermission] | XmppPermission.ALL]]) – The extensions with permissions to connect
- Return type:
None
Example
>>> client.connect_extensions([ ... (SomeExtension(), [XmppPersmision.SEND_XML, XmppPersmision.RECV_XML]) ... (SomeOtherExtension(), XmppPermission.ALL) ... ])
- connect_feature(feature, permissions)¶
Connects the given feature to the XMPP client.
- Parameters:
feature (XmppFeature) – The feature to connect.
permissions (List[XmppPermission] | XmppPermission.ALL) – The permissions to grant.
- Return type:
None
Example
>>> client.connect_feature(BindFeature("osmxmpp"), XmppPermission.ALL)
- connect_features(features_with_permissions)¶
Connects the given features to the XMPP client.
- Parameters:
features_with_permissions (List[Tuple[XmppFeature, List[XmppPermission] | XmppPermission.ALL]]) – The features with permissions to connect
- Return type:
None
Example
>>> client.connect_features([ ... (TLSFeature(), [XmppPersmision.SEND_XML, XmppPersmision.RECV_XML]) ... (BindFeature("osmxmpp"), XmppPermission.ALL) ... ])
- property connected¶
- disconnect()¶
Disconnects from the XMPP server.
- edit_message(*args, **kwargs)¶
Editing specific message.
- Parameters:
message_id (str) – The message ID to edit.
jid (str) – The JID to send the message to.
message (str) – The message to send.
type (str) – The message type. (Default: “chat”)
Example
>>> client.edit_message("12345679", "john@jabber.org", "Thank you very much, John!")
- property extensions¶
- hook_on_iq(hook)¶
Registers a hook for the iq event. The hook will be called when the client receives an iq stanza.
- Parameters:
hook (Callable) – The hook to register.
- Returns:
The hook (not changed).
- Return type:
Callable
- hook_on_message(hook)¶
Registers a hook for the message event. The hook will be called when the client receives a message stanza.
- Parameters:
hook (Callable) – The hook to register.
- Returns:
The hook (not changed).
- Return type:
Callable
- hook_on_presence(hook)¶
Registers a hook for the presence event. The hook will be called when the client receives a presence stanza.
- Parameters:
hook (Callable) – The hook to register.
- Returns:
The hook (not changed).
- Return type:
Callable
- hook_send_message(hook)¶
Registers a hook for the send message event. The hook will be called when the client sends a message.
- Parameters:
hook (Callable) – The hook to register.
- Returns:
The hook (not changed).
- Return type:
Callable
- on_connect(handler)¶
Registers a handler for the connected event. The handler will be called when the client is connected to the XMPP server, but not ready yet.
- Parameters:
handler (Callable) – The handler to register.
- Returns:
The handler (not changed).
- Return type:
Callable
- on_disconnect(handler)¶
Registers a handler for the disconnected event. The handler will be called when the client is disconnected from the XMPP server.
- Parameters:
handler (Callable) – The handler to register.
- Returns:
The handler (not changed).
- Return type:
Callable
- on_iq(handler)¶
Registers a handler for the iq event. The handler will be called when the client receives an iq stanza.
- Parameters:
handler (Callable) – The handler to register.
- Returns:
The handler (not changed).
- Return type:
Callable
- on_message(handler)¶
Registers a handler for the message event. The handler will be called when the client receives a message stanza.
- Parameters:
handler (Callable) – The handler to register.
- Returns:
The handler (not changed).
- Return type:
Callable
Example
>>> @client.on_message ... def on_message(message): ... if message.body is None: #Messages body can be empty ... return ... ... print(f"Received message from {message.from_jid}: {message.body}")
- on_presence(handler)¶
Registers a handler for the presence event. The handler will be called when the client receives a presence stanza.
- Parameters:
handler (Callable) – The handler to register.
- Returns:
The handler (not changed).
- Return type:
Callable
- on_ready(handler)¶
Registers a handler for the ready event. The handler will be called when the client is ready to send and receive XMPP stanzas.
- Parameters:
handler (Callable) – The handler to register.
- Returns:
The handler (not changed).
- Return type:
Callable
Example
>>> @client.on_ready ... def on_ready(): ... print(f"Loggened in as {client.jid}")
- reply_to_message(*args, **kwargs)¶
Replies to specific message.
- Parameters:
message_id (str) – The message ID to reply to.
jid (str) – The JID to send the message to.
message (str) – The message to send.
type (str) – The message type. (Default: “chat”)
message_author (str) – The replied message author. If none, equals to jid. (Default: None)
Example
>>> client.reply_to_message("12345678", "john@jabber.org", "Thanks, John!")
- send_message(*args, **kwargs)¶
Sends a message to the given JID.
- Parameters:
jid (str) – The JID to send the message to.
message (str) – The message to send.
type (str) – The message type. (Default: “chat”)
Example
>>> client.send_message("john@jabber.org", "Hello, John!")