Chat

Chat Bot

Wrapper for the Chat Bot / LLM API

class integreat_cms.api.v3.chat.chat_bot.ChatBot(hostname: str = 'igchat-inference.tuerantuer.org')[source]

Bases: object

API Wrapper for the LLM / Chat Bot

Parameters:

hostname (str)

__init__(hostname: str = 'igchat-inference.tuerantuer.org')[source]
Parameters:

hostname (str)

automatic_answer(message: str, region: Region, language_slug: str) str[source]

Get automatic answer to question

Parameters:
Return type:

str

automatic_translation(message: str, source_lang_slug: str, target_lang_slug: str) str[source]

Use LLM to translate message

Parameters:
  • message (str)

  • source_lang_slug (str)

  • target_lang_slug (str)

Return type:

str

format_message(response: dict) str[source]

Transform JSON into readable message

Parameters:

response (dict)

Return type:

str

User Chat

This module provides the API endpoints for the Integreat Chat API

integreat_cms.api.v3.chat.user_chat.chat(request: HttpRequest, region_slug: str, language_slug: str, device_id: str, attachment_id: str = '') JsonResponse | HttpResponse[source]

Function to send a new message in the current chat of a specified device_id, or to create one if no chat exists or the user requested a new one.

Parameters:
  • request (HttpRequest) – Django request

  • region_slug (str) – slug of a region

  • language_slug (str) – language slug

  • device_id (str) – ID of the user requesting the messages

  • attachment_id (str) – ID of the requested attachment (optional)

Returns:

JSON object according to APIv3 chat endpoint definition

Return type:

JsonResponse | HttpResponse

integreat_cms.api.v3.chat.user_chat.get_attachment(client: ZammadChatAPI, user_chat: UserChat | None, attachment_id: str) JsonResponse | HttpResponse[source]

Function to retrieve an attachment given the correct attachment_id

Parameters:
  • client (ZammadChatAPI) – the Zammad API client to use

  • user_chat (UserChat | None) – the device_id’s current chat (if one exists)

  • attachment_id (str) – ID of the requested attachment

Returns:

JSON object according to APIv3 offers endpoint definition

Return type:

JsonResponse | HttpResponse

integreat_cms.api.v3.chat.user_chat.get_messages(request: HttpRequest, client: ZammadChatAPI, user_chat: UserChat | None, device_id: str) JsonResponse[source]

Function to retrieve all messages of the most recent chat for a given device_id

Parameters:
  • request (HttpRequest) – Django request

  • client (ZammadChatAPI) – the Zammad API client to use

  • user_chat (UserChat | None) – the device_id’s current chat

  • device_id (str) – ID of the user requesting the messages

Returns:

JSON object according to APIv3 offers endpoint definition

Return type:

JsonResponse

integreat_cms.api.v3.chat.user_chat.is_chat_enabled_for_user(request: HttpRequest, region_slug: str, device_id: str) JsonResponse[source]

Function to check if the chat feature is enabled for the given region and the given user.

Parameters:
  • request (HttpRequest) – Django request

  • region_slug (str) – slug of a region

  • device_id (str) – ID of the user attempting to use the chat

Returns:

JSON object according to APIv3 chat endpoint definition

Return type:

JsonResponse

integreat_cms.api.v3.chat.user_chat.response_or_error(result: dict) JsonResponse[source]

Helper function to extract the status code from the API response

Parameters:

result (dict) – an API call’s result

Returns:

json response with appropriate status code

Return type:

JsonResponse

integreat_cms.api.v3.chat.user_chat.send_message(request: HttpRequest, language_slug: str, client: ZammadChatAPI, user_chat: UserChat | None, device_id: str) JsonResponse[source]

Function to send a new message in the current chat of a specified device_id, or to create one if no chat exists or the user requested a new one.

Parameters:
  • request (HttpRequest) – Django request

  • language_slug (str) – language slug

  • client (ZammadChatAPI) – the Zammad API client to use

  • user_chat (UserChat | None) – the device_id’s current chat (if one exists)

  • device_id (str) – ID of the user requesting the messages

Returns:

JSON object according to APIv3 offers endpoint definition

Return type:

JsonResponse

integreat_cms.api.v3.chat.user_chat.zammad_webhook(request: HttpRequest) JsonResponse[source]

Receive webhooks from Zammad to update the latest article translation

Parameters:

request (HttpRequest)

Return type:

JsonResponse

Zammad API

class integreat_cms.api.v3.chat.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, auto: bool = False) dict[source]

Post a new message to the given ticket

Parameters:
Return type:

dict