Production-Ready WhatsApp Integration with Node.js, Express, and Sinch - code-examples -

Frequently Asked Questions

Integrate WhatsApp by using Express.js and the Sinch Conversation API. This allows sending and receiving messages and provides a REST endpoint to trigger outgoing messages from your backend systems via Sinch.
The Sinch Conversation API is a unified platform to manage conversations across multiple channels, including WhatsApp. It simplifies interaction with the WhatsApp Business Platform and streamlines communication.
Express.js is used as a framework for building the API and web application in a Node.js environment due to its minimal and flexible nature, making integration with Sinch smoother.
Pre-approved templates are required when initiating conversations with users or messaging outside the 24-hour customer service window. This ensures compliance with WhatsApp Business policies.
Yes, Sinch provides delivery receipts through webhooks. The statuses include, DELIVERED, FAILED, READ, and PENDING, allowing you to track message delivery and handle failures. These statuses can be viewed in the webhook payload from Sinch
Use the 'x-sinch-signature' and 'x-sinch-timestamp' headers along with your Webhook Secret to calculate the expected signature. Compare this with the received signature using a constant-time comparison method like `crypto.timingSafeEqual` for security.
The 24-hour window allows businesses to send free-form messages after a user initiates contact. Outside this window, you must use pre-approved message templates or risk non-delivery.
Set up a webhook endpoint to receive incoming messages from Sinch. The webhook will provide details like contact ID, message content, and timestamp which will be used to trigger actions or replies based on the 24-hour window.
The `sendMessage` function, using helper functions like `sendTextMessage` or `sendTemplateMessage`, handles sending messages. It takes the recipient's phone number and message payload as arguments and makes a POST request to the Sinch API.
The `app_id` is your provisioned WhatsApp Sender ID from Sinch. It identifies your WhatsApp Business number when sending messages through the Sinch API.
You'll need Node.js/npm, a Sinch account with postpay billing, Conversation API access, a Sinch project and app, access keys, a WhatsApp Sender ID, and optionally ngrok for local testing.
The `contact_id` typically represents the sender's WhatsApp phone number. It is used to identify the user who sent the inbound message and is crucial for managing the 24-hour customer service window.
Webhooks require verification of the signature provided by Sinch in request headers. Verify this against your Webhook Secret by calculating the hash locally to ensure the origin of the messages received.
ngrok helps create a secure tunnel between your local development server and the internet, exposing it to receive webhooks for testing purposes before actual deployment.