notification-service-sdk
Version:
A Node.js notification service SDK supporting email and SMS providers
55 lines • 1.99 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.LarkProvider = void 0;
const interfaces_1 = require("../interfaces");
const axios_1 = __importDefault(require("axios"));
class LarkProvider {
constructor(config) {
if (!config.notifyUrl) {
throw new interfaces_1.NotificationError('Invalid Lark Notify url', 'INVALID_CONFIG');
}
this.notifyUrl = config.notifyUrl;
}
async send(message) {
try {
if (!message.card) {
throw new interfaces_1.NotificationError('Card are required', 'MISSING_CARD');
}
if (!message.msg_type) {
throw new interfaces_1.NotificationError('Message type is required', 'MISSING_MESSAGE_TYPE');
}
if (!message.receive_id) {
throw new interfaces_1.NotificationError('Receive ID is required', 'MISSING_RECEIVE_ID');
}
// 处理电话号码格式
const paramConfig = {
headers: {
'Content-Type': 'application/json',
},
};
const res = await axios_1.default.post(this.notifyUrl, message, paramConfig);
if (res.status == 200) {
return {
success: true,
};
}
else {
return {
success: false,
error: new interfaces_1.NotificationError(`Failed to send SMS: ${res.data.Message}`),
};
}
}
catch (error) {
return {
success: false,
error: error instanceof Error ? error : new Error(String(error)),
};
}
}
}
exports.LarkProvider = LarkProvider;
//# sourceMappingURL=lark.js.map