blab_chatbot_bot_client.conversation#

Contains a class that interacts with BLAB Controller.

The actual behaviour is implemented in subclasses (such as WebSocketBotClientConversation).

Module Contents#

Classes#

BotClientConversation

Represents a conversation on the client.

Attributes#

SettingsType#
class BotClientConversation(settings, conversation_id, bot_participant_id)#

Bases: Generic[SettingsType]

Represents a conversation on the client.

Create an instance.

Parameters:
  • settings (SettingsType) – bot settings

  • conversation_id (str) – id of the conversation

  • bot_participant_id (str) – id of the participant correspondent to the bot

enqueue_message(message)#

Enqueue a message to be sent to the controller.

Parameters:

message (OutgoingMessage) – the message to be sent

Return type:

None

on_connect()#

Handle the successful connection with the controller.

This method does nothing. The behaviour is defined by subclasses.

Return type:

None

on_receive_message(message)#

Handle the arrival of a new message.

This method does nothing. The behaviour is defined by subclasses.

Note that this method is also called when the bot’s own messages are delivered.

Parameters:

message (Message) – the incoming message

Return type:

None

on_receive_state(event)#

Handle the arrival of a new event message describing the current state.

This method updates the internal cached state.

Parameters:

event (dict[str, Any]) – the event data

Return type:

None

generate_answer(message)#

Generate zero or more answers to a given message.

This method returns an empty list. Subclasses should implement the desired behaviour.

Parameters:

message (Message) – the message which should be answered

Returns:

a list with the answers

Return type:

list[OutgoingMessage]

generate_greeting()#

Generate zero or more greetings to the user.

This method returns an empty list. Subclasses should implement the desired behaviour.

Returns

a list with the greetings

Return type:

list[OutgoingMessage]

classmethod bot_sends_first_message()#

Whether the bot sends the first message.

This method returns False by default, but subclasses should override it if the bots can initiate a conversation.

Returns

True if this bot sends a greeting message to the user before their first message

Return type:

bool

classmethod generate_local_id()#

Generate a unique local id to a message.

Each outgoing message should have a new local id. It is used by the controller to discard repeated attempts to send the same message after one successful delivery. It can also be used by bots to be notified when its own messages have been delivered.

Returns

the generated local id

Return type:

str