AI & Automation
AI for every conversation, campaign, and customer
EXPERT INSIGHTS
Dec-03-2020
Khoros Staff
Editor's note: This blog post was originally written on the Flow.ai website. Flow.ai was acquired by Khoros in 2021 to advance Khoros' conversational AI and machine learning (ML) capabilities and data science expertise. This blog post has been adapted to be on the Khoros blog.
Transfer and deflect phone calls to WhatsApp using Twilio
Deflecting calls to messaging can decrease the load on your customer service department and at the same time improve your customer satisfaction rates.
In this tutorial we’ll walk you through setting up phone deflection to WhatsApp using Twilio and Flow.ai.
In this use case we will configure a phone number that has an IVR. The IVR will offer a customer the choice to use WhatsApp instead of waiting on the phone for a customer service agent.
So the customer flow looks like:
To make this work you’ll need a couple of things:
Note: This article demonstrates WhatsApp and does not explain how to enroll a WhatsApp Business Account. Also note that this same use case would work with for example SMS, MessageMedia or a customer service solution like Khoros.
It all starts with a phone number: You’ll need to buy one or add an existing number to Twilio. This can be, but does not have to be the same phone number you use for WhatsApp.
For using an existing phone number that is not connected to Twilio you’ll have 3 options:
Note: Need help with this? No worries, please contact Twilio support or Flow.ai support.
Twilio offers unused phone numbers for different countries. Most of them you can easily buy within the Twilio console. Make sure the phone number you purchase supports voice! If you have any questions regarding the availability in your region, please contact Twilio support.
DEFLECT_CALL
async payload => {
<i>// CHANGE THE ID WITH YOUR OWN TEMPLATE ID</i>
return await toolbelt.whatsapp.send360Template({
id: 'YOUR UNIQUE ID'
})
}
When we are able to receive inbound calls with Twilio, you can configure the Twilio Voice API. Flow.ai provides a built-in Twilio Voice integration that allows you to create an intelligent IVR system, but you can also create the setup using the Twilio Voice API or Twilio Studio.
Setting up the IVR using Twilio studio requires a Flow.ai REST API integration. We basically configure the IVR within Twilio and when a user presses one we execute a piece of code that will send the WhatsApp templated message.
const request = require("then-request"); <i>//6.0.2</i>
<i>// READ MORE INSTRUCTIONS HERE:</i>
<i>// https://flow.ai/docs/api-docs/#rest-api-broadcast</i>
const apiEndpoint = 'https://api.flow.ai/rest/v1/broadcast/instant';
<i>// REPLACE THE FOLLOWING CONFIGURATION</i>
const channelName = 'whatsapp360';
const eventName = 'DEFLECT_CALL';
const channelExternalId = '+1234567890'; <i>// Your WhatsApp phone number</i>
const apiToken = '' <i>// The API token from the Flow.ai REST API</i>
exports.handler = function(context, event, callback) {
var phoneNumber = event.phonenumber.trim().replace('+','');
var body = {
audience: [{
name: 'Anonymous',
phoneNumber,
profile: {
}
}],
channel: {
channelName,
externalId: channelExternalId
},
payload: {
type: 'event',
eventName: eventName
}
};
var options = {
headers:{
'Content-Type': 'application/json',
'Authorization': apiToken
},
body: JSON.stringify(body)
};
request('POST', apiEndpoint, options).done(function(res) {
callback(null, "OK");
});
};
async payload => {
try {
<i>// READ MORE INSTRUCTIONS HERE:</i>
<i>// https://flow.ai/docs/api-docs/#rest-api-broadcast</i>
const apiEndpoint = 'https://api.flow.ai/rest/v1/broadcast/instant';
<i>// REPLACE THE FOLLOWING CONFIGURATION</i>
const channelName = 'whatsapp360';
const eventName = 'DEFLECT_CALL';
const channelExternalId = '+1234567890'; <i>// Your WhatsApp phone number</i>
const apiToken = '' <i>// The API token from the Flow.ai REST API</i>
await request({
method: 'POST',
url: apiEndpoint,
headers:{
'Content-Type': 'application/json',
'Authorization': apiToken
},
body: {
audience: [{
name: 'Anonymous',
phoneNumber,
profile: {
}
}],
channel: {
channelName,
externalId: channelExternalId
},
payload: {
type: 'event',
eventName: eventName
}
}
})
} catch(err) {
console.error('An error making a request', err)
}
}