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 or dict) – 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_FILE = 'bot_reply_file'#

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

Type:

PayloadAction

BOT_REPLY_IMAGE = 'bot_reply_image'#

Indicates that the payload’s purpose is to send a bot reply containing a file.File object, specifically an image.

Type:

PayloadAction

BOT_REPLY_LOCATION = 'bot_reply_location'#

Indicates that the payload’s purpose is to send a bot reply containing a location, which is a dictionary composed by a latitude and a longitude.

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_PLOTLY = 'bot_reply_plotly'#

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

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_FILE = 'user_file'#

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

Type:

PayloadAction

USER_MESSAGE = 'user_message'#

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

Type:

PayloadAction

USER_VOICE = 'user_voice'#

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

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