Reputation: 31
What I am trying to achieve is that I want to use the Whisper function in Twilio Studio.
Referencing this prior post Want to use Whisper in Twilio Studio the answer is that you cannot and it is advised to use TWIML to do this. This solution when used just using TWIML works fine. My question following on from this is that can you call TWIML from within Studio? It seems to me that you cannot but would be interested if someone can please clarify if this is the case.
Now, you can call functions from within Studio. So the next possible solution is that we write a function to use the whisper
Below is a template for call forwarding which works nicely to forward a number to using a function.
/**
* Call Forward Template
*
* This Function will forward a call to another phone number. If the call isn't answered or the line is busy,
* the call is optionally forwarded to a specified URL. You can optionally restrict which calling phones
* will be forwarded.
*/
exports.handler = function(context, event, callback) {
// set-up the variables that this Function will use to forward a phone call using TwiML
// REQUIRED - you must set this
let phoneNumber = event.PhoneNumber || "NUMBER TO FORWARD TO";
// OPTIONAL
let callerId = event.CallerId || null;
// OPTIONAL
let timeout = event.Timeout || null;
// OPTIONAL
let allowedCallers = event.allowedCallers || [];
// generate the TwiML to tell Twilio how to forward this call
let twiml = new Twilio.twiml.VoiceResponse();
let allowedThrough = true
if (allowedCallers.length > 0) {
if (allowedCallers.indexOf(event.From) === -1) {
allowedThrough = false;
}
}
let dialParams = {};
if (callerId) {
dialParams.callerId = callerId
}
if (timeout) {
dialParams.timeout = timeout
}
if (allowedThrough) {
twiml.dial(dialParams, phoneNumber);
}
else {
twiml.say('Sorry, you are calling from a restricted number. Good bye.');
}
// return the TwiML
callback(null, twiml);
};
The important parts of this are
// REQUIRED - you must set this
let phoneNumber = event.PhoneNumber || "NUMBER TO FORWARD TO";
Which is easy as you just enter the number you wish to forward to.
And this which is the important bit in my opinion
if (allowedThrough) {
twiml.dial(dialParams, phoneNumber);
So the question is, can we insert the whisper URL from the TWIML whisper in there. Something similar to the following.
twiml.dial({ url: 'https://handler.twilio.com/twiml/EH0b18ce0682059675bc39deca4e76e472' }, phoneNumber);
This doesn't work when I call this function from within Studio and I get the following error.
Msg "XML Validation warning"
line "1"
parserMessage " Attribute 'url' is not allowed to appear in element
'Dial'."
ErrorCode "12200"
cols "224"
LogLevel "WARN"
url "https://olivine-okapi-1701.twil.io/fwd_whisper"
This seems like hopefully just a syntax error. Not being a developer any help on this as to what is the correct syntax or whether or not this can even be done
Upvotes: 0
Views: 816
Reputation: 10781
You can use this article for reference, Recording a Phone Call with Twilio - . You will follow the example provided under, Record a Two-way Call using the TwiML Verb. So you would add the record attribute to the dialParams object:
dialParams.record = "record-from-ringing".
Upvotes: 0
Reputation: 10781
Whisper is handled by the Number Noun which falls under the Dial verb.
Try something like this instead:
if (allowedThrough) {
twiml.dial(dialParams)
.number({url: 'https://handler.twilio.com/twiml/EH0b18ce0682059675bc39deca4e76e472'}, phoneNumber);
}
Upvotes: 2