chat.chats#

Contains code that controls the events in a chat.

Module Contents#

Classes#

Chat

Represents a conversation.

ChatLimits

Maximum size of each attachment type.

Functions#

_get_bot(bot_spec, bot_participant_id, conversation_id)

_get_bot(bot_spec, bot_participant_id, conversation_id)#
Parameters:
  • bot_spec (tuple[str, str, bool, list[Any], dict[Any, Any]]) –

  • bot_participant_id (str | UUID) –

  • conversation_id (str) –

Return type:

Bot

class Chat(conversation)#

Represents a conversation.

Note that the Conversation represents a database entity, whereas Chat contains methods that manage the events that occur in a conversation.

Create an instance.

Parameters:

conversation (Conversation) – Conversation instance

_all_chats#
classmethod on_create_conversation(nickname, bots, conversation)#

Create Participant instances when a conversation is started.

This method creates the participants for the human user and the bots. Also, it generates system messages indicating that the conversation has been created and the participants have joined it.

A new instance of Chat is created and stored.

Parameters:
  • nickname (str) – name of the user who created the conversation

  • bots (list[str]) – list of bot names to invite to the conversation

  • conversation (Conversation) – the Conversation instance

Returns:

the list of participants in the conversation (the human participant is the first entry)

Return type:

list[Participant]

_on_create(nickname, bots)#

Create Participant instances when the conversation is started.

This method creates the participants for the human user and the bots. Also, it generates system messages indicating that the conversation has been created and the participants have joined it.

Parameters:
  • nickname (str) – name of the user who created the conversation

  • bots (list[str]) – list of bot names to invite to the conversation

Returns:

the list of participants in the conversation (the human participant is the first entry)

Return type:

list[Participant]

generate_participant_joined_system_message(participant_id)#

Create a message indicating that a participant has joined the conversation.

Parameters:

participant_id (str | UUID) – id of the participant

Returns:

the created message

Return type:

Message

_create_human_participant(nickname)#
Parameters:

nickname (str) –

Return type:

Participant

join(nickname)#

Create a Participant instance when a human user joins a conversation.

This method creates the participant instance and generates a system message indicating that it have joined the conversation.

Parameters:

nickname (str) – name of the user who joined the conversation

Returns:

the new participant instance corresponding to the participant who joined

Return type:

Participant

save_message(participant, message_data)#

Store a message sent by a human or bot.

Parameters:
  • participant (Participant) – the sender

  • message_data (dict[str, Any]) – mesesage data as a dictionary

Returns:

the created Message instance

Return type:

Message

_redirect_message(message, targets, field_overrides=None)#
Parameters:
  • message (Message) –

  • targets (list[str]) –

  • field_overrides (dict[str, Any] | None) –

Return type:

None

deliver_message_to_bot(message, bot, field_overrides=None)#

Deliver a message only to the specified bot.

Parameters:
  • message (Message) – the message to be delivered

  • bot (Participant) – the bot which will receive the message

  • field_overrides (dict[str, Any] | None) – dict from field names to the values that should replace the actual values

Return type:

None

deliver_status_to_bot(status, bot)#

Deliver status only to the specified bot.

Parameters:
  • status (dict[str, Any]) – the status information to be delivered

  • bot (Participant) – the bot which will receive the message

Return type:

None

classmethod get_chat(conversation_id)#

Obtain a Chat instance for a given conversation.

Parameters:

conversation_id (str | UUID) – id of the conversation

Returns:

a Chat instance if it exists for the given conversation id, of None if it does not exist

Return type:

Chat | None

class ChatLimits#

Bases: TypedDict

Maximum size of each attachment type.

Initialize self. See help(type(self)) for accurate signature.

MAX_ATTACHMENT_SIZE: int#

maximum size of an attached file (in bytes)

MAX_IMAGE_SIZE: int#

maximum size of an image file (in bytes)

MAX_VIDEO_SIZE: int#

maximum size of a video file (in bytes)

MAX_AUDIO_SIZE: int#

maximum size of an audio file (in bytes)

MAX_VOICE_SIZE: int#

maximum size of a voice recording file (in bytes)