Chat

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