84a1a2aa3022e458ee6dcb93589efe995ec69ee8
[motion2.git] / server / api / chatProactiveAction / chatProactiveAction.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 _0x0f3c=['../../config/license/hardware','api','../../config/utils','../../config/environment','../../mysqldb','status','end','json','offset','undefined','count','limit','set','apply','save','update','then','destroy','sendStatus','error','stack','name','send','show','keys','ChatProactiveAction','query','filters','intersection','model','attributes','fields','length','includeAll','catch','create','body','find','params','eml-format','rimraf','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch'];(function(_0x363dee,_0x4d1a44){var _0x31ae44=function(_0x1a3727){while(--_0x1a3727){_0x363dee['push'](_0x363dee['shift']());}};_0x31ae44(++_0x4d1a44);}(_0x0f3c,0x189));var _0xc0f3=function(_0x3e1647,_0x136dfd){_0x3e1647=_0x3e1647-0x0;var _0x1864ce=_0x0f3c[_0x3e1647];return _0x1864ce;};'use strict';var emlformat=require(_0xc0f3('0x0'));var rimraf=require(_0xc0f3('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0xc0f3('0x2'));var BPromise=require(_0xc0f3('0x3'));var Mustache=require(_0xc0f3('0x4'));var util=require(_0xc0f3('0x5'));var path=require(_0xc0f3('0x6'));var sox=require(_0xc0f3('0x7'));var csv=require(_0xc0f3('0x8'));var ejs=require(_0xc0f3('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xc0f3('0xa'));var squel=require(_0xc0f3('0xb'));var crypto=require('crypto');var jsforce=require(_0xc0f3('0xc'));var deskjs=require(_0xc0f3('0xd'));var toCsv=require('to-csv');var querystring=require(_0xc0f3('0xe'));var Papa=require(_0xc0f3('0xf'));var Redis=require(_0xc0f3('0x10'));var authService=require(_0xc0f3('0x11'));var qs=require(_0xc0f3('0x12'));var as=require(_0xc0f3('0x13'));var hardwareService=require(_0xc0f3('0x14'));var logger=require('../../config/logger')(_0xc0f3('0x15'));var utils=require(_0xc0f3('0x16'));var config=require(_0xc0f3('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0xc0f3('0x18'))['db'];function respondWithStatusCode(_0x2391fd,_0x2fcea0){_0x2fcea0=_0x2fcea0||0xcc;return function(_0x125e58){if(_0x125e58){return _0x2391fd['sendStatus'](_0x2fcea0);}return _0x2391fd[_0xc0f3('0x19')](_0x2fcea0)[_0xc0f3('0x1a')]();};}function respondWithResult(_0x2e7998,_0x597ebf){_0x597ebf=_0x597ebf||0xc8;return function(_0x37cad7){if(_0x37cad7){return _0x2e7998[_0xc0f3('0x19')](_0x597ebf)[_0xc0f3('0x1b')](_0x37cad7);}};}function respondWithFilteredResult(_0x135685,_0x63efe4){return function(_0x215aed){if(_0x215aed){var _0x4640ec=typeof _0x63efe4[_0xc0f3('0x1c')]===_0xc0f3('0x1d')&&typeof _0x63efe4['limit']===_0xc0f3('0x1d');var _0x1490c0=_0x215aed[_0xc0f3('0x1e')];var _0x2b2e84=_0x4640ec?0x0:_0x63efe4[_0xc0f3('0x1c')];var _0x504133=_0x4640ec?_0x215aed[_0xc0f3('0x1e')]:_0x63efe4[_0xc0f3('0x1c')]+_0x63efe4[_0xc0f3('0x1f')];var _0x2ecdde;if(_0x504133>=_0x1490c0){_0x504133=_0x1490c0;_0x2ecdde=0xc8;}else{_0x2ecdde=0xce;}_0x135685[_0xc0f3('0x19')](_0x2ecdde);return _0x135685[_0xc0f3('0x20')]('Content-Range',_0x2b2e84+'-'+_0x504133+'/'+_0x1490c0)[_0xc0f3('0x1b')](_0x215aed);}return null;};}function patchUpdates(_0x4c0550){return function(_0x345571){try{jsonpatch[_0xc0f3('0x21')](_0x345571,_0x4c0550,!![]);}catch(_0x3799c7){return BPromise['reject'](_0x3799c7);}return _0x345571[_0xc0f3('0x22')]();};}function saveUpdates(_0x9fdc14,_0x4a0757){return function(_0x3bea3e){if(_0x3bea3e){return _0x3bea3e[_0xc0f3('0x23')](_0x9fdc14)[_0xc0f3('0x24')](function(_0x4f36eb){return _0x4f36eb;});}return null;};}function removeEntity(_0x58f2b2,_0xf5e0ac){return function(_0x53ffff){if(_0x53ffff){return _0x53ffff[_0xc0f3('0x25')]()[_0xc0f3('0x24')](function(){_0x58f2b2[_0xc0f3('0x19')](0xcc)[_0xc0f3('0x1a')]();});}};}function handleEntityNotFound(_0x1f1ad3,_0x2484e7){return function(_0x22beeb){if(!_0x22beeb){_0x1f1ad3[_0xc0f3('0x26')](0x194);}return _0x22beeb;};}function handleError(_0x3391b1,_0x16c8e5){_0x16c8e5=_0x16c8e5||0x1f4;return function(_0x5436b){logger[_0xc0f3('0x27')](_0x5436b[_0xc0f3('0x28')]);if(_0x5436b[_0xc0f3('0x29')]){delete _0x5436b[_0xc0f3('0x29')];}_0x3391b1['status'](_0x16c8e5)[_0xc0f3('0x2a')](_0x5436b);};}exports[_0xc0f3('0x2b')]=function(_0x1a6f94,_0x4f2e88){var _0x358eca={'raw':!![],'where':{'id':_0x1a6f94['params']['id']}},_0x493eb7={};_0x493eb7['model']=_[_0xc0f3('0x2c')](db[_0xc0f3('0x2d')]['rawAttributes']);_0x493eb7['query']=_[_0xc0f3('0x2c')](_0x1a6f94[_0xc0f3('0x2e')]);_0x493eb7[_0xc0f3('0x2f')]=_[_0xc0f3('0x30')](_0x493eb7[_0xc0f3('0x31')],_0x493eb7['query']);_0x358eca[_0xc0f3('0x32')]=_[_0xc0f3('0x30')](_0x493eb7['model'],qs[_0xc0f3('0x33')](_0x1a6f94[_0xc0f3('0x2e')]['fields']));_0x358eca[_0xc0f3('0x32')]=_0x358eca[_0xc0f3('0x32')][_0xc0f3('0x34')]?_0x358eca[_0xc0f3('0x32')]:_0x493eb7[_0xc0f3('0x31')];if(_0x1a6f94[_0xc0f3('0x2e')][_0xc0f3('0x35')]){_0x358eca['include']=[{'all':!![]}];}_0x358eca=_['merge']({},_0x358eca,_0x1a6f94['options']);return db[_0xc0f3('0x2d')]['find'](_0x358eca)[_0xc0f3('0x24')](handleEntityNotFound(_0x4f2e88,null))[_0xc0f3('0x24')](respondWithResult(_0x4f2e88,null))[_0xc0f3('0x36')](handleError(_0x4f2e88,null));};exports[_0xc0f3('0x37')]=function(_0x1d0bae,_0x1ee1d3){return db['ChatProactiveAction'][_0xc0f3('0x37')](_0x1d0bae[_0xc0f3('0x38')],{})[_0xc0f3('0x24')](respondWithResult(_0x1ee1d3,0xc9))['catch'](handleError(_0x1ee1d3,null));};exports[_0xc0f3('0x23')]=function(_0x523974,_0x155f55){if(_0x523974[_0xc0f3('0x38')]['id']){delete _0x523974['body']['id'];}return db[_0xc0f3('0x2d')][_0xc0f3('0x39')]({'where':{'id':_0x523974[_0xc0f3('0x3a')]['id']}})[_0xc0f3('0x24')](handleEntityNotFound(_0x155f55,null))[_0xc0f3('0x24')](saveUpdates(_0x523974[_0xc0f3('0x38')],null))[_0xc0f3('0x24')](respondWithResult(_0x155f55,null))[_0xc0f3('0x36')](handleError(_0x155f55,null));};exports[_0xc0f3('0x25')]=function(_0x2fbbac,_0x46bb46){return db[_0xc0f3('0x2d')][_0xc0f3('0x39')]({'where':{'id':_0x2fbbac['params']['id']}})[_0xc0f3('0x24')](handleEntityNotFound(_0x46bb46,null))['then'](removeEntity(_0x46bb46,null))[_0xc0f3('0x36')](handleError(_0x46bb46,null));};