UNPKG

@prass/botpress-native

Version:

A simple and powerful SDK for integrating Botpress Chat API with React Native,

49 lines (46 loc) 2.02 kB
import { prepareHeaders } from '../../utils/prepareHeaders.js'; import { handleError } from '../../utils/errorHandler.js'; import { z } from 'zod'; const ListConversationsParamsSchema = z.object({ nextToken: z.string().optional(), }); /** * Handles the API request to retrieve a paginated list of conversations for the authenticated user. * * This function sends a GET request to the Botpress API and fetches the list of conversations. * If a `nextToken` is provided, it will be included in the request to support pagination. * * @param this - The `Botpress` class instance, providing access to class properties like `ChatApiBaseUrl` and `userKey`. * @param {ListConversationsParams} params - Parameters for listing conversations. * @param {string} [params.nextToken] - Optional token for pagination to fetch the next set of conversations. * * @returns {Promise<ListConversationsResponse>} The retrieved list of conversations along with pagination metadata. * @throws {Exception} If the request fails, throws a custom exception with relevant error details. */ async function handleListConversations({ nextToken }) { // Ensure user key is present if (!this.userKey) throw new Error(this.errors.userNotCreated); const { nextToken: nxt } = ListConversationsParamsSchema.parse({ nextToken }); try { // Construct the API URL, including pagination token if provided const url = this.ChatApiBaseUrl.getUrl(["conversations"], { nextToken: nxt, }); // Perform the GET request to fetch conversations const { data } = await this.axiosInstance.request({ url, method: "GET", headers: prepareHeaders({ "x-user-key": this.userKey, }), timeout: this.config.timeout, }); return data; } catch (err) { return handleError(err, "ListConversations"); } } export { handleListConversations }; //# sourceMappingURL=listConversations.js.map