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.

If a chat exists but has been inactive long enough that its Zammad ticket is assumed to be gone (Zammad’s ticket retention is shorter than ours), a new chat is started for the same device id on POST requests.

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.

Zammad ticket IDs are only unique per Zammad server. Therefore the chat is looked up by the ticket ID in all regions that use the same Zammad URL as the region of the webhook token. This allows multiple regions to share a Zammad server, while regions with their own Zammad server stay separated.

Parameters:

request (HttpRequest)

Return type:

JsonResponse