Utils

Utils for the Integreat Chat

Chat Bot

Wrapper for the Chat Bot / LLM API

async integreat_cms.api.v3.chat.utils.chat_bot.async_process_answer(message_text: str, source_language: str, target_language: str) dict[source]

Process automatic or counselor answers

Parameters:
  • message_text (str)

  • source_language (str)

  • target_language (str)

Return type:

dict

async integreat_cms.api.v3.chat.utils.chat_bot.async_process_user_message(zammad_chat_language_slug: str, region_slug: str, region_default_language_slug: str, message_text: str) tuple[dict, dict][source]

Process the message from an Integreat App user

Parameters:
  • zammad_chat_language_slug (str)

  • region_slug (str)

  • region_default_language_slug (str)

  • message_text (str)

Return type:

tuple[dict, dict]

async integreat_cms.api.v3.chat.utils.chat_bot.automatic_answer(message: str, region_slug: str, language_slug: str, session: ClientSession) dict[source]

Get automatic answer to question asynchronously

Parameters:
  • message (str)

  • region_slug (str)

  • language_slug (str)

  • session (ClientSession)

Return type:

dict

async integreat_cms.api.v3.chat.utils.chat_bot.automatic_translation(message: str, source_language_slug: str, target_language_slug: str, session: ClientSession) dict[source]

Use LLM to translate message asynchronously

Parameters:
  • message (str)

  • source_language_slug (str)

  • target_language_slug (str)

  • session (ClientSession)

Return type:

dict

Zammad API

class integreat_cms.api.v3.chat.utils.zammad_api.ZammadChatAPI(region: Region)[source]

Bases: object

Class providing an API for Zammad used in the context of user chats.

Parameters:
  • url – The region’s Zammad URL

  • http_token – The region’s client secret

  • region (Region)

__init__(region: Region)[source]
Parameters:

region (Region)

create_ticket(device_id: str, language_slug: str) dict[source]

Create a new ticket (i.e. initialize a new chat conversation)

Parameters:
  • device_id (str) – ID of the user requesting a new chat

  • language_slug (str) – user’s language

Return type:

dict

get_attachment(attachment_map: AttachmentMap) bytes | dict[source]

Get the (binary) attachment file from Zammad.

Parameters:

attachment_map (AttachmentMap) – the object containing the IDs Zammad requires to identify attachments

Returns:

the binary object file or a dict containing an error message

Return type:

bytes | dict

get_messages(chat: UserChat) dict[str, dict | list[dict] | str][source]

Get all non-internal messages for a given ticket

Parameters:

chat (UserChat) – UserChat instance for the relevant Zammad ticket

Return type:

dict[str, dict | list[dict] | str]

send_message(chat_id: int, message: str, internal: bool = False, automatic_message: bool = False) dict[source]

Post a new message to the given ticket

param chat_id: Zammad ID of the chat param message: The message body param internal: keep the message internal in Zammad (do not show to user) param automatic_message: sets title to “automatically generated message” return: dict with Zammad article data

Parameters:
  • chat_id (int)

  • message (str)

  • internal (bool)

  • automatic_message (bool)

Return type:

dict