brewery-notif
v1.0.1
Published
A Notification Library for Brewery Project
Downloads
2
Readme
brewery-notif
A Notification Library for Brewery Project
Installation
npm install brewery-notifUsage
const BreweryNotif = require('brewery-notif');
BreweryNotif.initNotif({
sms: {
service: 'twilio',
aws: {
accessKeyId: 'XXXXXXXXXXXXXXXXXXXX',
secretAccessKey: 'XXXXXXXXXXXXXXXXXXXX',
region: 'ap-southeast-1'
},
twilio: {
accountSid: 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
authToken: 'xxxXXXXXXXXXXXXXXXXXXXXXXXXX',
fromPhoneNumber: '+12341234123'
},
},
email: {
service: 'aws',
aws: {
accessKeyId: 'XXXXXXXXXXXXXXXXXXXX',
secretAccessKey: 'XXXXXXXXXXXXXXXXXXXX',
region: 'us-east-1',
sourceEmail: '[email protected]',
senderName: 'Brewery Notif',
},
tempDir: 'file_attachments',
},
});
const message = 'Hi, Welcome to Brewery.';
let data = {
message: message,
phoneNumber: '+43214321432'
};
BreweryNotif.sendSms(data);
data = {
message: {
subject: 'Welcome to Brewery',
body: message
},
destinations: ['[email protected]']
};
BreweryNotif.sendEmail(data);API
BreweryNotif
.initNotif([config]) - Initialize the Brewery Notif
config( Type:Object, Properties:sms,email)
.sendSms([details]) - Sends an SMS message
details( Type:Object, Properties:message,phoneNumber)- Note:
phoneNumbermust be in E.164 Phone Number Format.
.sendEmail([details], dir) - Sends an email
details( Type:Object, Properties:message,destinations)dir( Type:String)- Note:
-
destinationsshould be an array. -diris the temporary directory of file attachments.
Notifications
The core notification transports that are currently available to BreweryNotif are:
Email- sends a simple email with no attachment
USAGE
BreweryNotif.initNotif({
email: {
service: 'aws',
aws: {
accessKeyId: 'XXXXXXXXXXXXXXXXXXXX',
secretAccessKey: 'XXXXXXXXXXXXXXXXXXXX',
region: 'us-east-1',
sourceEmail: '[email protected]',
senderName: 'Brewery Notif',
},
},
});
const message = 'Hi, Welcome to Brewery.';
let data = {
message: {
subject: 'Welcome to Brewery',
body: message
},
destinations: ['[email protected]']
};
const response = BreweryNotif.sendEmail(data);
return response;OUTPUT
{ "body": "MessageID is \"01234123aa1a1111-a1234567-aaa1-1a19-aa1a-aaa11a1111aa-000000\"" }Email with Attachment- sends an email with file attachment
USAGE
Your node.js code:
const multer = require('multer');
const fs = require('fs');
const { Router, static } = require('express');
const router = Router();
const config = {
email: {
service: 'aws',
aws: {
accessKeyId: 'XXXXXXXXXXXXXXXXXXXX',
secretAccessKey: 'XXXXXXXXXXXXXXXXXXXX',
region: 'us-east-1',
sourceEmail: '[email protected]',
senderName: 'Brewery Notif',
},
tempDir: 'file_attachments',
},
};
BreweryNotif.initNotif(config);
const dir = path.join(__dirname, './' + config.email.tempDir);
if (!fs.existsSync(dir)){
fs.mkdirSync(dir);
}
const storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, dir);
},
filename: function (req, file, cb) {
cb(null, file.originalname);
}
});
const upload = multer({storage: storage});
router.post('/send-email', upload.any(), function(req, res) {
const success = BreweryNotif.sendEmail(req, dir);
success.then(
function(data) {
res.json(data);
}).catch(
function(err) {
console.error(err);
});
});Your HTML code:
<html>
<body>
<form action="/send-email" method="post" enctype="multipart/form-data">
<input type="file" name="file-attached">
<br />
<label>To:</label>
<input type="text" name="destinations[0]">
<label>Subject:</label>
<input type="text" name="subject">
<label>Body:</label>
<input type="text" name="body">
<input type="submit" value="Submit">
</form>
</body>
</html>OUTPUT
{ "body": "MessageID is \"01234123aa1a1111-a1234567-aaa1-1a19-aa1a-aaa11a1111aa-000000\"" }SMS- sends an SMS message
USAGE
BreweryNotif.initNotif({
sms: {
service: 'aws',
aws: {
accessKeyId: 'XXXXXXXXXXXXXXXXXXXX',
secretAccessKey: 'XXXXXXXXXXXXXXXXXXXX',
region: 'ap-southeast-1'
},
twilio: {
accountSid: 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
authToken: 'xxxXXXXXXXXXXXXXXXXXXXXXXXXX',
fromPhoneNumber: '+12341234123'
},
},
});
const message = 'Hi, Welcome to Brewery.';
let data = {
message: message,
phoneNumber: '+43214321432'
};
const response = BreweryNotif.sendSms(data);
return response;OUTPUT
{ "body": "MessageID is \"123aa1aa-a11a-1234-11a1-11aa12345678\"" }Contributors
- Aviel Caña
- Kristaleen dela Cruz
License
MIT © Stratpoint Technologies Inc.
