[mirotalksfu] - extend email notification 4 widget
هذا الالتزام موجود في:
@@ -64,7 +64,7 @@ dev dependencies: {
|
||||
* @license For commercial or closed source, contact us at license.mirotalk@gmail.com or purchase directly via CodeCanyon
|
||||
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
|
||||
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
|
||||
* @version 1.9.26
|
||||
* @version 1.9.27
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -172,6 +172,15 @@ const hostCfg = {
|
||||
presenters: config?.security?.host?.presenters,
|
||||
};
|
||||
|
||||
const widget = {
|
||||
enabled: config?.ui?.brand?.widget?.enabled,
|
||||
roomId: config?.ui?.brand?.widget?.roomId || 'support-room',
|
||||
alert: {
|
||||
enabled: config?.ui?.brand?.widget?.alert?.enabled,
|
||||
type: config?.ui?.brand?.widget?.alert?.type || 'email',
|
||||
},
|
||||
};
|
||||
|
||||
const restApi = {
|
||||
basePath: '/api/v1', // api endpoint path
|
||||
docs: host + '/api/v1/docs', // api docs
|
||||
@@ -1900,15 +1909,32 @@ function startServer() {
|
||||
}
|
||||
}
|
||||
|
||||
// SCENARIO: Notify when the first user join room and is awaiting assistance...
|
||||
if (room.getPeersCount() === 1) {
|
||||
nodemailer.sendEmailAlert('join', {
|
||||
room_id: room.id,
|
||||
peer_name: peer_name,
|
||||
domain: socket.handshake.headers.host.split(':')[0],
|
||||
os: os_name ? `${os_name} ${os_version}` : '',
|
||||
browser: browser_name ? `${browser_name} ${browser_version}` : '',
|
||||
}); // config.email.alert: true
|
||||
// Email body payload
|
||||
const emailPayload = {
|
||||
room_id: room.id,
|
||||
peer_name: peer_name,
|
||||
domain: socket.handshake.headers.host.split(':')[0],
|
||||
os: os_name ? `${os_name} ${os_version}` : '',
|
||||
browser: browser_name ? `${browser_name} ${browser_version}` : '',
|
||||
};
|
||||
|
||||
const firstJoin = room.getPeersCount() === 1;
|
||||
|
||||
// SCENARIO: Notify when the first user join room and is awaiting assistance
|
||||
if (firstJoin && !widget.alert.enabled) {
|
||||
nodemailer.sendEmailAlert('join', emailPayload);
|
||||
}
|
||||
|
||||
// SCENARIO: Notify when a user joins the widget room for expert assistance
|
||||
if (firstJoin && widget.enabled && widget.alert && widget.alert.enabled && widget.roomId === room.id) {
|
||||
switch (widget.alert.type) {
|
||||
case 'email':
|
||||
nodemailer.sendEmailAlert('widget', emailPayload);
|
||||
break;
|
||||
// case slack, discord, webhook, ...
|
||||
default:
|
||||
log.warn('Unknown alert type for widget', { type: widget.type });
|
||||
}
|
||||
}
|
||||
|
||||
// handle WebHook
|
||||
|
||||
@@ -1021,6 +1021,10 @@ module.exports = {
|
||||
poweredBy: process.env.WIDGET_SUPPORT_POWERED_BY || 'Powered by MiroTalk SFU',
|
||||
},
|
||||
},
|
||||
alert: {
|
||||
enabled: process.env.WIDGET_ALERT_ENABLED === 'true',
|
||||
type: process.env.WIDGET_ALERT_TYPE || 'email',
|
||||
},
|
||||
},
|
||||
|
||||
app: {
|
||||
|
||||
@@ -5,6 +5,8 @@ const config = require('../config');
|
||||
const Logger = require('../Logger');
|
||||
const log = new Logger('NodeMailer');
|
||||
|
||||
const APP_NAME = config.ui.brand.app.name || 'MiroTalk SFU';
|
||||
|
||||
// ####################################################
|
||||
// EMAIL CONFIG
|
||||
// ####################################################
|
||||
@@ -61,11 +63,14 @@ function sendEmailAlert(event, data) {
|
||||
subject = getJoinRoomSubject(data);
|
||||
body = getJoinRoomBody(data);
|
||||
break;
|
||||
case 'widget':
|
||||
subject = getWidgetRoomSubject(data);
|
||||
body = getWidgetRoomBody(data);
|
||||
break;
|
||||
case 'alert':
|
||||
subject = getAlertSubject(data);
|
||||
body = getAlertBody(data);
|
||||
break;
|
||||
//...
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -90,7 +95,7 @@ function sendEmail(subject, body) {
|
||||
|
||||
function getJoinRoomSubject(data) {
|
||||
const { room_id } = data;
|
||||
return `MiroTalk SFU - New user Join to Room ${room_id}`;
|
||||
return `${APP_NAME} - New user Join to Room ${room_id}`;
|
||||
}
|
||||
function getJoinRoomBody(data) {
|
||||
const { peer_name, room_id, domain, os, browser } = data;
|
||||
@@ -147,9 +152,26 @@ function getJoinRoomBody(data) {
|
||||
`;
|
||||
}
|
||||
|
||||
// ==========
|
||||
// Widget
|
||||
// ==========
|
||||
|
||||
function getWidgetRoomSubject(data) {
|
||||
const { room_id } = data;
|
||||
return `${APP_NAME} WIDGET - New user Wait for expert assistance in Room ${room_id}`;
|
||||
}
|
||||
|
||||
function getWidgetRoomBody(data) {
|
||||
return getJoinRoomBody(data);
|
||||
}
|
||||
|
||||
// ==========
|
||||
// Alert
|
||||
// ==========
|
||||
|
||||
function getAlertSubject(data) {
|
||||
const { subject } = data;
|
||||
return subject || 'MiroTalk SFU - Alert';
|
||||
return subject || `${APP_NAME} - Alert`;
|
||||
}
|
||||
|
||||
function getAlertBody(data) {
|
||||
|
||||
المرجع في مشكلة جديدة
حظر مستخدم