payload#

class besser.bot.platforms.payload.Payload(action, message=None)[source]#

Bases: object

Represents a payload object used for encoding and decoding messages between a bot and any other external agent.

static decode(payload_str)[source]#

Decode a JSON payload string into a Payload object.

Parameters:

payload_str (str) – A JSON-encoded payload string.

Returns:

A Payload object if the decoding is successful, None otherwise.

Return type:

Payload or None

class besser.bot.platforms.payload.PayloadAction(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: Enum

Enumeration of the different possible actions embedded into a Payload.

BOT_REPLY_DF = 'bot_reply_dataframe'#

Indicates that the payload’s purpose is to send a bot reply containing a pandas.DataFrame object.

Type:

PayloadAction

BOT_REPLY_OPTIONS = 'bot_reply_options'#

Indicates that the payload’s purpose is to send a bot reply containing a list of strings, where the user should select 1 of them.

Type:

PayloadAction

BOT_REPLY_STR = 'bot_reply_str'#

Indicates that the payload’s purpose is to send a bot reply containing a str object.

Type:

PayloadAction

RESET = 'reset'#

Use the WebSocketPlatform on this bot.

Type:

PayloadAction

USER_MESSAGE = 'user_message'#

Indicates that the payload’s purpose is to send a user message.

Type:

PayloadAction

class besser.bot.platforms.payload.PayloadEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]#

Bases: JSONEncoder

Encoder for the Payload class.

Example

import json
encoded_payload = json.dumps(payload, cls=PayloadEncoder)
default(obj)[source]#

Returns a serializable object for a Payload

Parameters:

obj – the object to serialize

Returns:

the serialized payload

Return type:

dict