I see that Dialogflow has fulfiment and webhook installations to allow for further dynamic and logistic control over the bot responses. I'm trying to peg a database on top of the webhook, but the channel I'm using is Twilio Text Messaging, and I'm having a little trouble with connecting the two. When I do activate fulfillment, the twilio bot does not read it. Any way to solve this?
I already created a few webhooks using Flask, and integrated it through fulfillment briefly using ngrok, but the bot is responding via the text responses I set for it. Its for google assistance, and facebook messenger, but not with the Twilio integration.
I also tried using inlineJS to see if that held any difference to specifically define Twilio as the messaging outlet to use, however it did not peak success.
const functions = require('firebase-functions');
const {dialogflow} = require('actions-on-google');
const GOODLOCATION = 'location.good'
const NEARLOCATION = 'location.near'
const CHEAPLOCATION = 'location.cheap'
const WELCOME_INTENT = 'Default Welcome Intent'
const FALLBACK_INTENT = 'Default Fallback Intent'
const CRAVINGCULTUREINTENT = 'CravingCulture'
const CRAVINGITEM = 'CravingItem'
const app = dialogflow()
/*Supported Platforms*/
const PLATFORMS = {
UNSPECIFIED: 'PLATFORM_UNSPECIFIED',
FACEBOOK: 'FACEBOOK',
SLACK: 'SLACK',
TELEGRAM: 'TELEGRAM',
KIK: 'KIK',
SKYPE: 'SKYPE',
LINE: 'LINE',
VIBER: 'VIBER',
ACTIONS_ON_GOOGLE: 'ACTIONS_ON_GOOGLE',
TWILIO: 'TWILIO'
};
// Platforms that support Rich messaging
const SUPPORTED_RICH_MESSAGE_PLATFORMS = [
PLATFORMS.FACEBOOK,
PLATFORMS.SLACK,
PLATFORMS.TELEGRAM,
PLATFORMS.KIK,
PLATFORMS.SKYPE,
PLATFORMS.LINE,
PLATFORMS.VIBER,
PLATFORMS.ACTIONS_ON_GOOGLE,
PLATFROM.TWILIO
];
app.intent(WELCOME_INTENT, (conv)=> {
if(agent.requestSource === agent.TWILIO){
conv.ask('This is working, Congratulations!')
}
else{
conv.ask("Could not be served")
}
});
app.intent(FALLBACK_INTENT, (conv)=> {
conv.ask("I am unaware of that phrase, could you repeat that?")
});
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app)
I want the output to be any thing that the user insert through the twilio that this bot will respond accordingly to what is passed in.
A little late, perhaps - hopefully this issue isn't still blocking/plaguing you.
I'm thinking you were intending:
if(agent.requestSource === PLATFORMS.TWILIO){
not:
if(agent.requestSource === agent.TWILIO){
However, also the value of agent.requestSource is actually lowercase "twilio".
Related
How can I find available Twilio numbers based on the US state?
When we are in the Twilio console, there is a criteria where we can add a number and select "match to = first part of number", which I guess works with regex conditions / patterns.
I am aware we can extract the state prefixes and to use the prefix for the state which we want to search and use it as some pattern.
In addition, I need to check for the voice capabilities.
I am referring to this API: https://www.twilio.com/docs/phone-numbers/api but I have a hard tome to understand the proper fields that needs to be used. Also, I found many StackOverflow questons pointing to a links to Twilio doc, that are no longer valid.
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);
const statePrefix = '823';
const voiceCapabilty = true;
client.availablePhoneNumbers('US')
.then(/* do something */);
I am making a simple to the verify api from a Twilio Function triggered in a studio flow.
The error I am recieving is "verifications resource not found".
I assumed it was an authentication issue, but I have the correct SIDS and have checked that a number of times.
Not sure what I am missing.
const accountSid = process.env.ACCOUNT_SID;
const authToken = process.env.AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);
const functions = Runtime.getFunctions();
const formatPhone = require(functions['formatters/formatPhone'].path);
exports.handler = function (context, event, callback) {
const verifyPhone = formatPhone.toSearch(event.verifyPhone);
const verifyType = event.verifyType;
client.verify
.services('<Verify SID>')
.verifications.create({ to: '+1' + verifyPhone, channel: verifyType })
.then((verification) => {
console.log(verification.sid);
callback(null, 'done');
})
.catch((err) => callback(err, null));
};
I can run this code from my machine and hit it from studio using NGROK and an http widget instead of a function.
SAME CODE.
I feel that it may be the work of Legacy Systems!
So as strange as it sounds it ended up being a library versioning issue.
npm i 'twilio'
and then pushed again to the server
twilio serverless:deploy --override-existing-project
I also realize that I didn't list the error originally. I have edited it to make more sense as to the problem I was having.
I´m developing a chatbot using Twilio Studio and at some point, I need to collect the data inputs from the clients that talk to my bot, and then post it into an airtable base.
I don´t have much coding skills, so my guide was this Dabble Lab tutorial: https://www.youtube.com/watch?v=xjt9YhNFrno
However, the Twilio function proposed in the video isn´t working. Here is the code:
exports.handler = function(context, event, callback) {
let member = {
name : event.name,
email : event.email,
date : Date.now()
};
var Airtable = require('airtable');
var base = new Airtable({apiKey: context.AIRTABLE_API_KEY}).base('appISrkMnNdL65Lzj');
base('Members').create(member, function(err, record) {
if (err) { console.error(err); return; }
console.log(record.getId());
callback(null, member);
});
};
When I try to make a POST request via Postman, this is what happens in my Twilio Console
And this is the capture of Postman response
As I´m using Twilio Studio Flow for developing the chatbot, I guess I could use the HTTP Request Widget but I really don´t know how to configure it.
The columns in my base are: Id - name - email - date
Any idea how can I solve this?
There are a couple of good Twilio/Airtable blogs recently posted. It looks like you are getting an error back but your error condition isn't calling the callback and thus the timeout.
Could it be some issue is with the Airtable field types not liking the type of the data you are posting, in particular the date.
Maybe you need something like this instead?
const today = new Date();
const date = `${(today.getMonth()+1)}/${today.getDate()}/${today.getFullYear()}`;
Writing to Airtable from your Twilio app
Using Airtable as a database for your Twilio app
I'm trying to use this dialpad plugin for Twilio Flex to make phone calls. I'm newbie on this so maybe I'm forgetting something to do in the process. I will detail the steps I made:
git clone https://github.com/lehel-twilio/plugin-dialpad.git
npm install
cp public/appConfig.example.js public/appConfig.js
appConfig.js file code:
// your account sid
var accountSid = 'ACXXxxxxXXXXxxxxxxXXXXXXxxxx35'; //my accountSid
// set to /plugins.json for local dev
// set to /plugins.local.build.json for testing your build
// set to "" for the default live plugin loader
var pluginServiceUrl = '/plugins.json';
var appConfig = {
pluginService: {
enabled: true,
url: pluginServiceUrl,
},
sso: {
accountSid: accountSid
},
ytica: false,
logLevel: 'debug',
showSupervisorDesktopView: true,
};
I deploy functions according to github docs: Hold Call (/hold-call), Create New Task (/create-new-task), Cleanup Rejected Task (/cleanup-rejected-task), Flex Dialpad Add Conference Participant (/add-conference-participant)
According to plugin-dialpad documentation, all these functions have the option Check for valid Twilio signature unchecked:
Configuring Functions :
Task channel 'custom1' is created:
I added my phone number as an attribute value to every Worker:
And finally, I added the filter:
At the beginning it displayed this error when I tried to make a phone call:
I could fix it applying CORS headers in Create New Task function which It's showing the error, I changed this line: "Access-Control-Allow-Origin":"https://flex.twilio.com":
But now it shows me an error in dialpad-plugin.js and I still can't make phone calls:
Flex version 1.11.1 (same happens with 1.10.0)
plugin-dialpad version 4.0
How can I fix it? I'd like your help.
Are you sure you created the function as details in the github repo? For example, the create-new-task function looks very different then what you posted.
https://github.com/lehel-twilio/plugin-dialpad/blob/master/src/functions/create-new-task.js
All the functions are located here:
https://github.com/lehel-twilio/plugin-dialpad/tree/master/src/functions
Ok, finally I could fix my problem.
First, I had to create Twilio functions according to github: https://github.com/lehel-twilio/plugin-dialpad/tree/master/src/functions
After that, when I make a phone call it's showing me an error message on Twilio Debugger: Got HTTP 500 response from https://*****.twil.io/call-outbound-join Error: 'From' phone number not verified.
My Twilio Phone Number is from another country, so I fixed adding this additional code on "Create New Task" function which allows so add "+" sign automatically:
const numbx = "+" + event.From; const wnumbx = numbx.replace(/\s/g,'');
console.log(wnumbx); const numbt = "+" + event.To; const wnumbt =
numbt.replace(/\s/g,''); console.log(wnumbt);
client.taskrouter.workspaces(workspace) .tasks .create( { attributes: JSON.stringify( { to: wnumbt, direction: 'outbound', name: 'MY COMPANY', from: wnumbx,...
This is not necessary on Twilio phone numbers of US.
My company uses Twilio Flex as our phone system and I was recently tasked with setting up a feature that will let us edit a TwiML voice message that plays before our normal voice message. This TwiML message will be changed through a Twilio bot that I've published in our Microsoft Teams.
The reason for this is so that our support desk can add a short message in the lines of "We're currently experiencing issues with X" before our normal "Welcome to [Company] support" message.
If TwiML's can be edited using HTTP POST/PUT or Twilio's API this should be a trivial matter, but so far I've not been able to figure out how.
I couldn't find any reference to this in the API doc, so I decided that HTTP POST would be the way to go. Using this as a start off point, I'm able to retrieve my TwiML using HTTP GET:
https://support.twilio.com/hc/en-us/articles/223132187--Not-Authorized-error-when-trying-to-view-TwiML-Bin-URL
const axios = require('axios');
const crypto = require('crypto');
const accountSidFlex = process.env.accountSidFlex;
const authTokenFlex = process.env.authTokenFlex;
var URL = 'https://handler.twilio.com/twiml/EHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' + '?AccountSid=' + accountSidFlex
var twilioSig = crypto.createHmac('sha1', authTokenFlex).update(new Buffer(URL, 'utf-8')).digest('Base64')
var config = {
headers:{
'X-TWILIO-SIGNATURE': twilioSig
}
}
axios.get(
URL,config
).catch(error => console.log(error))
.then(response => {
console.log(response.data)
})
response.data shows the TwiML's current XML content.
My attempts at a POST only gives the same output as the GET, while PUT gives 405 Method Not Allowed.
var URL = 'https://handler.twilio.com/twiml/EHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' + '?AccountSid=' + accountSidFlex
var twilioSig = crypto.createHmac('sha1', authTokenFlex).update(new Buffer(URL, 'utf-8')).digest('Base64')
var config = {
headers:{
'X-TWILIO-SIGNATURE': twilioSig,
'Content-Type': 'text/xml'
}
}
var xml =
'<?xml version="1.0" encoding="UTF-8"?>\
<Response><Play digits="www"/>\
<Say voice="alice">"We are currently experiencing X related issues". </Say>\
</Response>';
axios.post(
URL,xml,config
)
.catch(error => console.log(error))
.then(response => {
console.log(response.data)
})
Ideally I'd like to be able to change a specific TwiML using either HTTP methods or the Twilio-API, so that we can use it in out Studio Flow. We'd just keep it silent until we need to add something to it and revert back to silent once the issues have passed.
Any help would be appreciated!
You cannot currently change the contents of TwiML Bins, Studio Flows, or Twilio Functions programatically. I believe the key functionality you are looking for is a way to dynamically update the messaging (Say/Play Widget) in a Studio flow based on some condition.
One way is to use a Function Widget to retrieve a Twilio Sync document for the message, returning the message as JSON and have the Say/Play widget play that message. You can find the Twilio Sync REST API examples for Add, Modify, and Retrieve in the associated document.
You can retrieve the parsed response using variable syntax detailed here, https://www.twilio.com/docs/studio/widget-library#run-function.