dynamicsmobile
Version:
Allows development of off-line mobile and web business apps over the Dynamics Mobile platform. More info on https://www.dynamicsmobile.com
199 lines • 8.96 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MobileNotificationService = void 0;
const tslib_1 = require("tslib");
const injectable_1 = require("../ioc/injectable");
const notification_service_1 = require("../lib-core/notification-service");
const dms_root_container_1 = require("../ioc/dms-root-container");
const syncpacket_service_1 = require("../lib-core/syncpacket-service");
let MobileNotificationService = exports.MobileNotificationService = class MobileNotificationService extends notification_service_1.NotificationService {
sendSms(recipient, content) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (!recipient) {
throw new Error('NotificationService.sendSms requires recipient argument');
}
// const re = /^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$/
// if(!re.test(String(recipient).toLowerCase())){
// throw new Error('NotificationService.sendSms requires valid phone number for recipient argument');
// }
if (!content) {
throw new Error('NotificationService.sendsms requires content argument');
}
if (content.length > 240) {
throw new Error('NotificationService.sendsms requires content with length below 240');
}
const message = {
recipient: recipient,
message: {
content: Buffer.from(content).toString('base64'),
},
channel: 'sms',
className: '$NotificationMessage',
boName: '$NotificationMessage',
objectTableName: '$NotificationMessage'
};
const ps = dms_root_container_1.RootDIContainer.inject(syncpacket_service_1.SyncPacketService);
ps.start();
ps.addEntity(message);
yield ps.post();
});
}
sendEmail(recipient, subject, content, attachments, sender) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (!recipient) {
throw new Error('NotificationService. requires recipient argument');
}
const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if (!re.test(String(recipient).toLowerCase())) {
throw new Error('NotificationService. requires valid email for recipient argument');
}
if (sender) {
if (!re.test(String(sender).toLowerCase())) {
throw new Error('NotificationService.sendEmail requires valid email for sender argument');
}
}
if (!subject) {
throw new Error('NotificationService.sendEmail requires subject argument');
}
if (!content) {
throw new Error('NotificationService.sendEmail requires content argument');
}
const message = {
recipient: recipient,
sender: sender,
message: {
subject: Buffer.from(subject).toString('base64'),
content: Buffer.from(content).toString('base64'),
},
channel: 'email',
className: '$NotificationMessage',
boName: '$NotificationMessage',
objectTableName: '$NotificationMessage'
};
const ps = dms_root_container_1.RootDIContainer.inject(syncpacket_service_1.SyncPacketService);
ps.start();
ps.addEntity(message);
yield ps.post();
});
}
sendViber(appCode, recipient, type, content) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (!appCode) {
throw new Error('NotificationService.sendViber requires appCode argument');
}
if (!recipient) {
throw new Error('NotificationService.sendViber requires recipient argument');
}
if (!content) {
throw new Error('NotificationService.sendViber requires content argument');
}
const message = {
recipient: recipient,
message: {
type: type,
content: Buffer.from(content).toString('base64'),
},
channel: 'viber',
className: '$NotificationMessage',
boName: '$NotificationMessage',
objectTableName: '$NotificationMessage'
};
const ps = dms_root_container_1.RootDIContainer.inject(syncpacket_service_1.SyncPacketService);
ps.start();
ps.addEntity(message);
yield ps.post();
});
}
sendDevicePush(recipient, type, content) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (!recipient) {
throw new Error('NotificationService.sendDevicePush requires recipient argument');
}
const types = ['custommessage', 'sync', 'wipeout'];
if (types.indexOf(type) < 0) {
throw new Error(`${types.join(',')}`);
}
if (!content) {
throw new Error('NotificationService.sendDevicePush requires content argument');
}
if (content.length > 1000) {
throw new Error('NotificationService.sendDevicePush requires content with length below 1000');
}
const message = {
recipient: recipient,
message: {
type: type,
content: Buffer.from(content).toString('base64'),
},
channel: 'push',
className: '$NotificationMessage',
boName: '$NotificationMessage',
objectTableName: '$NotificationMessage'
};
const ps = dms_root_container_1.RootDIContainer.inject(syncpacket_service_1.SyncPacketService);
ps.start();
ps.addEntity(message);
yield ps.post();
});
}
sendWhatsApp(appCode, recipient, type, content) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (!appCode) {
throw new Error('NotificationService.sendWhatsApp requires appCode argument');
}
if (!recipient) {
throw new Error('NotificationService.sendWhatsApp requires recipient argument');
}
if (!content) {
throw new Error('NotificationService.sendWhatsApp requires content argument');
}
const message = {
recipient: recipient,
message: {
type: type,
content: Buffer.from(typeof (content) == 'object' ? JSON.stringify(content) : content).toString('base64'),
},
channel: 'whatsapp',
className: '$NotificationMessage',
boName: '$NotificationMessage',
objectTableName: '$NotificationMessage'
};
const ps = dms_root_container_1.RootDIContainer.inject(syncpacket_service_1.SyncPacketService);
ps.start();
ps.addEntity(message);
yield ps.post();
});
}
sendMessenger(appCode, recipient, type, content) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (!appCode) {
throw new Error('NotificationService.sendMessenger requires appCode argument');
}
if (!recipient) {
throw new Error('NotificationService.sendMessenger requires recipient argument');
}
if (!content) {
throw new Error('NotificationService.sendMessenger requires content argument');
}
const message = {
recipient: recipient,
message: {
type: type,
content: Buffer.from(content).toString('base64'),
},
channel: 'sendMessenger',
className: '$NotificationMessage',
boName: '$NotificationMessage',
objectTableName: '$NotificationMessage'
};
const ps = dms_root_container_1.RootDIContainer.inject(syncpacket_service_1.SyncPacketService);
ps.start();
ps.addEntity(message);
yield ps.post();
});
}
};
exports.MobileNotificationService = MobileNotificationService = tslib_1.__decorate([
(0, injectable_1.Injectable)()
], MobileNotificationService);
//# sourceMappingURL=mobile-notification-service.js.map