@prass/botpress-native
Version:
A simple and powerful SDK for integrating Botpress Chat API with React Native,
45 lines (42 loc) • 1.81 kB
JavaScript
import { prepareHeaders } from '../../utils/prepareHeaders.js';
import { handleError } from '../../utils/errorHandler.js';
import { z } from 'zod';
const DeleteConversationParamsSchema = z.object({
id: z.string().nonempty("Conversation ID is required"),
});
/**
/**
* Handles the logic to delete a conversation by its ID.
*
* This function makes an API request to Botpress to delete the conversation identified by the provided ID.
* It ensures that the user has been created (i.e., the user key is available) before proceeding with the request.
*
* @param this - The Botpress class instance, providing access to class properties like `ChatApiBaseUrl` and `userKey`.
* @param {DeleteConversationParams} params - The parameters containing the conversation ID.
* @param {string} params.id - The unique identifier of the conversation to delete.
*
* @returns {Promise<void>} Resolves when the conversation has been successfully deleted.
* @throws {Exception} If the request fails, throws a custom exception containing the error details.
*/
async function handleDeleteConversation({ id }) {
if (!this.userKey)
throw new Error(this.errors.userNotCreated);
const { id: cid } = DeleteConversationParamsSchema.parse({ id });
try {
const url = this.ChatApiBaseUrl.getUrl(["conversations", cid]);
// Make the DELETE request to the Botpress API
const { data } = await this.axiosInstance.request({
url,
method: "DELETE",
headers: prepareHeaders({
"x-user-key": this.userKey,
}),
timeout: this.config.timeout,
});
}
catch (e) {
return handleError(e, "DeleteConversation");
}
}
export { handleDeleteConversation };
//# sourceMappingURL=deleteConversation.js.map