Building your application
Sending Messages
Learn how to send messages using the Wapi.js SDK
Wapi.js SDK provides a simple and easy to use classes architecture to send messages. You can send message of following types using the Wapi.js SDK:
Send a message
You can send a message to a user using the send
method available on the client class message manager. Here is an example of how you can send a message:
// assuming you already have initiated the client,
const textMessage = new TextMessage({
text: 'Hello, how are you?'
})
// send a message
const response = await whatsappClient.message.send({
to: '919876543210',
message: textMessagew
})
The .send() method is a asynchronous method and returns a promise of response which can either be a success response or a error response. It is suggested to acknowledge the response, as calling the .send() method does not gurantees the message has been sent, there may be some API error which may lead to message not being sent, the SDK does not retries the message, it is the application login responsibility to add retry mechanism. However, if you think this should be added to the SDK itlsef, you are invited to open a issue on the github repository of the SDK.
Was this page helpful?