node-easysms
Version:
EasySMS is an SMS sender for Node.js
181 lines (180 loc) • 4.58 kB
JavaScript
'use strict';
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Message = void 0;
/**
* 消息类
*/
class Message {
constructor(attributes, type = Message.TEXT_MESSAGE) {
this.gateways = [];
this.type = '';
this.sign_name = '';
this.content = '';
this.template = '';
this.data = null;
this.type = type;
if (attributes['sign_name']) {
this.sign_name = attributes['sign_name'];
}
if (attributes['content']) {
this.content = attributes['content'];
}
if (attributes['template']) {
this.template = attributes['template'];
}
if (attributes['data']) {
if (typeof attributes['data'] === 'function') {
this.data = attributes['data'];
}
else {
this.data = Object.assign({}, attributes['data']);
}
}
}
/**
* 设置消息所对应的网关
* @param gateways
* @returns
*/
setGateways(gateways) {
this.gateways = gateways;
return this;
}
/**
* 获取消息所对应的网关
* @returns
*/
getGateways() {
return this.gateways;
}
/**
* 设置消息类型
* @param type
* @returns
*/
setType(type) {
this.type = type;
return this;
}
/**
* 获取消息类型
* @returns
*/
getType() {
return this.type;
}
/**
* 获取消息类型
* @returns
*/
getMessageType() {
return this.type;
}
/**
* 设置消息签名
* @param sign_name
* @returns
*/
setSignName(sign_name) {
this.sign_name = sign_name;
return this;
}
/**
* 获取消息签名
* @param gateway 当前网关
* @returns
*/
getSignName(gateway) {
return __awaiter(this, void 0, void 0, function* () {
if (typeof this.sign_name === 'function') {
return yield this.sign_name(gateway);
}
return this.sign_name;
});
}
/**
* 设置消息内容
* @param content
* @returns
*/
setContent(content) {
this.content = content;
return this;
}
/**
* 获取消息内容
* @param gateway 当前网关
* @returns
*/
getContent(gateway) {
return __awaiter(this, void 0, void 0, function* () {
if (typeof this.content === 'function') {
return yield this.content(gateway);
}
return this.content;
});
}
/**
* 设置消息模版
* @param template
* @returns
*/
setTemplate(template) {
this.template = template;
return this;
}
/**
* 获取消息模版
* @param gateway 当前网关
* @returns
*/
getTemplate(gateway) {
return __awaiter(this, void 0, void 0, function* () {
if (typeof this.template === 'function') {
return yield this.template(gateway);
}
return this.template;
});
}
setData(data) {
if (typeof data === 'function') {
this.data = data;
}
else {
this.data = Object.assign({}, data);
}
return this;
}
/**
* 获取消息模版参数
* @param gateway 当前网关
* @returns
*/
getData(gateway) {
return __awaiter(this, void 0, void 0, function* () {
if (typeof this.data === 'function') {
return yield this.data(gateway);
}
return this.data;
});
}
}
exports.Message = Message;
/**
* 文本消息
*/
Message.TEXT_MESSAGE = 'text';
/**
* 语音消息
*/
Message.VOICE_MESSAGE = 'voice';
;