UNPKG

@prass/botpress-native

Version:

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

44 lines (41 loc) 1.71 kB
import { prepareHeaders } from '../../utils/prepareHeaders.js'; import { handleError } from '../../utils/errorHandler.js'; import { z } from 'zod'; const GetConversationParamsSchema = z.object({ id: z.string().nonempty("Conversation ID is required"), }); /** * Handles the logic to retrieve a conversation by its ID. * * This function makes an API call to fetch the conversation details from the Botpress system * using the provided conversation ID and the `x-user-key` header for authentication. * * @param this - The Botpress class instance, providing access to class properties like `ChatApiBaseUrl` and `userKey`. * @param {GetConversationParams} params - The parameters containing the conversation ID. * @param {string} params.id - The unique identifier of the conversation to retrieve. * * @returns {Promise<GetConversationResponse>} The details of the retrieved conversation. * @throws {Exception} If the request fails, throws a custom exception containing the error details. */ async function handleGetConversation({ id }) { if (!this.userKey) throw new Error(this.errors.userNotCreated); const { id: cid } = GetConversationParamsSchema.parse({ id }); try { const url = this.ChatApiBaseUrl.getUrl(["conversations", cid]); const { data } = await this.axiosInstance.request({ url, method: "GET", headers: prepareHeaders({ "x-user-key": this.userKey, }), timeout: this.config.timeout, }); return data; } catch (e) { return handleError(e, "GetConversation"); } } export { handleGetConversation }; //# sourceMappingURL=getConversation.js.map