Skip to content

Commit

Permalink
fix: app crash on api key error
Browse files Browse the repository at this point in the history
Signed-off-by: sarthakjdev <jsarthak448@gmail.com>
  • Loading branch information
sarthakjdev committed Jul 20, 2024
1 parent 087c668 commit ea0aaf7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
3 changes: 2 additions & 1 deletion apps/wapi-ai-chatbot/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ async function init() {

whatsappClient.on('TextMessage', async (event: TextMessageEvent) => {

Check warning on line 16 in apps/wapi-ai-chatbot/src/index.ts

View workflow job for this annotation

GitHub Actions / build-and-lint

Promise returned in function argument where a void return was expected
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()
Expand Down
4 changes: 2 additions & 2 deletions packages/wapi.js/src/client/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}),
});
Expand Down
7 changes: 3 additions & 4 deletions packages/wapi.js/src/manager/message/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/wapi.js/src/manager/message/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit ea0aaf7

Please sign in to comment.