Does Twilio support DTMF recognition over a voice call? - node.js

I've been following the https://github.com/TwilioDevEd/browser-calls-node project code, and I have it successfully making calls from a browser to a cellular phone, but I can't for the life of me figure out if Twilio's supports DTMF inside that call from the Cell phone.
Calling their sales department just had them create a support ticket and I haven't gotten a response.
Has anyone successfully done this? And if so, how?
This is the code I've added is to call.js, in the /connect endpoint I added:
const gather = twiml.gather({
input: 'dtmf',
finishOnKey: 9,
timeout: 1,
action: '/call/completed'
});
gather.say('Welcome to Twilio, please tell us why you\'re calling');
console.log(twiml.toString())
As well as added the route:
router.post('/completed', twilio.webhook({ validate: false }), function (req, res, next) {
console.log(req.toString());
});

Their support team replied saying (tl;dr) they only support sendDigits(digits) in the SDK, and do not support recognizing DTMF in incoming audio stream.
Their response:
The Twilio Client SDK's sendDigits(digits) parameter can used to pass dtmf tones.
The SDK only supports sending DTMF digits. It does not raise events if DTMF digits are present in the incoming audio stream.
Ref:https://www.twilio.com/docs/voice/client/javascript/connection#sendDigits```

Related

How to programmatically manipulate voice in real time while dialing using Twilio?

I have a small Twilio app that calls a real phone number (e.g. +3333333) whenever my Twilio number (e.g. +22222222) is called using my personal number (e.g. +1111111). I implement this using the following Twilio function:
exports.handler = (context, event, callback) => {
const twiml = new Twilio.twiml.VoiceResponse();
twiml.dial("+3333333");
return callback(null, twiml);
};
Now when the owner of +3333333 picks up his phone, a call connection is established between the caller (+1111111) and the target (+3333333).
How can I intercept speeches in this call, in real-time, by running a function whenever either the caller (+1111111) or the target (+3333333) speaks, to do things such as changing voice, filtering profanity, etc?
I have tried using <Gather> and <Say> TwiML verbs in my Twilio function but these will only get triggered after the call has ended or hung up.
You can actually achieve this with Twilio now. You can receive and send audio streams using the <Connect><Stream> TwiML. <Stream> allows you to receive and send audio to the call over a websocket connection in real time.
To change the audio in between, you would want to connect the callers just to the <Stream>, not to each other, and relay the audio from one call, through the websocket and whatever processing you want to do to it, and then out through the websocket connected to the other call (and vice versa).
I don't have more information on how to do that, as I've not seen it done. But it's possible in theory.

Use Google Cloud Speech in Twilio IVR

I'm using Twilio's example of Google Cloud Speech to transcribe the audio stream of Twilio in real time (because twilio model doesn't support my language). But I wanted to response to user after I heard some keyword from them. But the gather function only works with Twilio's speech model.
app.post("/", (req, res) => {
res.set("Content-Type", "text/xml");
res.send(`
<Response>
<Start>
<Stream url="wss://${req.headers.host}/"/>
</Start>
<Say>Hello?</Say>
<Gather/>
</Response>
`);
});
I would like to know how to response to user after I catch the keyword, I tried to response in the stream but it doesn't work:
recognizeStream = client
.streamingRecognize(request)
.on("error", console.error)
.on("data", (data) => {
console.log("result: " + data.results[0].alternatives[0].transcript);
if (data.results[0].alternatives[0].transcript.toLowerCase() == "xin chào"){
console.log("got xin chao")
app.post("/", (req, res) => {
res.set("Content-Type", "text/xml");
res.send(`
<Response>
<Say>Hello there</Say>
</Response>
`);
});
}
Please help me out, thanks!
Twilio developer evangelist here.
When you use <Start><Stream> Twilio forks the audio and starts sending the audio from the call to your websocket. The call then carries on with the next TwiML instruction. If you want to interrupt the user once they say a keyword there are two approaches you can take.
Instead of using <Start><Stream> you can use <Connect><Stream>. <Connect> sets up a bidirectional stream, allowing you to receive the audio over the web socket connection and send audio back over the web socket. This way you could use the Google Cloud Speech API to generate your responses and stream them into the call. <Connect> doesn't fork the stream, so it won't carry out the TwiML instructions after it until the connection is ended.
Alternatively, you can continue using <Start><Stream> but once you get the keyword you are looking for you can redirect the call to new TwiML. Note that you need to use the REST API to update the call rather than returning TwiML within the web socket stream, like you are attempting.

Playing custom notification sound using Cloud Functions - iOS

I'm sending notification to my client app using Cloud Functions and GoogleCloudMessaging in this way:
const notificationContent = {
notification: {
title: `${senderName} has sent you a message`,
body: `${messageString}`,
icon: "default",
sound: "customNotificationSound",
},
};
return admin.messaging()
.sendToDevice(notifToken, notificationContent)
.then((result) =>{
console.log("write done correctly");
});
I want to use a custom notification sound instead of the default one; so I followed some guides online like this, this and this but they don't seem to answer my question.
Since I'm sending the push notification from the cloud function, do I still need to load the sound file in the client Main Bundle (I tried it and in fact it doesn't seem to work).
Or do I have to upload it somewhere else?
P.s. also the sound file extension is .wav so there shouldn't be problems for that matter.
I solved this and the answer is Yes, you still need to upload the music file in your main bundle even tough you're sending the push notification from cloud functions

how to send sms from within Twilio programmable voice function

I have a Twilio function which executes whenever someone calls a certain number. I'm trying to have the function send an sms. It's not working, but I'm not getting any error. Any help debugging would be great.
exports.handler = function(context, event, callback) {
let response = new Twilio.twiml.MessagingResponse();
response.message({
to: '+11234567890',
}, 'new sms from testing');
};
Additionally, If you could let me know how to access the incoming phone number within this function, I would greatly appreciate it. Thanks in advance for any suggestions or insights.
You will not be able to send a messaging response to a voice event, you'll need to create a messaging client and send separately. See docs here: https://www.twilio.com/docs/sms/tutorials/how-to-send-sms-messages-node-js .
For incoming phone numbers, that is included in the event object. It should be event.From, but you can log the event object to get all the parameters. They should follow the Call object schema: https://www.twilio.com/docs/voice/api/call

Add a bot into Twilio conference, and announce some information, using conference Friendly name

With below code my users are joining a conference call, conference is created with unique names.
const VoiceResponse = require('twilio').twiml.VoiceResponse;
const response = new VoiceResponse();
const dial = response.dial();
dial.conference({
statusCallback: <event_url>,
statusCallbackEvent: 'start end join leave'
}, "test_conference_name");
res.type('text/xml');
res.send(response.toString());
Now I want to add bot to this conference call and announce something to all users, like conference is going to end in next 5 min.
const twilio_client = require('twilio')(accountSid, authToken);
twilio_client.calls.create({
url: "<twiml url with voice responce>",
to: "test_conference_name",
from: "+17016390587",
})
.then((call) => {
console.log("success")
})
I am getting error that The phone number you are attempting to call, "test_conference_name", is not valid.
I saw this solution in this post Twilio: programmatically join conference and play <Say> command or <Play> sound file? but it has old syntax and working with a conference no.
I wan to add a bot on the basis of conference name, I don't have conference no.
Twilio developer evangelist here.
Right now, you have two options. However, they both require a number to be connected.
You can either setup a number that points to a URL that returns TwiML to direct your bot into the conference and you call that number with your bot (as the solution from the question you linked).
Or, you create a call from your conference to a number that is connected to your bot which has an inbound webhook that points to the TwiML for the message it's going to say to your conference.
Finally, Conference is getting more features at the moment and the ability to <Say> or <Play> something to your participants is coming soon, according to this blog post.
Let me know if that helps at all.

Resources