1
votes

Currently my bot is on Facebook messenger, used by employees. I'd like my bot to send one SMS to a person to welcome him / her to our team and with its credentials.

I know Microsoft Bot Framework integrates Twilio, so I integrated Twilio channel following this: https://docs.microsoft.com/en-us/bot-framework/channel-connect-twilio, so I have a phone, and everything is well configured because I can send manually SMS (from the Twilio's dashboard), it works.

Problem is that I don't know how to use it right now, in the bot.

const confirmPerson = (session, results) => {
  try {
    if (results.response && session.userData.required) {

      // Here I want to send SMS

      session.endDialog('SMS sent ! (TODO)');
    } else {
      session.endDialog('SMS cancelled !');
    }
  } catch (e) {
    console.error(e);
    session.endDialog('I had a problem while sending SMS :/');
  }
};

How to achieve this ?

EDIT: Precision, the person welcoming employee is a coach, just sending SMS from bot with the credentials to use in the webapp the bot connects after first usage by the user welcomed

1

1 Answers

2
votes

Twilio developer evangelist here.

You can do this in bot framework by sending an ad-hoc proactive message. It seems you'd need to create an address for the user that you want to send messages to though and I can't find in the documentation what an address should look like.

Since you're in a Node environment, you could use Twilio's API wrapper to this though. Just install twilio to your project with:

npm install twilio

Then gather your account credentials and use the module like so:

const Twilio = require('twilio');

const confirmPerson = (session, results) => {
  try {
    if (results.response && session.userData.required) {

      const client = new Twilio('your_account_sid','your_auth_token');

      client.messages.create({
        to: session.userData.phoneNumber,   // or whereever it's stored.
        from: 'your_twilio_number',
        body: 'Your body here'
      }).then(function() {
        session.endDialog('SMS sent ! (TODO)');
      }).catch(function() {
        session.endDialog('SMS could not be sent.');
      })

    } else {
      session.endDialog('SMS cancelled !');
    }
  } catch (e) {
    console.error(e);
    session.endDialog('I had a problem while sending SMS :/');
  }
};

Let me know how this goes.