From ea0aaf73d4a33e0b1f7f5f38ae99123524ac9d1f Mon Sep 17 00:00:00 2001 From: sarthakjdev Date: Sat, 20 Jul 2024 10:57:40 +0530 Subject: [PATCH] fix: app crash on api key error Signed-off-by: sarthakjdev --- apps/wapi-ai-chatbot/src/index.ts | 3 ++- packages/wapi.js/src/client/schema.ts | 4 ++-- packages/wapi.js/src/manager/message/index.ts | 7 +++---- packages/wapi.js/src/manager/message/schema.ts | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) 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({