Built motion from commit (unavailable).|2.5.21
[motion2.git] / server / api / notification / notification.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xf390=['hasOwnProperty','TemplateId','Sequelize','ValidationError','Must\x20specify\x20at\x20least\x20one\x20argument\x20for\x20\x27text\x27\x20or\x20\x27TemplateId\x27','view','Missing\x20\x27view\x27\x20parameter','recipients','parse','Invalid\x20\x27recipients\x27\x20object','chatqueue','faxqueue','mailqueue','openchannelqueue','smsqueue','team','model','toLowerCase','Invalid\x20model\x20in\x20\x27recipients\x27\x20object','senderName','user','fullname','recipientsDescription','isEmpty','beep','sortBy','join','sequelize','create','forEach','recipient','emit','notification:send','catch','text','Template','findOne','html','render','startCase','User','ids','includes','queue','replace','Queue','all','flatten','map','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','defaults','redis','socket.io-emitter','./notification.socket','register','sendStatus','status','json','set','apply','reject','save','update','then','destroy','end','stack','name','send','sendNotification','body'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0xf390,0x148));var _0x0f39=function(_0x11143b,_0x4b8a2c){_0x11143b=_0x11143b-0x0;var _0x5028a6=_0xf390[_0x11143b];return _0x5028a6;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0x0f39('0x0'));var jsonpatch=require(_0x0f39('0x1'));var rp=require(_0x0f39('0x2'));var moment=require('moment');var BPromise=require(_0x0f39('0x3'));var Mustache=require(_0x0f39('0x4'));var util=require(_0x0f39('0x5'));var path=require(_0x0f39('0x6'));var sox=require(_0x0f39('0x7'));var csv=require(_0x0f39('0x8'));var ejs=require(_0x0f39('0x9'));var fs=require('fs');var _=require(_0x0f39('0xa'));var squel=require(_0x0f39('0xb'));var crypto=require(_0x0f39('0xc'));var jsforce=require('jsforce');var deskjs=require(_0x0f39('0xd'));var toCsv=require(_0x0f39('0x8'));var querystring=require(_0x0f39('0xe'));var Papa=require('papaparse');var Redis=require(_0x0f39('0xf'));var authService=require(_0x0f39('0x10'));var qs=require('../../components/parsers/qs');var as=require(_0x0f39('0x11'));var hardwareService=require(_0x0f39('0x12'));var logger=require('../../config/logger')('api');var utils=require(_0x0f39('0x13'));var config=require(_0x0f39('0x14'));var licenseUtil=require(_0x0f39('0x15'));var db=require(_0x0f39('0x16'))['db'];config['redis']=_[_0x0f39('0x17')](config[_0x0f39('0x18')],{'host':'localhost','port':0x18eb});var socket=require(_0x0f39('0x19'))(new Redis(config[_0x0f39('0x18')]));require(_0x0f39('0x1a'))[_0x0f39('0x1b')](socket);function respondWithStatusCode(_0x4943ba,_0x53db4d){_0x53db4d=_0x53db4d||0xcc;return function(_0x40a7d9){if(_0x40a7d9){return _0x4943ba[_0x0f39('0x1c')](_0x53db4d);}return _0x4943ba[_0x0f39('0x1d')](_0x53db4d)['end']();};}function respondWithResult(_0x36528a,_0x33101c){_0x33101c=_0x33101c||0xc8;return function(_0x4f67ac){if(_0x4f67ac){return _0x36528a[_0x0f39('0x1d')](_0x33101c)[_0x0f39('0x1e')](_0x4f67ac);}};}function respondWithFilteredResult(_0x388cd1,_0x551031){return function(_0x402dbb){if(_0x402dbb){var _0x131e01=_0x402dbb['count'],_0x14c76d=_0x551031['offset'],_0x570450=_0x551031['offset']+_0x551031['limit'],_0x552a14;if(_0x570450>=_0x131e01){_0x570450=_0x131e01;_0x552a14=0xc8;}else{_0x552a14=0xce;}_0x388cd1[_0x0f39('0x1d')](_0x552a14);return _0x388cd1[_0x0f39('0x1f')]('Content-Range',_0x14c76d+'-'+_0x570450+'/'+_0x131e01)[_0x0f39('0x1e')](_0x402dbb);}return null;};}function patchUpdates(_0x4c3bee){return function(_0x48dc84){try{jsonpatch[_0x0f39('0x20')](_0x48dc84,_0x4c3bee,!![]);}catch(_0x33dd1c){return BPromise[_0x0f39('0x21')](_0x33dd1c);}return _0x48dc84[_0x0f39('0x22')]();};}function saveUpdates(_0x588201,_0x226737){return function(_0x341d81){if(_0x341d81){return _0x341d81[_0x0f39('0x23')](_0x588201)[_0x0f39('0x24')](function(_0x2c8e80){return _0x2c8e80;});}return null;};}function removeEntity(_0x595f43,_0x2209c0){return function(_0x501715){if(_0x501715){return _0x501715[_0x0f39('0x25')]()[_0x0f39('0x24')](function(){_0x595f43[_0x0f39('0x1d')](0xcc)[_0x0f39('0x26')]();});}};}function handleEntityNotFound(_0x36cf5d,_0x396a41){return function(_0x597033){if(!_0x597033){_0x36cf5d[_0x0f39('0x1c')](0x194);}return _0x597033;};}function handleError(_0x57951e,_0x39e4af){_0x39e4af=_0x39e4af||0x1f4;return function(_0x25b415){logger['error'](_0x25b415[_0x0f39('0x27')]);if(_0x25b415['name']){delete _0x25b415[_0x0f39('0x28')];}_0x57951e['status'](_0x39e4af)[_0x0f39('0x29')](_0x25b415);};}exports[_0x0f39('0x2a')]=function(_0x16a292,_0x102a08,_0x2a9471){if(!_0x16a292[_0x0f39('0x2b')][_0x0f39('0x2c')]('text')&&!_0x16a292['body'][_0x0f39('0x2c')](_0x0f39('0x2d'))){throw new db[(_0x0f39('0x2e'))][(_0x0f39('0x2f'))](_0x0f39('0x30'));}else{if(_0x16a292[_0x0f39('0x2b')][_0x0f39('0x2c')](_0x0f39('0x2d'))&&!_0x16a292[_0x0f39('0x2b')][_0x0f39('0x2c')](_0x0f39('0x31'))){throw new db[(_0x0f39('0x2e'))]['ValidationError'](_0x0f39('0x32'));}if(!_0x16a292['body'][_0x0f39('0x2c')](_0x0f39('0x33'))){throw new db['Sequelize'][(_0x0f39('0x2f'))]('Missing\x20\x27recipients\x27\x20parameter');}else{try{var _0x489e25=JSON[_0x0f39('0x34')](_0x16a292[_0x0f39('0x2b')][_0x0f39('0x33')]);}catch(_0x4eb79d){logger['error'](_0x4eb79d);throw new db[(_0x0f39('0x2e'))][(_0x0f39('0x2f'))](_0x0f39('0x35'));}var _0x386972=[_0x0f39('0x36'),_0x0f39('0x37'),_0x0f39('0x38'),_0x0f39('0x39'),_0x0f39('0x3a'),'voicequeue','whatsappqueue',_0x0f39('0x3b'),'user'];if(_['some'](_0x489e25,function(_0x2105c2){return!_['includes'](_0x386972,_0x2105c2[_0x0f39('0x3c')][_0x0f39('0x3d')]());})){throw new db['Sequelize'][(_0x0f39('0x2f'))](_0x0f39('0x3e'));}}}var _0x32f3ee={};_0x32f3ee[_0x0f39('0x3f')]=_0x16a292[_0x0f39('0x2b')]['hasOwnProperty'](_0x0f39('0x3f'))?_0x16a292[_0x0f39('0x2b')][_0x0f39('0x3f')]:_0x16a292[_0x0f39('0x40')][_0x0f39('0x41')];_0x32f3ee[_0x0f39('0x42')]=_[_0x0f39('0x43')](_0x16a292[_0x0f39('0x2b')][_0x0f39('0x42')])?null:_0x16a292[_0x0f39('0x2b')]['recipientsDescription'];_0x32f3ee[_0x0f39('0x44')]=_0x16a292[_0x0f39('0x2b')][_0x0f39('0x44')]||![];_0x32f3ee['SenderId']=_0x16a292['user']['id'];return getContent(_0x16a292[_0x0f39('0x2b')])[_0x0f39('0x24')](function(_0x1042c0){_0x32f3ee[_0x0f39('0x2b')]=_0x1042c0;return getRecipients(_0x489e25);})[_0x0f39('0x24')](function(_0x562198){_0x32f3ee['recipientsId']=_[_0x0f39('0x45')](_0x562198)[_0x0f39('0x46')](',');return db[_0x0f39('0x47')]['transaction'](function(_0x5d7471){return db['Notification'][_0x0f39('0x48')](_0x32f3ee,{'raw':!![],'transaction':_0x5d7471})[_0x0f39('0x24')](function(_0x25059a){var _0x11d89b={'sender':_0x32f3ee[_0x0f39('0x3f')],'description':_0x32f3ee[_0x0f39('0x42')],'content':_0x32f3ee[_0x0f39('0x2b')],'beep':_0x32f3ee[_0x0f39('0x44')]};_0x562198[_0x0f39('0x49')](function(_0x473430){_0x11d89b[_0x0f39('0x4a')]=_0x473430;socket[_0x0f39('0x4b')](_0x0f39('0x4c'),_0x11d89b);});return _0x25059a;});});})[_0x0f39('0x24')](respondWithResult(_0x102a08,0xc9))[_0x0f39('0x4d')](handleError(_0x102a08,null));};function getContent(_0x31182f){return new BPromise(function(_0x22030b,_0x1f0d91){if(_0x31182f['text']){_0x22030b(_0x31182f[_0x0f39('0x4e')]);return;}return db[_0x0f39('0x4f')][_0x0f39('0x50')]({'attributes':[_0x0f39('0x51')],'where':{'id':_0x31182f[_0x0f39('0x2d')]},'raw':!![]})['then'](function(_0x4f31d9){if(!_0x4f31d9)throw new db[(_0x0f39('0x2e'))][(_0x0f39('0x2f'))]('Invalid\x20\x27TemplateId\x27\x20parameter');var _0x1ce602=Mustache[_0x0f39('0x52')](_0x4f31d9['html'],_0x31182f[_0x0f39('0x31')]);_0x22030b(_0x1ce602);})[_0x0f39('0x4d')](function(_0x3039a1){_0x1f0d91(_0x3039a1);});});}function getRecipients(_0xf07989){return new BPromise(function(_0xf3d9c,_0x2915d1){var _0x3eb36f=[];var _0x2b9e50=[];_0xf07989[_0x0f39('0x49')](function(_0x2e9e74){var _0x30e4d7=_[_0x0f39('0x53')](_0x2e9e74[_0x0f39('0x3c')]['toLowerCase']());if(_0x30e4d7===_0x0f39('0x54')){_0x3eb36f=_['union'](_0x3eb36f,_0x2e9e74[_0x0f39('0x55')]);}else{if(_[_0x0f39('0x56')](_0x30e4d7,_0x0f39('0x57')))_0x30e4d7=_0x30e4d7[_0x0f39('0x58')](_0x0f39('0x57'),_0x0f39('0x59'));_0x2e9e74[_0x0f39('0x55')][_0x0f39('0x49')](function(_0x58470f){_0x2b9e50['push'](getAgents(_0x30e4d7,_0x58470f));});}});return BPromise[_0x0f39('0x5a')](_0x2b9e50)[_0x0f39('0x24')](function(_0xd470c0){_0x3eb36f=_['union'](_0x3eb36f,_[_0x0f39('0x5b')](_0xd470c0));_0xf3d9c(_0x3eb36f);})[_0x0f39('0x4d')](function(_0x273288){_0x2915d1(_0x273288);});});}function getAgents(_0x1196a3,_0x1eb90b){return new BPromise(function(_0x4059d3,_0x48f457){return db[_0x1196a3]['findOne']({'where':{'id':_0x1eb90b}})[_0x0f39('0x24')](function(_0xc73ff9){return _0xc73ff9['getAgents']({'attributes':['id'],'raw':!![]})[_0x0f39('0x24')](function(_0x4672cd){var _0x36e88a=_[_0x0f39('0x5c')](_0x4672cd,'id');_0x4059d3(_0x36e88a);});})[_0x0f39('0x4d')](function(_0x597c93){_0x48f457(_0x597c93);});});}