'How to send SMS using node.js

I want to make web app designed to send SMS via web interface. How can I send SMS (from my phone number) to specified recipient using node/express? Is twilio the only way?



Solution 1:[1]

Unless there are some very particular functionalities your mobile carrier is providing, there is nothing like send SMS (from my phone number) ... using node/express.

Only the phone that has your SIM installed within can send SMS from your number.

Possible solutions

  • If you are only interested in sending SMS from a web platform use a provider like Sendgrid and twillio
  • If you need to send SMS from a phone number assigned to a physical SIM owned by you, devices exists that can be connected to your server, will host your SIM, and allow you to send messages.
  • If you need to send SMS from your phone number (and be able to use your number at the same time) you may create a mobile app that regularly downloads updates from your server and send the listed messages.

Solution 2:[2]

I have used Twilio to send a Programmable SMS, so little but knowing about the product, you can create a free trial account and try SMS feature of Twilio.

Answer to your this question -> How can I send SMS (from my phone number) to a specified recipient using node/express?

-->

you can procure the Twilio Number to send SMS / (for Inbound or Outbound calls). you need to just choose your favorite number from Twilio.

Node.js Code :

const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);

client.messages
.create({
      body: 'This is the ship that made the Kessel Run in fourteen 
      parsecs?',
 from: '+15017122661',
 to: '+15558675310'
 })
.then(message => console.log(message.sid)); 

you will find accountSid, authToken once you log in to Twilio.

here is the reference link: https://www.twilio.com/docs/sms/quickstart/node

Give your first ever try with Twilio. Enjoy :)

Solution 3:[3]

Sendgrid and twillio are the major two services to send SMS.

Solution 4:[4]

Twilio is not the only way , You can also use services like messente and plivo. both services provide an API which can be integrated into your code base (node/express) , and it is preferable to handle this functionality using the superface sdk (it is easy to use and integrate multiple providers with much less code) . follow the two steps below

npm install @superfaceai/one-sdk

npx @superfaceai/cli install communication/send-sms

const { SuperfaceClient } = require('@superfaceai/one-sdk');

const sdk = new SuperfaceClient();

async function run() {
  // Load the installed profile
  const profile = await sdk.getProfile('communication/send-sms');

  // Use the profile
  const result = await profile
    .getUseCase('SendMessage')
    .perform({
      to: '+12127290149',
      from: '+4915207955279',
      text: 'Your order is ready to be picked up!'
    });

  return result.unwrap();
}

run();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Newbie
Solution 2 Santosh Suryawanshi
Solution 3 Sangam Rajpara
Solution 4 Henok