Step-by-Step Guide: Sending SMS Text Messages with Twilio API in Node.js | Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome back to the channel in this video we will see how to send text SMS using video library in node.js applications twilio is one of the popular web service provider for uh communication apis like for sending sms voice calls in the home page like if you go to the product section you can find various Services they are providing for example on the message section like you can see they are providing service for SMS WhatsApp and chat also you can also send emails using the send grid service you can make and receive voice calls and many other services are there so in our case we will use make use of for messaging service for sending text SMS so you can get started for free like once you go to the signup page so you can sign up with the email and once a signup process is completed you need to verify your email also you need to verify your phone number so after that you can navigate to the home page so you can see this is my twilio console so you can see like they will provide the trial credits for you so that you can test your application so the first thing is like you need to get it will your phone number you can see I have already got one so here you will have a button and to get a phone number so if you scroll down like you can find the account information like account Sid and authentication token and you can see it will also provide you the phone number that you have again so so this is these three informations are uh important for us in order to send SMS so you can see they have given one sample uh diagram so from our node.js applications like you can see when we execute the code it will reach to that video library and then this will communicate and send the text message to the receiver also note down these points like so you can see in your trial so you will get one phone number that supports the SMS also you can see to send messages to the recipients in United States so you need to complete the additional uh process like you need to upgrade your account so there is also one thing like you can only send messages to the verified mobile numbers when you are in trial period so for example if you go to phone number section if you expand the manage here you can find the verified caller IDs initially I have verified my mobile number that's why it is listed here you can also add one more by clicking on add new caller ID so here you can select the country code and then you can provide the number it will send you a verification code and once you verify then you can send messages to that phone number so I'm going back to the home page so let's get started with the code so here I have opened the project folder in vs code I have created a DOT EnV file as well as uh send SMS dot JS file so I have executed few commands so to start the application like I have created uh executed this command for creating the package.json file and I have also installed the twilio library as well as a DOT EnV file module so these are the two dependencies that we needed to send SMS okay so the first thing is we need to import the dot EnV Library so that you can access the environment variables so I have already added My Account Details like account Sid or token and the phone number to the environment variables so the next thing is we need to create these two variables so here you can see I'm accessing the environment variables so next we need to create a client object using the twilio library so here you can see I am passing the account Sid on the auth token like this so this expression is called uh if we pattern immediately invoked Expressions so once we create our client object so I let me create a function send SMS so this will be a sync function so we will accept a body as a argument so when we are calling this function like I would like to say hello from node.js app so this is our SMS text body so first of all we need to create the options so here we need to provide the from mobile number using the environment variables so I have a environment variable for a from number so the next option is a two so again I have one more environment variable so this is my personal mobile number which I have verified on the twilio console so in order to send SMS when you are in trial period so you need to make sure like you have verified the numbers recipient numbers okay so the next property is the body of the sms okay so we we can usually like you can provide like this after year six like you can uh proceed like this also so the next thing is I would like to open the try cash block so if there is any error so let's log to the console okay so here we we need to make use of the client uh using this we can call the messages dot create so to this function so we need to pass this message options since uh this is going to return a promise like we need to handle this as incorporation so we can make use of a weight in front of it and we can store the response in variable after this execution like we can console it to see the response in mod yes okay so I have saved this file so make sure that you have all these variables uh added in your dot EnV file so we have used from William number and the receive receiver's mobile number so I have opened the Powershell uh so here I would like to run this file so before that I would like to cast my mobile to the system so that we can see the responses okay so here I'm using a phone mirror service for mirroring my Android device or to this so let me execute this okay you can see I have received the console message as well as you can see I have received message on mobile so here you can see we got our text message but uh since you are in trial account like it will add that uh inside the body so once you upgrade then that will be removed that's all about the video guys so I hope this video is helpful do like and subscribe to the channel let's meet in another video Until then take care bye
Info
Channel: Web Wizard
Views: 8,738
Rating: undefined out of 5
Keywords:
Id: iiOXV2KySXs
Channel Id: undefined
Length: 6min 56sec (416 seconds)
Published: Fri Jun 16 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.