@prass/botpress-native
Version:
A simple and powerful SDK for integrating Botpress Chat API with React Native,
38 lines (35 loc) • 1.2 kB
JavaScript
import { prepareHeaders } from '../../utils/prepareHeaders.js';
import { handleError } from '../../utils/errorHandler.js';
import { z } from 'zod';
const GetEventParamsSchema = z.object({
id: z.string().nonempty("Event ID is required"),
});
/**
* Internal handler for retrieving a specific event’s details.
* @param this - Botpress instance context
* @param params - Parameters containing the event ID
* @returns Promise resolving to the event’s details
* @throws Error if user key is missing or API call fails
*/
async function handleGetEvent({ id }) {
if (!this.userKey)
throw new Error(this.errors.userNotCreated);
const { id: eid } = GetEventParamsSchema.parse({ id });
try {
const url = this.ChatApiBaseUrl.getUrl(["events", eid]);
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, "GetEvent");
}
}
export { handleGetEvent };
//# sourceMappingURL=getEvent.js.map