Utils

Utils for the Integreat Chat

Chat Bot

Wrapper for the Chat Bot / LLM API

integreat_cms.api.v3.chat.utils.chat_bot.automatic_answer(message: str, region: Region, language_slug: str) str | None[source]

Get automatic answer to question

Parameters:
Return type:

str | None

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

Use LLM to translate message

Parameters:
  • message (str)

  • source_language_slug (str)

  • target_language_slug (str)

Return type:

str

integreat_cms.api.v3.chat.utils.chat_bot.format_message(response: dict) str[source]

Transform JSON into readable message

Parameters:

response (dict)

Return type:

str

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]][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]]

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