SDK comes with wrappers around different node modules for sending Email and SMS in a single interface named Notifier
.
The SDK currently supports the following notifiers:
Before we start, we need to setup our message templates per email and sms channels:
import { Notifications } from "@ssofy/node-sdk";
...
const templates = [
<Notifications.Template>{
name: 'otp',
path: 'PATH_TO_SMS_HANDLEBARS_TEMPLATE_FILE',
engine: Notifications.HandlebarsEngine,
channel: Notifications.Channel.SMS
},
<Notifications.Template>{
name: 'otp',
path: 'PATH_TO_EMAIL_HANDLEBARS_TEMPLATE_FILE',
engine: Notifications.HandlebarsEngine,
channel: Notifications.Channel.EMAIL
},
];
Installing dependencies:
npm i twilio -S
import { Notifications } from "@ssofy/node-sdk";
import * as Twilio from "twilio";
...
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const twilio = Twilio(accountSid, authToken);
const notifier = new Notifications.TwilioSMSNotifier(
twilio, // twilio client
'+441234567890', // sender
templates, // message templates
{ // optional template vars
brand: 'SSOfy'
}
);
Installing dependencies:
npm i @vonage/server-sdk -S
import { Notifications } from "@ssofy/node-sdk";
import { Vonage } from "@vonage/server-sdk";
...
const vonage = new Vonage({
apiKey: 'xxx',
apiSecret: 'xxx',
});
const notifier = new Notifications.VonageSMSNotifier(
vonage, // vonage client
'+441234567890', // sender
templates, // message templates
{ // optional template vars
brand: 'SSOfy'
}
);
Installing dependencies:
npm i nodemailer -S
import { Notifications } from "@ssofy/node-sdk";
import * as nodemailer from "nodemailer";
...
const transport = nodemailer.createTransport({
host: "smtp.example.com",
port: 587,
secure: false,
auth: {
user: "username",
pass: "password",
},
});
const transporter = nodemailer.createTransport(transport);
const notifier = new Notifications.NodemailerEmailNotifier(
transporter, // nodemailer transporter
'no-reply@example.com', // sender
templates, // message templates
{ // optional template vars
brand: 'SSOfy'
}
);
Installing dependencies:
npm i @sendgrid/mail -S
import { Notifications } from "@ssofy/node-sdk";
import * as sgMail from "@sendgrid/mail";
...
sgMail.setApiKey('xxx');
const notifier = new Notifications.SendGridEmailNotifier(
sgMail, // sendgrid client
'no-reply@example.com', // sender
templates, // message templates
{ // optional template vars
brand: 'SSOfy'
}
);
Installing dependencies:
npm i @mailchimp/mailchimp_transactional -S
import { Notifications } from "@ssofy/node-sdk";
import * as mailchimp from "@mailchimp/mailchimp_transactional";
...
const mailchimpClient = mailchimp(
"YOUR_API_KEY"
);
const notifier = new Notifications.MailchimpNotifier(
mailchimpClient, // mailchimp client
'no-reply@example.com', // sender
templates, // message templates
{ // optional template vars
brand: 'SSOfy'
}
);
Installing dependencies:
npm i mailgun.js -S
import { Notifications } from "@ssofy/node-sdk";
import * as FormData from 'form-data';
import Mailgun from 'mailgun.js';
...
const mailgun = new Mailgun(FormData);
const mg = mailgun.client({
username: 'api',
key: 'xxx'
});
const notifier = new Notifications.MailgunEmailNotifier(
mg, // mailgun client
'no-reply@example.com', // sender
templates, // message templates
{ // optional template vars
brand: 'SSOfy'
}
);
Installing dependencies:
npm i aws-sdk -S
import { Notifications } from "@ssofy/node-sdk";
import AWS from 'aws-sdk';
...
AWS.config.update({
region: 'REGION'
});
const ses = new AWS.SES({
apiVersion: '2010-12-01'
});
const notifier = new Notifications.SESEmailNotifier(
ses, // ses client
'no-reply@example.com', // sender
templates, // message templates
{ // optional template vars
brand: 'SSOfy'
}
);
Checkout the Notifier interface for the list of available methods.
You may also build your own custom notifier by implementing the Notifier Interface.