How to Configure Sending Viber/SMS via Infobip
Infobip allows sending text messages through Viber and SMS. This is useful for automating communications with clients, for example, for order confirmations, promotional notifications, or other important information.
📖 Documentation: For more details about Infobip API, read on the official website.
Prerequisites
- Active Infobip account
- API key from Infobip
- Registered Sender Name for Viber (if using Viber)
Obtaining API Key
- Sign in to Infobip management panel
- Go to the API Keys section
- Create a new API key
- Copy the received key
Configuring Sender Name for Viber
- In the Infobip panel, go to the Viber Sender Names section
- Register a unique sender name (usually your company name)
- Wait for approval (may take some time)
Creating Action for Infobip
To send messages through Infobip, you need to create a custom action through Action Jail.
Action Code Example
const axios = require('axios');
// Constants for API configuration
const API_KEY = 'YOUR_API_KEY'; // Your Infobip API key
const SENDER_NAME = 'DemoCompany'; // Sender name for Viber
const BASE_URL = 'https://api.infobip.com'; // Base URL for Infobip
const API_PATH = '/viber/2/messages'; // Path for sending messages
const action_infobip_send_message = async function() {
const j = this.getCurrentStateJSON();
if (!j || typeof j !== 'object') {
console.error("Error: JSON data is invalid or not an object.");
return "error";
}
const message = (j.message || '').trim();
const to = (j.to || '').trim();
if (!message || !to) {
console.error("Error: 'message' or 'to' is missing in the JSON data.");
return "error";
}
const options = {
method: 'POST',
url: `${BASE_URL}${API_PATH}`,
headers: {
'Authorization': `App ${API_KEY}`,
'Content-Type': 'application/json',
'Accept': 'application/json'
},
data: {
messages: [
{
sender: SENDER_NAME,
destinations: [{ to }],
content: {
text: message,
type: "TEXT"
}
}
]
}
};
try {
const response = await axios(options);
console.log("Response from Infobip:", response.data);
return "success";
} catch (error) {
console.error("Error sending message:", error.response?.data || error.message);
return "error";
}
};
module.exports = action_infobip_send_message;
Usage in Scenario
Data Preparation
Before calling the action, set variables in state:
{
"message": "Your order #123 has been shipped!",
"to": "380971234567"
}
Parameters:
message— message text to sendto— recipient phone number in international format (without+sign)
Result Handling
Success (success):
- If the message is successfully sent, the action returns
"success" - In the scenario, you can add subsequent actions (logging, status update, etc.)
Error (error):
- If an error occurred, the action returns
"error" - In the scenario, you should provide error handling (notify administrator, retry, etc.)
Sending SMS via Infobip
For sending SMS, a different endpoint is used:
const smsOptions = {
method: 'POST',
url: `${BASE_URL}/sms/2/text/single`,
headers: {
'Authorization': `App ${API_KEY}`,
'Content-Type': 'application/json'
},
data: {
from: SENDER_NAME,
to: to,
text: message
}
};
Limitations
- Viber messages have text length limitations
- Phone number must be in international format
- Sender Name must be registered in Infobip
- Rate limiting may apply depending on Infobip tariff plan
Related Articles
- Infobip API Documentation — official Infobip documentation
- Create custom action — creating custom actions through ActionJail