Chat

User Chat

This module provides the API endpoints for the public chat API

integreat_cms.api.v3.chat.user_chat.chat(request: HttpRequest, region_slug: str, language_slug: str, device_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

  • language_slug (str) – language slug

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

  • attachment_id – ID of the requested attachment (optional)

  • region_slug (str)

Returns:

JSON object according to APIv3 chat endpoint definition

Return type:

JsonResponse | HttpResponse

integreat_cms.api.v3.chat.user_chat.get_or_create_user_chat(request: HttpRequest, device_id: str, language: Language) UserChat | None[source]

Get existing UserChat or create a new one if the HTTP method is POST.

Parameters:
  • request (HttpRequest) – Django request

  • device_id (str) – UUID of the app device

  • language_slug – slug of language that is used by the app

  • language (Language)

Return type:

UserChat | None

integreat_cms.api.v3.chat.user_chat.is_app_user_message(webhook_message: dict) bool[source]

Check if message originates from app user

param webhook_message: Zammad webhook ticket dict

Parameters:

webhook_message (dict)

Return type:

bool

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

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

  • region_slug (str)

Returns:

JSON object according to APIv3 chat endpoint definition

Return type:

JsonResponse

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

Create or get UserChat object and return list of messages. Save new message or updated Zammad ticket attributes.

Parameters:
  • request (HttpRequest) – Django request

  • device_id (str) – UUID of the app device

  • language_slug (str) – slug of language that is used by the app

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.

Optional feature: if a Zammad has an object attribute “device_id” for tickets, we can use this to directly fetch the corresponding chat from our database. This allows multiple regions to use the same Zammad server. As not all Zammad servers have this configured, we still need to support the old method were we fetch the UserChat object identified by the region token and Zammad ticket id.

Parameters:

request (HttpRequest)

Return type:

JsonResponse