diff --git a/apps/wapi-ai-chatbot/src/index.ts b/apps/wapi-ai-chatbot/src/index.ts index 7759de9..24e83fb 100644 --- a/apps/wapi-ai-chatbot/src/index.ts +++ b/apps/wapi-ai-chatbot/src/index.ts @@ -15,11 +15,12 @@ async function init() { whatsappClient.on('TextMessage', async (event: TextMessageEvent) => { const aiResponse = await askAi(event.text.data.text, event.context.from) - await event.reply({ + const response = await event.reply({ message: new TextMessage({ text: aiResponse }) }) + console.log({ response }) }) whatsappClient.initiate() diff --git a/packages/wapi.js/src/client/schema.ts b/packages/wapi.js/src/client/schema.ts index 019763c..1d51928 100644 --- a/packages/wapi.js/src/client/schema.ts +++ b/packages/wapi.js/src/client/schema.ts @@ -63,8 +63,8 @@ export const CloudApiErrorResponseSchemaType = z.object({ error_data: z.object({ messaging_product: z.string(), details: z.string(), - }), - error_subcode: z.string().optional(), + }).nullish(), + error_subcode: z.number().optional(), fbtrace_id: z.string().optional(), }), }); diff --git a/packages/wapi.js/src/manager/message/index.ts b/packages/wapi.js/src/manager/message/index.ts index dc0161a..cf30588 100644 --- a/packages/wapi.js/src/manager/message/index.ts +++ b/packages/wapi.js/src/manager/message/index.ts @@ -18,8 +18,7 @@ import { type MessageResponseSchemaType } from "./schema"; */ export class MessageManager extends BaseManager - implements MessageManagerInterface -{ + implements MessageManagerInterface { client: Client; constructor(props: { client: Client }) { super(props.client); @@ -59,7 +58,7 @@ export class MessageManager return { status: "error", error: { - description: responseData.error.error_data.details, + description: responseData.error.error_data?.details || responseData.error.message, title: responseData.error.message, errorCode: responseData.error.code, errorSubCode: responseData.error.error_subcode, @@ -122,7 +121,7 @@ export class MessageManager return { status: "error", error: { - description: responseData.error.error_data.details, + description: responseData.error.error_data?.details || responseData.error.message, title: responseData.error.message, errorCode: responseData.error.code, errorSubCode: responseData.error.error_subcode, diff --git a/packages/wapi.js/src/manager/message/schema.ts b/packages/wapi.js/src/manager/message/schema.ts index cc9a8ce..d3cbf75 100644 --- a/packages/wapi.js/src/manager/message/schema.ts +++ b/packages/wapi.js/src/manager/message/schema.ts @@ -5,7 +5,7 @@ export const ErrorSchemaType = z.object({ title: z.string(), description: z.string(), errorCode: z.number(), - errorSubCode: z.string().optional(), + errorSubCode: z.number().optional(), }); export const MessageSuccessResponseSchemaType = z.object({