sendDigits Function sample code is not working

491 views
Skip to first unread message

Michael Windsor

unread,
Aug 5, 2020, 12:46:21 PM8/5/20
to Twilio Functions
I'm trying to use a function in twilio studio to forward a call to a phone number with an extension. The Twilio Docs on using sendDigits gives this example code in node.js: 

const VoiceResponse = require('twilio').twiml.VoiceResponse;


const response = new VoiceResponse();
const dial = response.dial();
dial.number({
sendDigits: 'wwww1928'
}, '415-123-4567');

console.log(response.toString());

but dial.number gives the error message "twiml.dial.number is not a function". And when I call my twilio number, I hear a message that says "the number you dialed is not a working number". 

If I remove the number so that it reads:

dial({
sendDigits: 'wwww1928'
}, '415-123-4567');

then I can call my twilio number and get through to the phone number it's supposed to connect me to, but it is not dialing the sendDigits. So it's only doing what a "Connect Call to" widget would do in studio, which is not helpful to me. I need it to dial the sendDigits so that I can call an extension.

Here's my current studio flow. There are other widgets, but they're disconnected at the moment and irrelevant to the issue so I left them off the screenshot. This set up just uses one "Run Function" to pick the number to forward someone to and another "Run Function" to dial the number with an extension (which is not working). 

Any tips on getting sendDigits to work would be really appreciated.
Screen Shot 2020-08-05 at 10.40.40 AM.png

Malcolm Elavia

unread,
Aug 5, 2020, 12:53:54 PM8/5/20
to Twilio Functions
I'm a newbie so take it for what it is but I believe your phone number is in the wrong format, it should be:
[+][country code][phone number] 
So for a US number the format would be +15554443333 
Hope it helps

Malcolm Elavia

unread,
Aug 5, 2020, 12:56:09 PM8/5/20
to Twilio Functions
I went to the DOCS to try and link it for you but upon doing so I see that your format works too. Sorry, but I'm not a strong enough coder to help =\


On Wednesday, August 5, 2020 at 12:46:21 PM UTC-4, Michael Windsor wrote:

Michael Windsor

unread,
Aug 5, 2020, 12:58:05 PM8/5/20
to Twilio Functions
Thanks for your reply! That's just the example number from Twilio. In my actual code, I do have the +1. But as I understand it, Twilio gives extra slack on US numbers and they can be in either format. I have tried my own number in both formats just to make sure that wasn't the issue though so it's a good suggestion. 

Malcolm Elavia

unread,
Aug 5, 2020, 12:58:05 PM8/5/20
to Twilio Functions
I'm not sure what language you're using but your code looks to be formatted different when looking at all the different language examples. Maybe this link will help you https://www.twilio.com/docs/voice/twiml/number#:~:text=Phone%20numbers%20should%20be%20formatted,or%20415%2D555%2D1212.


On Wednesday, August 5, 2020 at 12:46:21 PM UTC-4, Michael Windsor wrote:

Michael Windsor

unread,
Aug 5, 2020, 12:59:24 PM8/5/20
to Twilio Functions
haha the link you provided is the same link I provide above and that's where the sample code I included in my post came from. It's the node.js example. 

Malcolm Elavia

unread,
Aug 5, 2020, 1:12:20 PM8/5/20
to Twilio Functions
Did you check to make sure your webhooks are properly set when calling the function?
Again, sorry if this is rudimentary as I am a newbie and just learned node.js but not strong.

Michael Windsor

unread,
Aug 5, 2020, 1:26:14 PM8/5/20
to Twilio Functions
Yes I did check that too but I appreciate you asking all these questions since I'm new too. BUT a friend just took a look and figured it out! I was using the wrong variable in the callback. I had been trying "dial" but I needed to be using "response". 

Malcolm Elavia

unread,
Aug 5, 2020, 2:05:45 PM8/5/20
to Twilio Functions
Glad you got it working!
Newbies unite!



On Wednesday, August 5, 2020 at 12:46:21 PM UTC-4, Michael Windsor wrote:
Reply all
Reply to author
Forward
0 new messages