In this article we will gonna learn how we can send SMS using Bandwidth in Node.

What is Bandwidth ?

Bandwidth is a big company which provide services like sms messaging and calling. It is the only API platform provider that owns a Tier 1 network, giving you better quality, rates, and control.

Bandwidth services are used by the Google, Zoom, GoDaddy and other big companies.

Send sms using Bandwidth

To use the bandwidth messaging services with node you gonna need few things.

  • First of all get an account on bandwidth and get the following values basicAuthUserName, basicAuthPassword, applicationId, userId (AccountId).
  • Once you have got your values then you need to install a package in order to use SMS service @bandwidth/messaging.

You can create an account using this url and then install above package using below command.

npm install --save @bandwidth/messaging

Once above two steps are done you can move to code part.

First of all import bandwidth package.

import BandwidthMessaging from '@bandwidth/messaging';

Then add your tokens and other values.

BandwidthMessaging.Configuration.basicAuthUserName = "apitoken"; // The username to use with basic authentication
BandwidthMessaging.Configuration.basicAuthPassword = "apisecret"; // The password to use with basic authentication

const applicationId = '';
const userId = '';

Create a controller.

const messagingController = BandwidthMessaging.APIController;

then create a message body.

 const body = new BandwidthMessaging.MessageRequest({
      applicationId,
      to:["number"],
      from:"number", 
      text: "",
    });

send above message body using controller.

const response = await messagingController.createMessage(userId, body);

You can check response for message status. Don’t forget to wrap your code in try and catch.

Feel free to write your valuable comments and I hope you have learned about sending sms using bandwidth.

Generate pdf from dom with multiple pages and without cutting

Categories: JavaScript

1 Comment

How to make wiggly div in React - Blog React · September 25, 2020 at 3:31 am

[…] How to send SMS using Bandwidth in Node […]

Comments are closed.