@prass/botpress-native
Version:
A simple and powerful SDK for integrating Botpress Chat API with React Native,
44 lines (41 loc) • 1.5 kB
JavaScript
import { prepareHeaders } from '../../utils/prepareHeaders.js';
import { handleError } from '../../utils/errorHandler.js';
import { z } from 'zod';
const GetParticipantParamsSchema = z.object({
conversationId: z.string().nonempty("Conversation ID is required"),
userId: z.string().nonempty("User ID is required"),
});
/**
* Internal handler for retrieving a specific participant's details from a conversation.
* @param this - Botpress instance context
* @param params - Parameters containing conversationId and userId
* @returns Promise resolving to the participant's details
* @throws Error if prerequisites are missing or API call fails
*/
async function handleGetParticipant({ conversationId, userId }) {
if (!this.userKey)
throw new Error(this.errors.userNotCreated);
const { conversationId: cid, userId: uid } = GetParticipantParamsSchema.parse({ conversationId, userId });
try {
const url = this.ChatApiBaseUrl.getUrl([
"conversations",
cid,
"participants",
uid,
]);
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, "GetParticipant");
}
}
export { handleGetParticipant };
//# sourceMappingURL=getParticipant.js.map