Spaces:
Runtime error
Runtime error
File size: 2,086 Bytes
46252cd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | /**
* Chats resource — chat-list operations (read/unread/delete/typing state).
*
* NOTE: these endpoints live under the session controller
* (`/api/sessions/:id/chats/*`), but are surfaced here as a dedicated resource
* for clarity.
*
* @packageDocumentation
*/
import { encodeSegment } from '../http.js';
import type { OpenWAClient } from '../client.js';
import type { ChatSummary, DeleteChatRequest, MarkChatRequest, SendChatStateRequest, SuccessResult } from '../types.js';
export interface ListChatsQuery {
limit?: number;
offset?: number;
}
export class ChatsResource {
constructor(private readonly client: OpenWAClient) {}
/** List active chats, most recent first. */
list(sessionId: string, query?: ListChatsQuery): Promise<ChatSummary[]> {
return this.client.request<ChatSummary[]>({
method: 'GET',
path: `/api/sessions/${encodeSegment(sessionId)}/chats`,
query,
});
}
/** Mark a chat as read/seen. */
markRead(sessionId: string, body: MarkChatRequest): Promise<SuccessResult> {
return this.client.request<SuccessResult>({
method: 'POST',
path: `/api/sessions/${encodeSegment(sessionId)}/chats/read`,
body,
});
}
/** Mark a chat as unread. */
markUnread(sessionId: string, body: MarkChatRequest): Promise<SuccessResult> {
return this.client.request<SuccessResult>({
method: 'POST',
path: `/api/sessions/${encodeSegment(sessionId)}/chats/unread`,
body,
});
}
/** Delete a chat from the chat list. */
delete(sessionId: string, body: DeleteChatRequest): Promise<SuccessResult> {
return this.client.request<SuccessResult>({
method: 'POST',
path: `/api/sessions/${encodeSegment(sessionId)}/chats/delete`,
body,
});
}
/** Send a chat presence state (typing/recording/paused). */
sendState(sessionId: string, body: SendChatStateRequest): Promise<SuccessResult> {
return this.client.request<SuccessResult>({
method: 'POST',
path: `/api/sessions/${encodeSegment(sessionId)}/chats/typing`,
body,
});
}
}
|