Sending SMS Through Analysis


I’m working on a simple script to send an SMS message to a user, and I can’t quite figure out what I’m doing wrong. I can get emails to work, but not SMS. This function gets called from within an Analysis. I’ve replaced my phone number with 5’s in the snip below, but kept the country code for USA.

async function sendSMSNotification(context) {
  const smsService = new Services(context.token).sms;
  const messageText = "test";
  const phone = "+15555555555"
  await smsService.send({to: phone, message: messageText}).then(context.log).catch(context.log);

I was able to successfully send a text message from an action, but not from within my analysis. When the analysis runs, the console prints "Error on SMS Server. " Appreciate any insight!

Hi @jefft,

change the first line of your function to:

  const smsService = new Services({ token: context.token }).sms;

lmk if it helps.


1 Like

Hey Guilherme,

Thanks! I’ve got it working now. When I changed the first line as you suggested, I started getting an “Authorization Denied” error. To fix it, it required changing my “Services” variable. Originally, I had it as:

const Services = require('tago/services');

To fix it, I added it to the tago sdk block:

const { Analysis, Utils, Account, Device, Services } = require('@tago-io/sdk');

Thanks for your help!

1 Like