Integrate Twilio with Node.js - Send SMS and MMS, make phone calls and implement text-to-speech
HTML-код
- Опубликовано: 18 окт 2024
- In this video, we're gonna learn how to integrate Twilio with Node.js.
We're gonna learn how to send SMS and MMS, make phone calls playing an audio file (.mp3) with a recorded message, send instructions using TwiML file (.xml) and implement text-to-speech in different languages.
🔗 GitHub Repository:
github.com/man...
Sir your content just ❤
thanks, bro you save me time
These bro's contents is on another level 🙌🏾. I subscribed and hit the bell to receive every video you uploaded since the day I found you on YT. Keep it up, we are here to support you. Bless.
Thank you very much my friend.🤜🏻🤛🏻
sir you are back 😇
sir do you run a business, work a job, or do freelancing?
@snacksports8188 I actually do all 3 lol. But I’m more focused on my job, which is backend with ai, and a little of frontend as well.
Love from Pakistan
TOP TOP TOP Thanks
Nice content bro! I see that you always type Brazil, are you Brazilian as well?
Obrigado meu amigo. Sou sim rsrs
@@manfraio tem linkedin irmao??
@@manfraio sou muito grato para esse video, vou precisar integrar o Twilio no meu micro-saas esse mes.
great
can you please make videos on zustand, react-query, zod, react router and lastly how can we use them all together efficiently?
Yes we have plans to add react, react native and next.js videos. We’re focusing more on backend for now but soon we’ll have full stack projects. Stay tuned!
Thanks man, do you have experience how to send to WhatsApp or viber messages with twilio or maybe another service?
For WhatsApp I recommend using their official API. There’s a video here o the channel explaining how to use WhatsApp API with Node.js.
Integrate Whatsapp API with Node.js:
ruclips.net/video/4cvQxqFZTIQ/видео.html
@@manfraio 🤝 thanks a lot, bro
can i give that say or play URL of audio as dynamically in between the call , I mean I want play URL of audio or say as Multiple Times with different data in single call
Yes, you can use the say and play properties together multiple times on the call.
@@manfraio i mean if user says 'hi' in call I want to play some relevant audio on ongoing call , is it possible ?
Here is an example of how to make an outbound call using Twilio, wait for the user to say something, and then respond accordingly by either playing an audio file or saying something:
1. Create an endpoint to make the call and when the user answer, pass another endpoint to the url property to handle the answering:
app.post('/make-call', async (req, res) => {
const toNumber = req.body.to; // Get the user's number from the request
try {
const call = await client.calls.create({
url: 'your_app_url/voice', // This won't work on localhost. To test locally you would have to use something like ngrok
to: toNumber,
from: 'YOUR_TWILIO_PHONE_NUMBER' // Your Twilio number
});
res.send(`Calling ${toNumber}...`);
} catch (err) {
console.error(err);
res.status(500).send('Error making the call.');
}
});
2. Create the endpoint to handle the response (the same endpoint you passed on the URL parameter on the make-call endpoint) :
app.post('/voice', (req, res) => {
const twimlResponse = new twilio.twiml.VoiceResponse();
const gather = twimlResponse.gather({
input: 'speech',
speechTimeout: '3s', // Wait 3s for the user to say something
action: '/process-speech', // This won't work locally as well. Use something like ngrok
method: 'POST', // Method from the /process-speech endpoint passed above on the action attribute
});
gather.say('Please say something to continue.');
// If no speech is detected, re-prompt
twimlResponse.say('I did not hear anything. Please try again.');
twimlResponse.redirect('/voice');
res.type('text/xml');
res.send(twimlResponse.toString());
});
3. Create the third endpoint to process the speech, that means handle whatever the user said:
app.post('/process-speech', (req, res) => {
const twimlResponse = new twilio.twiml.VoiceResponse();
const speechResult = req.body.SpeechResult;
// Check what the user said
if (speechResult) {
twimlResponse.say(`You said: ${speechResult}. Now playing audio.`);
twimlResponse.play('www.example.com/path/to/your/audio.mp3'); // Replace with your audio file URL
} else {
twimlResponse.say('I did not recognize that. Please try again.');
twimlResponse.redirect('/voice');
}
res.type('text/xml');
res.send(twimlResponse.toString());
});
@@manfraio can you make a separate video about that