whatsapp-api-js: Cannot make handle_post to return 200

I am running on Nextjs 14 App router, and I am able to setup the client and send messages (using provided vercel middleware), however when using the Whatsapp.handle_post(rawBody), i always get 500 returned.

export async function POST(request: NextRequest) {

    const Whatsapp = createWhatsappClient();
    const rawBody = await request.text();
    const res = await Whatsapp.handle_post(rawBody);
    
    return NextResponse.json({}, { status: res });

}

Remember I am able to use the client to send messages however this handle_post is not working for some reason. Plus: inspite the docs says need to disable bodyParser, its no longer needed on Next app router routes. Is there anything i am missing here?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (9 by maintainers)

Commits related to this issue

Most upvoted comments

For example, you could just store the message object (which includes the message type), the sender and the bot number, while on the other endpoint use the data directly rather than going through Whatsapp.post again.

@Secreto31126 , I understand what you mean but this mindset works on a stateful environment. On a stateful environment you have the worker to check new messages on the database then trigger the response. So this make sense. Queueing could be done internally.

But on a stateless environment, you have to somehow trigger the interaction response. There are not right or wrongs, but only challenges that these two different approaches brings us.

Maybe i should reevaluate if I shouldn’t be doing this on a stateful environment, which wasn’t my first option to worry on scalability issues and peaks.

Anyways, it would facilitate a lot if we could trigger the Whatsapp.on.message manually. So I can control the response from this.

Thanks for the release!