Current section
Files
Jump to
Current section
Files
lib/xdk/chat.ex
# AUTO-GENERATED FILE - DO NOT EDIT
# This file was automatically generated by the XDK build tool.
# Any manual changes will be overwritten on the next generation.
defmodule Xdk.Chat do
@moduledoc "Auto-generated client for chat operations"
@doc """
Get user public keys
GET /2/users/{id}/public_keys
Returns the public keys and Juicebox configuration for the specified user.
"""
@spec get_user_public_keys(Xdk.t(), id :: String.t(), opts :: keyword()) ::
{:ok, map()} | {:error, Xdk.Errors.error()}
def get_user_public_keys(client, id, opts \\ []) do
query =
[
{"public_key.fields", Keyword.get(opts, :public_key_fields)}
]
|> Xdk.Query.build()
Xdk.request(client, :get, "/2/users/{id}/public_keys",
params: %{
"id" => id
},
query: query
)
end
@doc """
Add public key
POST /2/users/{id}/public_keys
Registers a user's public key for X Chat encryption.
"""
@spec add_user_public_key(Xdk.t(), id :: String.t(), body :: map()) ::
{:ok, map()} | {:error, Xdk.Errors.error()}
def add_user_public_key(client, id, body) do
Xdk.request(client, :post, "/2/users/{id}/public_keys",
params: %{
"id" => id
},
json: body
)
end
@doc """
Send Chat Message
POST /2/chat/conversations/{conversation_id}/messages
Sends an encrypted message to a specific Chat conversation.
"""
@spec send_message(Xdk.t(), conversation_id :: String.t(), body :: map()) ::
{:ok, map()} | {:error, Xdk.Errors.error()}
def send_message(client, conversation_id, body) do
Xdk.request(client, :post, "/2/chat/conversations/{conversation_id}/messages",
params: %{
"conversation_id" => conversation_id
},
json: body
)
end
@doc """
Get Chat Conversation
GET /2/chat/conversations/{conversation_id}
Retrieves messages and key change events for a specific Chat conversation with pagination support.
"""
@spec get_conversation(Xdk.t(), conversation_id :: String.t(), opts :: keyword()) ::
{:ok, map()} | {:error, Xdk.Errors.error()}
def get_conversation(client, conversation_id, opts \\ []) do
query =
[
{"max_results", Keyword.get(opts, :max_results)},
{"pagination_token", Keyword.get(opts, :pagination_token)},
{"chat_message_event.fields", Keyword.get(opts, :chat_message_event_fields)}
]
|> Xdk.Query.build()
Xdk.request(client, :get, "/2/chat/conversations/{conversation_id}",
params: %{
"conversation_id" => conversation_id
},
query: query
)
end
@doc """
Get Chat Conversations
GET /2/chat/conversations
Retrieves a list of Chat conversations for the authenticated user's inbox.
"""
@spec get_conversations(Xdk.t(), opts :: keyword()) ::
{:ok, map()} | {:error, Xdk.Errors.error()}
def get_conversations(client, opts \\ []) do
query =
[
{"max_results", Keyword.get(opts, :max_results)},
{"pagination_token", Keyword.get(opts, :pagination_token)},
{"chat_conversation.fields", Keyword.get(opts, :chat_conversation_fields)},
{"expansions", Keyword.get(opts, :expansions)},
{"user.fields", Keyword.get(opts, :user_fields)}
]
|> Xdk.Query.build()
Xdk.request(client, :get, "/2/chat/conversations", query: query)
end
end