The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/app/livechat/server/sendMessageBySMS.js

52 lines
1.4 KiB

import { callbacks } from '../../callbacks';
import { settings } from '../../settings';
import { SMS } from '../../sms';
import { LivechatVisitors } from '../../models';
import { normalizeMessageAttachments } from '../../utils/server/functions/normalizeMessageAttachments';
callbacks.add('afterSaveMessage', function(message, room) {
// skips this callback if the message was edited
if (message.editedAt) {
return message;
}
if (!SMS.enabled) {
return message;
}
// only send the sms by SMS if it is a livechat room with SMS set to true
if (!(typeof room.t !== 'undefined' && room.t === 'l' && room.sms && room.v && room.v.token)) {
return message;
}
// if the message has a token, it was sent from the visitor, so ignore it
if (message.token) {
return message;
}
// if the message has a type means it is a special message (like the closing comment), so skips
if (message.t) {
return message;
}
if (message.file) {
message = normalizeMessageAttachments(message);
}
const SMSService = SMS.getService(settings.get('SMS_Service'));
if (!SMSService) {
return message;
}
const visitor = LivechatVisitors.getVisitorByToken(room.v.token);
if (!visitor || !visitor.phone || visitor.phone.length === 0) {
return message;
}
SMSService.send(room.sms.from, visitor.phone[0].phoneNumber, message.msg);
return message;
}, callbacks.priority.LOW, 'sendMessageBySms');