I am developing a chat application that interacts with users via the WhatsApp Cloud API. The idea is to show the "typing" status when the user is writing, but I can't find a way to implement this.
I am using Node.js for the application and integrating with the API, but I don't see any clear example of how to display the "typing" status. So far, I have been able to send messages successfully, but the typing indicator part is still a challenge.
Here is a basic example of how I am setting up the API with Node.js:
const axios = require('axios');
const sendMessage = async (recipient, message) => {
const url = 'https://graph.facebook.com/v16.0/{your_phone_number_id}/messages';
const data = {
messaging_product: 'whatsapp',
to: recipient,
text: { body: message }
};
const headers = {
'Authorization': 'Bearer {your_access_token}',
'Content-Type': 'application/json'
};
try {
const response = await axios.post(url, data, { headers });
console.log('Message sent successfully', response.data);
} catch (error) {
console.error('Error sending message', error);
}
};
sendMessage('recipient_number', 'Hello, this is a test message!');
I would like to know if anyone has experience sending the "typing" status (typing indicator) using the WhatsApp Cloud API with Node.js. How can I do this?
Some ideas I’ve considered:
Has anyone implemented this or found a better approach? Any advice or solutions would be greatly appreciated!
Thank you in advance for any help!
Facebook Official API:
https://developers.facebook.com/docs/whatsapp/cloud-api/typing-indicators
You can use this API with message.id
to simulate typing.