This guide shows how to send SMS messages using the Azure Communication Services JavaScript SDK.
npm install @azure/communication-sms
import { SmsClient } from "@azure/communication-sms";
const connectionString = "";
const smsClient = new SmsClient(connectionString);
async function sendSms() {
try {
const sendResult = await smsClient.send({
from: "",
to: ["+1234567890"],
message: "Hello from Azure Communication Services!",
enableDeliveryReport: true,
tag: "demo-sms"
});
console.log("SMS sent successfully:", sendResult);
} catch (err) {
console.error("Failed to send SMS:", err);
}
}
sendSms();
Save the code to a file sendSms.js and execute:
node sendSms.js
SmsClient.send(options)
from – The Azure phone number to send from.to – An array of recipient phone numbers.message – The text message.enableDeliveryReport – (optional) Set to true to receive delivery status.tag – (optional) Custom tag for tracking.