const args = message.content.split(' ')
const phNumber = args[1]
const ttsMessage = args.slice(2).join(' ')
if (phNumber) {
// Call phNumber and say ttsMessage and collect keypad input code
const call = await TwilioClient.calls.create({
url: 'http://demo.twilio.com/docs/voice.xml',
to: phNumber,
from: process.env.TWILIO_PHONE_NUMBER,
})
}
// somehow get the input the user entered and do something with it here. Maybe by using await or Promises etc...
I want to get the number the user entered and do some stuff with it!
When you create a call resource in the Twilio API, it will initiate a phone call between the two numbers you specified, and also send a webhook request to the url you specified.
This url should point to your webserver where you can handle the webhook request and respond with TwiML instructions. These instructions are how you manage the phone call. One of the TwiML verbs is <Gather> where you can ask for input using DTMF (digits on the phone dialer) or voice.
The user response will be posted back to you with another webhook request, this time to the URL specified in the action attribute from the <Gather> verb.
You cannot provide TwiML instructions using the Twilio API or get the input back, you have to use webhooks.
It's not easy, but you technically could use a websocket connection (or some other way of communication) to connect your webhook server and your node.js app, so that your webhook server can stream the data to your node.js app, and your node.js app could send information back. This way you could exchange information from the call in realtime between the node.js app that created the call, and the webhook server that is managing the call.
I recommend checking out this tutorial on responding to phone calls using node.js.