mares-apistore-message-sender
Version:
apistore용 rest api를 wrapping한 node.js용 모듈입니다.
64 lines (54 loc) • 1.84 kB
JavaScript
const rp = require('request-promise');
module.exports = {
/**
* 문자를 발송한다. private method. 외부에서 호출안함.
* @param {string} token - apistore에서 발급받은 토큰
* @param {string} from - 발신번호
* @param {string} to - 착신번호
* @param {string} title - 문자제목 LMS에서만 가능하다.
* @param {string} body - 문자 내용
* @returns {Promise<void>}
*/
async send(token, from, to, title, body) {
to = to.replace('+82', '0');
from = from.replace('+82', '0');
const options = {
uri: 'http://api.openapi.io/ppurio/1/message/sms/slogup',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'x-waple-authorization': token
},
formData: {
send_phone: from,
dest_phone: to,
msg_body: body
}
};
if (title) {
options.formData.subject = title;
}
return await rp(options);
},
/**
* 문자를 발송할 번호를 등록한다
* @param {string} token - apistore에서 발급받은 토큰
* @param {string} from - 발송번호
* @returns {Promise<void>}
*/
async register(token, from) {
from = from.replace('+82', '0');
const options = {
uri: 'http://api.openapi.io/ppurio/1/sendnumber/save/slogup',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'x-waple-authorization': token
},
formData: {
sendnumber: from
}
};
return await rp(options);
}
};