Chat

This package contains all models for the author and user chats

Chat Message

class integreat_cms.cms.models.chat.chat_message.ChatHistoryManager(*args, **kwargs)[source]

Bases: Manager

Custom manager for returning the chat history of the last x days (as configured in AUTHOR_CHAT_HISTORY_DAYS)

get_queryset() QuerySet[source]

Custom queryset with applied filters to return the chat messages of the last x days

Returns:

The QuerySet of the most recent chat history

Return type:

QuerySet

class integreat_cms.cms.models.chat.chat_message.ChatMessage(*args, **kwargs)[source]

Bases: AbstractBaseModel

A model for a message in the author chat

Parameters:

Relationship fields:

Parameters:

sender (ForeignKey to User) – Sender (related name: chat_messages)

exception DoesNotExist[source]

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned[source]

Bases: MultipleObjectsReturned

get_repr() str[source]

This overwrites the default Django __repr__() method which would return <ChatMessage: ChatMessage object (id)>. It is used for logging.

Returns:

The canonical string representation of the chat message

Return type:

str

history = <integreat_cms.cms.models.chat.chat_message.ChatHistoryManager object>[source]

Django manager to access the ORM Use ChatMessage.objects.all() to fetch all objects.

A manager for the most recent chat history

objects = <django.db.models.Manager object>[source]

Django manager to access the ORM Use ChatMessage.objects.all() to fetch all objects.

The default manager

User Chat

class integreat_cms.cms.models.chat.user_chat.ABTester(*args, **kwargs)[source]

Bases: AbstractBaseModel

A helper model for keeping track of A/B testers for the chat feature

Parameters:

Relationship fields:

Parameters:

region (ForeignKey to Region) – Region (related name: abtester)

exception DoesNotExist[source]

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned[source]

Bases: MultipleObjectsReturned

get_repr() str[source]

This overwrites the default Django __repr__() method which would return <ABTester: ABTester object (id)>. It is used for logging.

Returns:

The canonical string representation of the ab tester

Return type:

str

class integreat_cms.cms.models.chat.user_chat.UserChat(*args, **kwargs)[source]

Bases: AbstractBaseModel, ZammadAPI

A model for a user (app) chat, mapping a device ID to a Zammad ticket ID

Parameters:
  • id (BigAutoField) – Primary key: ID

  • device_id (CharField) – Device id

  • zammad_id (IntegerField) – Zammad id

  • total_words_generated (IntegerField) – Total words generated. Number of words generated in this chat.

  • created_timestamp (DateTimeField) – Created timestamp. Date and time when the chat was started.

  • last_message_timestamp (DateTimeField) – Last message timestamp. Date and time when the last chat message was sent.

Relationship fields:

Parameters:
exception DoesNotExist[source]

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned[source]

Bases: MultipleObjectsReturned

as_dict() dict[str, Any][source]

API compatible dict representation of the chat

Return type:

dict[str, Any]

get_repr() str[source]

This overwrites the default Django __repr__() method which would return <UserChat: UserChat object (id)>. It is used for logging.

Returns:

The canonical string representation of the user chat

Return type:

str

property is_expired: bool[source]

Whether the chat has been inactive long enough that its Zammad ticket is assumed to be gone (Zammad’s ticket retention is shorter than ours).

Using the timestamp avoids an extra request to the Zammad API on every chat request just to check whether the ticket still exists.

Returns:

True if the chat is considered expired, False otherwise

update_mt_budget(words_generated: int) None[source]

Update the machine translation budget and number of generated words.

Parameters:
  • words_generate – the number of words generated in an automatic response

  • words_generated (int)

Return type:

None

class integreat_cms.cms.models.chat.user_chat.UserChatManager(*args, **kwargs)[source]

Bases: Manager

custom manager providing function to get the current chat

create(region: Region, device_id: str, language: Language) UserChat[source]

Override super create method to create a Zammad ticket for each new chat

Parameters:
  • region (Region) – Region to which the chat belongs

  • device_id (str) – UUID identifying a chat/device

  • language (Language) – the UI language of the app

Return type:

UserChat

current_chat(device_id: str, **kwargs: Any) UserChat[source]

Return only the newest (i.e. current) chat for a given device_id

Parameters:
  • device_id (str) – the device id for which we want the current chat

  • **kwargs (Any) – The supplied kwargs

Returns:

the current chat for the given device_id

Return type:

UserChat