a786dbe402c05970d7fac8574f4963c21a3257f9
[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 _0xe002=['merge','options','find','catch','create','body','params','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','status','end','json','offset','undefined','limit','count','apply','save','update','then','destroy','sendStatus','error','stack','name','show','model','keys','ChatProactiveAction','query','filters','intersection','attributes','fields','length','include'];(function(_0x321bb2,_0x202794){var _0x9c12ed=function(_0x263dd3){while(--_0x263dd3){_0x321bb2['push'](_0x321bb2['shift']());}};_0x9c12ed(++_0x202794);}(_0xe002,0xf7));var _0x2e00=function(_0x4b7e4d,_0x82d2ab){_0x4b7e4d=_0x4b7e4d-0x0;var _0x38d6af=_0xe002[_0x4b7e4d];return _0x38d6af;};'use strict';var emlformat=require(_0x2e00('0x0'));var rimraf=require(_0x2e00('0x1'));var zipdir=require(_0x2e00('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x2e00('0x3'));var moment=require(_0x2e00('0x4'));var BPromise=require(_0x2e00('0x5'));var Mustache=require('mustache');var util=require(_0x2e00('0x6'));var path=require(_0x2e00('0x7'));var sox=require(_0x2e00('0x8'));var csv=require(_0x2e00('0x9'));var ejs=require(_0x2e00('0xa'));var fs=require('fs');var fs_extra=require(_0x2e00('0xb'));var _=require(_0x2e00('0xc'));var squel=require(_0x2e00('0xd'));var crypto=require('crypto');var jsforce=require(_0x2e00('0xe'));var deskjs=require(_0x2e00('0xf'));var toCsv=require('to-csv');var querystring=require(_0x2e00('0x10'));var Papa=require(_0x2e00('0x11'));var Redis=require(_0x2e00('0x12'));var authService=require(_0x2e00('0x13'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x2e00('0x14'));var logger=require(_0x2e00('0x15'))(_0x2e00('0x16'));var utils=require('../../config/utils');var config=require(_0x2e00('0x17'));var licenseUtil=require(_0x2e00('0x18'));var db=require(_0x2e00('0x19'))['db'];function respondWithStatusCode(_0x40e6d1,_0x34cb45){_0x34cb45=_0x34cb45||0xcc;return function(_0x4ec979){if(_0x4ec979){return _0x40e6d1['sendStatus'](_0x34cb45);}return _0x40e6d1[_0x2e00('0x1a')](_0x34cb45)[_0x2e00('0x1b')]();};}function respondWithResult(_0x23796c,_0x24c603){_0x24c603=_0x24c603||0xc8;return function(_0x13e130){if(_0x13e130){return _0x23796c['status'](_0x24c603)[_0x2e00('0x1c')](_0x13e130);}};}function respondWithFilteredResult(_0x53a6fa,_0x1d805a){return function(_0x1247f9){if(_0x1247f9){var _0x554dd4=typeof _0x1d805a[_0x2e00('0x1d')]===_0x2e00('0x1e')&&typeof _0x1d805a[_0x2e00('0x1f')]===_0x2e00('0x1e');var _0x4be341=_0x1247f9[_0x2e00('0x20')];var _0x3d5593=_0x554dd4?0x0:_0x1d805a['offset'];var _0xa19ca1=_0x554dd4?_0x1247f9[_0x2e00('0x20')]:_0x1d805a[_0x2e00('0x1d')]+_0x1d805a['limit'];var _0x280804;if(_0xa19ca1>=_0x4be341){_0xa19ca1=_0x4be341;_0x280804=0xc8;}else{_0x280804=0xce;}_0x53a6fa[_0x2e00('0x1a')](_0x280804);return _0x53a6fa['set']('Content-Range',_0x3d5593+'-'+_0xa19ca1+'/'+_0x4be341)['json'](_0x1247f9);}return null;};}function patchUpdates(_0x5c022f){return function(_0x2a2bf3){try{jsonpatch[_0x2e00('0x21')](_0x2a2bf3,_0x5c022f,!![]);}catch(_0x2a10ad){return BPromise['reject'](_0x2a10ad);}return _0x2a2bf3[_0x2e00('0x22')]();};}function saveUpdates(_0x10b55b,_0x1b0cab){return function(_0x465af0){if(_0x465af0){return _0x465af0[_0x2e00('0x23')](_0x10b55b)[_0x2e00('0x24')](function(_0x415b6f){return _0x415b6f;});}return null;};}function removeEntity(_0xac65da,_0x7c262f){return function(_0x172967){if(_0x172967){return _0x172967[_0x2e00('0x25')]()[_0x2e00('0x24')](function(){_0xac65da[_0x2e00('0x1a')](0xcc)[_0x2e00('0x1b')]();});}};}function handleEntityNotFound(_0x36d576,_0x811a65){return function(_0x550ecb){if(!_0x550ecb){_0x36d576[_0x2e00('0x26')](0x194);}return _0x550ecb;};}function handleError(_0x102faa,_0xe8ee4){_0xe8ee4=_0xe8ee4||0x1f4;return function(_0x497b2d){logger[_0x2e00('0x27')](_0x497b2d[_0x2e00('0x28')]);if(_0x497b2d[_0x2e00('0x29')]){delete _0x497b2d[_0x2e00('0x29')];}_0x102faa[_0x2e00('0x1a')](_0xe8ee4)['send'](_0x497b2d);};}exports[_0x2e00('0x2a')]=function(_0x5a75ad,_0x133967){var _0x4842c5={'raw':!![],'where':{'id':_0x5a75ad['params']['id']}},_0x388d82={};_0x388d82[_0x2e00('0x2b')]=_[_0x2e00('0x2c')](db[_0x2e00('0x2d')]['rawAttributes']);_0x388d82[_0x2e00('0x2e')]=_[_0x2e00('0x2c')](_0x5a75ad[_0x2e00('0x2e')]);_0x388d82[_0x2e00('0x2f')]=_[_0x2e00('0x30')](_0x388d82['model'],_0x388d82[_0x2e00('0x2e')]);_0x4842c5[_0x2e00('0x31')]=_[_0x2e00('0x30')](_0x388d82[_0x2e00('0x2b')],qs[_0x2e00('0x32')](_0x5a75ad[_0x2e00('0x2e')][_0x2e00('0x32')]));_0x4842c5[_0x2e00('0x31')]=_0x4842c5['attributes'][_0x2e00('0x33')]?_0x4842c5['attributes']:_0x388d82[_0x2e00('0x2b')];if(_0x5a75ad[_0x2e00('0x2e')]['includeAll']){_0x4842c5[_0x2e00('0x34')]=[{'all':!![]}];}_0x4842c5=_[_0x2e00('0x35')]({},_0x4842c5,_0x5a75ad[_0x2e00('0x36')]);return db[_0x2e00('0x2d')][_0x2e00('0x37')](_0x4842c5)['then'](handleEntityNotFound(_0x133967,null))[_0x2e00('0x24')](respondWithResult(_0x133967,null))[_0x2e00('0x38')](handleError(_0x133967,null));};exports[_0x2e00('0x39')]=function(_0x5754c9,_0x17e785){return db[_0x2e00('0x2d')][_0x2e00('0x39')](_0x5754c9[_0x2e00('0x3a')],{})[_0x2e00('0x24')](respondWithResult(_0x17e785,0xc9))[_0x2e00('0x38')](handleError(_0x17e785,null));};exports[_0x2e00('0x23')]=function(_0x59d1cc,_0x5de126){if(_0x59d1cc['body']['id']){delete _0x59d1cc['body']['id'];}return db[_0x2e00('0x2d')][_0x2e00('0x37')]({'where':{'id':_0x59d1cc[_0x2e00('0x3b')]['id']}})[_0x2e00('0x24')](handleEntityNotFound(_0x5de126,null))['then'](saveUpdates(_0x59d1cc[_0x2e00('0x3a')],null))[_0x2e00('0x24')](respondWithResult(_0x5de126,null))[_0x2e00('0x38')](handleError(_0x5de126,null));};exports[_0x2e00('0x25')]=function(_0x1269eb,_0x563517){return db[_0x2e00('0x2d')][_0x2e00('0x37')]({'where':{'id':_0x1269eb['params']['id']}})[_0x2e00('0x24')](handleEntityNotFound(_0x563517,null))['then'](removeEntity(_0x563517,null))['catch'](handleError(_0x563517,null));};