0.2.1 • Published 4 years ago

altsendmessage v0.2.1

Weekly downloads
1
License
MIT
Repository
-
Last release
4 years ago

altsendmessage NPM version

A helper module to handle AWS SNS.publish in order to send a short message.

Install

Install with npm:

$ npm install --save altsendmessage

Usage

const {ParamsBuilder,SendMessage} = require('altsendmessage');
const aws = require('aws-sdk');
const sns = new aws.SNS({
    accessKeyId: 'my-key',
    secretAccessKey: 'my-secret',
    region: 'my-region'
})


// #1. use when creating only params with ParamsBuilder
const paramsBuilder = new ParamsBuilder();
const params = paramsBuilder.message('foo is bar')
    .to('+123456780').params;
    
sns.publish(params).promise()
    .then(data=>{
        console.log(data);
    })
    .catch(err=> {
        console.log(err);
    });


// #2. use when executing together with SendMessage
const sendMessage = new SendMessage(sns);
sendMessage.message('foo is bar')
    .to('+123456780')
    .executeSendMessage()
    .then(data=>{
        console.log(data);
    })
    .catch(err=> {
        console.log(err);
    });

API Reference

class ParamsBuilder

constructor() ⇒ ParamsBuilder
to initiate an instance of the ParamsBuilder.

clear() ⇒ ParamsBuilder
to initialize all values of .params except .params.Message.

message(txt) ⇒ ParamsBuilder
to set .params.Message by the txt argument.

body(txt) ⇒ ParamsBuilder
to call .message(txt) internally.

phoneNumber(numStr) ⇒ ParamsBuilder
to set .params.PhoneNumber by the numStr argument. (E.164 format is required)

to(numStr) ⇒ ParamsBuilder
to call .phoneNumber(numStr) internally.

class SendMessage extends ParamsBuilder

constructor(sns) ⇒ SendMessage
to initiate an instance of the SendMessage. A aws.SNS instance is required.

executeSendMessage() ⇒ Promise
to execute the publish method of the SNS of the aws-sdk. It will return a Promise when called with no argument.

executeSendMessage(callback) ⇒ SendMessage
to execute the publish method of the SNS of the aws-sdk. It will return the SendMessage when called with a callback function.

License

Copyright © 2018, Seunghwan Noh. Released under the MIT License.

0.2.1

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago