slidge.core.command
#
This module implements an unified way to define ad-hoc or chatbot-type commands
Submodules#
Package Contents#
Classes#
Abstract base class to implement gateway commands (chatbot and ad-hoc) |
|
Defines who can access a given Command |
|
A confirmation 'dialog' |
|
A form, to request user input |
|
Represents a field of the form that a user will see when registering to the gateway |
|
Results of the search command (search for contacts via Jabber Search) |
|
Structured data as the result of a command |
Attributes#
- class slidge.core.command.Command(xmpp)[source]#
Bases:
abc.ABC
Abstract base class to implement gateway commands (chatbot and ad-hoc)
- Parameters:
xmpp (slidge.core.gateway.BaseGateway) –
- ACCESS: CommandAccess#
Who can use this command
- subclasses#
- classmethod __init_subclass__(**kwargs)#
- async run(session, ifrom, *args)#
Entry point of the command
- Parameters:
session (Optional[slidge.core.session.BaseSession]) – If triggered by a registered user, its slidge Session
ifrom (slixmpp.JID) – JID of the command-triggering entity
args – When triggered via chatbot type message, additional words after the CHAT_COMMAND string was passed
- Returns:
Either a TableResult, a Form, a Confirmation, a text, or None
- Return type:
CommandResponseType
- _get_session(jid)#
- Parameters:
jid (slixmpp.JID) –
- raise_if_not_authorized(jid)#
Raise an appropriate error is jid is not authorized to use the command
- Parameters:
jid (slixmpp.JID) – jid of the entity trying to access the command
:return:session of JID if it exists
- class slidge.core.command.CommandAccess[source]#
-
Defines who can access a given Command
Initialize self. See help(type(self)) for accurate signature.
- ADMIN_ONLY = 0#
- USER = 1#
- USER_LOGGED = 2#
- USER_NON_LOGGED = 3#
- NON_USER = 4#
- ANY = 5#
- class slidge.core.command.Confirmation[source]#
A confirmation ‘dialog’
- handler: Callable#
An async function that should return a ResponseType
- handler_args: Iterable[Any]#
arguments passed to the handler
- get_form()#
Get the slixmpp form
- Returns:
some xml
- class slidge.core.command.Form[source]#
A form, to request user input
- handler: Callable#
- handler_args: Iterable[Any]#
- get_values(slix_form)#
Parse form submission
- get_xml()#
Get the slixmpp “form”
- Returns:
some XML
- class slidge.core.command.FormField[source]#
Represents a field of the form that a user will see when registering to the gateway via their XMPP client.
- var: str = ''#
Internal name of the field, will be used to retrieve via
slidge.GatewayUser.registration_form
- private: bool = False#
For sensitive info that should not be displayed on screen while the user types. Forces field_type to “text-private”
- value: str = ''#
Pre-filled value. Will be automatically pre-filled if a registered user modifies their subscription
- dict()#
- __post_init__()#
- __acceptable_options()#
- validate(value)#
Raise appropriate XMPPError if a given value is valid for this field
- Parameters:
value (str) – The value to test
- Returns:
The same value OR a JID if
self.type=jid-single
- get_xml()#
Get the field in slixmpp format
- Returns:
some XML
- class slidge.core.command.SearchResult[source]#
Bases:
TableResult
Results of the search command (search for contacts via Jabber Search)
- class slidge.core.command.TableResult[source]#
Structured data as the result of a command
- items: Collection[dict[str, str]]#
The rows of the table. Each row is a dict where keys are the fields
var
attribute.
- get_xml()#
Get a slixmpp “form” (with <reported> header)to represent the data
- Returns:
some XML