Utils

Utils for the public chat

Chat Bot

Celery tasks for processing Chat Bot messages

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

Process automatic or counselor answers

Parameters:
  • message_text (str) – Message text that should be translated

  • source_language (str) – source language of the message to be translated

  • target_language (str) – target language of the message to be translated

Returns:

dict containing the translated message

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, messages: list[dict]) tuple[dict, dict][source]

Process the message from an Integreat App user

Parameters:
  • zammad_chat_language_slug (str) – Language selected in Integreat App

  • region_slug (str) – region used in webhook

  • region_default_language_slug (str) – default language of region / counselors

  • messages (list[dict]) – list of all messages (can contain newer messages than message_text)

Returns:

a tuple of the answer and translation dict

Return type:

tuple[dict, dict]

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

Get automatic answer to question asynchronously

Parameters:
  • messages (list) – a list of chat messages

  • region_slug (str) – the slug of the region to which the chat belongs

  • language_slug (str) – the slug of the language in which the chat was started

  • session (ClientSession)

Returns:

dict containing the answer

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) – Message text that should be translated

  • source_language – source language of the message to be translated

  • target_language – target language of the message to be translated

  • session (ClientSession) – the aiohttp session used for sending the request

  • source_language_slug (str)

  • target_language_slug (str)

Returns:

dict containing the translated message

Return type:

dict