How to send transactional Viber Business Message
Steps to Send a Transactional Message to Viber Users via Phone Number
Prerequisites:
Viber Business API Access: You need to register with Viber Business and obtain an API key/token.
Recipient's Phone Number: You need the recipient's Viber-registered phone number in international format (e.g.,
+65xxxxxxxx
).Node.js: Ensure that you have Node.js installed and set up for making API calls.
Full Example Code to Send a Transactional Message
Explanation of the Code:
API Token:
Replace
YOUR_VIBER_BUSINESS_API_TOKEN
with your Viber Business API token. This token is provided after registering for Viber's Business Messaging service.
Phone Number:
Replace
+65xxxxxxxx
with the actual recipient’s Viber-registered phone number in international format (e.g.,+65xxxxxxx
for Singapore). The phone number must be registered with Viber.
Message Text:
Modify the content of the
transactionalMessageText
variable to whatever transactional message you want to send (e.g., order confirmation, delivery update, etc.).
API Request:
The code uses
axios
to send aPOST
request to thehttps://chatapi.viber.com/pa/send_message
endpoint, with the message payload that includes the recipient’s phone number, message type, and content.
Sender Information:
The
sender
object contains the business name and an optional avatar URL. These will be shown to the recipient when they receive the message.
Optional Tracking Data:
The
tracking_data
field is optional and can be used to pass any data that you want to track for the message, such as an internal identifier.
Testing the Application:
Ensure you have Node.js installed.
Install the
axios
package if you haven't already:
Run the script using Node.js:
Result:
If everything is set up correctly, the transactional message (e.g., order confirmation) will be delivered to the specified Viber user, and you will see a success message logged in the console.
Important Considerations:
Business Messaging API Access:
You need to work with a Viber Business partner or apply through Viber Business Messaging Partner to get API access.
Depending on your business case, you may need to comply with specific Viber guidelines and have approval for sending transactional messages.
Rate Limits:
Ensure you are aware of the rate limits imposed by Viber to avoid hitting limits or being blocked from sending messages.
Pricing:
Viber charges for sending messages, especially promotional ones. The cost may vary depending on the country and the message type (e.g., transactional vs. promotional).
By following this code, you'll be able to send transactional Viber messages directly to customers using their phone numbers.
Last updated