UNPKG

@prass/botpress-native

Version:

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

38 lines (35 loc) 1.22 kB
import { prepareHeaders } from '../../utils/prepareHeaders.js'; import { handleError } from '../../utils/errorHandler.js'; import { z } from 'zod'; const GetMessageParamsSchema = z.object({ id: z.string().nonempty("Message ID is required"), }); /** * Internal handler for retrieving a specific message's details. * @param this - Botpress instance context * @param params - Parameters containing the message id * @returns Promise resolving to the message details * @throws Error if prerequisites are missing or API call fails */ async function handleGetMessage({ id }) { if (!this.userKey) throw new Error(this.errors.userNotCreated); const { id: mid } = GetMessageParamsSchema.parse({ id }); try { const url = this.ChatApiBaseUrl.getUrl(["messages", mid]); 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, "GetMessage"); } } export { handleGetMessage }; //# sourceMappingURL=getMessage.js.map