6a65aded579b8ba9de8e4dcfe6d3ff8a598ce152
[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 _0x950a=['jsforce','desk.js','querystring','papaparse','ioredis','../../config/license/hardware','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','end','status','json','offset','limit','undefined','count','set','apply','save','update','then','destroy','error','stack','name','send','show','params','model','keys','ChatProactiveAction','rawAttributes','query','filters','intersection','fields','attributes','includeAll','options','find','catch','create','body','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','sox','to-csv','fs-extra','lodash'];(function(_0x14f009,_0x4d3a3c){var _0x3c9312=function(_0x46d7d7){while(--_0x46d7d7){_0x14f009['push'](_0x14f009['shift']());}};_0x3c9312(++_0x4d3a3c);}(_0x950a,0x111));var _0xa950=function(_0x16e53d,_0x56e133){_0x16e53d=_0x16e53d-0x0;var _0x3ec7dc=_0x950a[_0x16e53d];return _0x3ec7dc;};'use strict';var emlformat=require(_0xa950('0x0'));var rimraf=require(_0xa950('0x1'));var zipdir=require(_0xa950('0x2'));var jsonpatch=require(_0xa950('0x3'));var rp=require('request-promise');var moment=require(_0xa950('0x4'));var BPromise=require(_0xa950('0x5'));var Mustache=require(_0xa950('0x6'));var util=require(_0xa950('0x7'));var path=require('path');var sox=require(_0xa950('0x8'));var csv=require(_0xa950('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xa950('0xa'));var _=require(_0xa950('0xb'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0xa950('0xc'));var deskjs=require(_0xa950('0xd'));var toCsv=require(_0xa950('0x9'));var querystring=require(_0xa950('0xe'));var Papa=require(_0xa950('0xf'));var Redis=require(_0xa950('0x10'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xa950('0x11'));var logger=require('../../config/logger')(_0xa950('0x12'));var utils=require(_0xa950('0x13'));var config=require(_0xa950('0x14'));var licenseUtil=require('../../config/license/util');var db=require(_0xa950('0x15'))['db'];function respondWithStatusCode(_0x4f9c04,_0x10e64a){_0x10e64a=_0x10e64a||0xcc;return function(_0x439097){if(_0x439097){return _0x4f9c04[_0xa950('0x16')](_0x10e64a);}return _0x4f9c04['status'](_0x10e64a)[_0xa950('0x17')]();};}function respondWithResult(_0x2aed6a,_0x1c7adb){_0x1c7adb=_0x1c7adb||0xc8;return function(_0x4ba74f){if(_0x4ba74f){return _0x2aed6a[_0xa950('0x18')](_0x1c7adb)[_0xa950('0x19')](_0x4ba74f);}};}function respondWithFilteredResult(_0x425201,_0x5d5f4c){return function(_0x31b25b){if(_0x31b25b){var _0x46fca7=typeof _0x5d5f4c[_0xa950('0x1a')]==='undefined'&&typeof _0x5d5f4c[_0xa950('0x1b')]===_0xa950('0x1c');var _0x162586=_0x31b25b[_0xa950('0x1d')];var _0x16aabc=_0x46fca7?0x0:_0x5d5f4c[_0xa950('0x1a')];var _0x2b0e44=_0x46fca7?_0x31b25b[_0xa950('0x1d')]:_0x5d5f4c[_0xa950('0x1a')]+_0x5d5f4c[_0xa950('0x1b')];var _0x28fedf;if(_0x2b0e44>=_0x162586){_0x2b0e44=_0x162586;_0x28fedf=0xc8;}else{_0x28fedf=0xce;}_0x425201[_0xa950('0x18')](_0x28fedf);return _0x425201[_0xa950('0x1e')]('Content-Range',_0x16aabc+'-'+_0x2b0e44+'/'+_0x162586)[_0xa950('0x19')](_0x31b25b);}return null;};}function patchUpdates(_0x1a10fe){return function(_0x50abe1){try{jsonpatch[_0xa950('0x1f')](_0x50abe1,_0x1a10fe,!![]);}catch(_0x41c405){return BPromise['reject'](_0x41c405);}return _0x50abe1[_0xa950('0x20')]();};}function saveUpdates(_0x5ad191,_0x2eda79){return function(_0x14ada5){if(_0x14ada5){return _0x14ada5[_0xa950('0x21')](_0x5ad191)[_0xa950('0x22')](function(_0x5617cd){return _0x5617cd;});}return null;};}function removeEntity(_0x11b8af,_0x3f4633){return function(_0x31c135){if(_0x31c135){return _0x31c135[_0xa950('0x23')]()[_0xa950('0x22')](function(){_0x11b8af[_0xa950('0x18')](0xcc)[_0xa950('0x17')]();});}};}function handleEntityNotFound(_0x23cb20,_0x12dcb8){return function(_0xc4894b){if(!_0xc4894b){_0x23cb20[_0xa950('0x16')](0x194);}return _0xc4894b;};}function handleError(_0x26f366,_0x43f8c8){_0x43f8c8=_0x43f8c8||0x1f4;return function(_0x5d82d8){logger[_0xa950('0x24')](_0x5d82d8[_0xa950('0x25')]);if(_0x5d82d8[_0xa950('0x26')]){delete _0x5d82d8[_0xa950('0x26')];}_0x26f366[_0xa950('0x18')](_0x43f8c8)[_0xa950('0x27')](_0x5d82d8);};}exports[_0xa950('0x28')]=function(_0x52e133,_0x19ad7a){var _0x442a94={'raw':!![],'where':{'id':_0x52e133[_0xa950('0x29')]['id']}},_0x5e4c94={};_0x5e4c94[_0xa950('0x2a')]=_[_0xa950('0x2b')](db[_0xa950('0x2c')][_0xa950('0x2d')]);_0x5e4c94[_0xa950('0x2e')]=_[_0xa950('0x2b')](_0x52e133[_0xa950('0x2e')]);_0x5e4c94[_0xa950('0x2f')]=_[_0xa950('0x30')](_0x5e4c94['model'],_0x5e4c94[_0xa950('0x2e')]);_0x442a94['attributes']=_['intersection'](_0x5e4c94[_0xa950('0x2a')],qs['fields'](_0x52e133[_0xa950('0x2e')][_0xa950('0x31')]));_0x442a94[_0xa950('0x32')]=_0x442a94[_0xa950('0x32')]['length']?_0x442a94[_0xa950('0x32')]:_0x5e4c94['model'];if(_0x52e133[_0xa950('0x2e')][_0xa950('0x33')]){_0x442a94['include']=[{'all':!![]}];}_0x442a94=_['merge']({},_0x442a94,_0x52e133[_0xa950('0x34')]);return db[_0xa950('0x2c')][_0xa950('0x35')](_0x442a94)[_0xa950('0x22')](handleEntityNotFound(_0x19ad7a,null))[_0xa950('0x22')](respondWithResult(_0x19ad7a,null))[_0xa950('0x36')](handleError(_0x19ad7a,null));};exports['create']=function(_0x4b8e0d,_0x356258){return db['ChatProactiveAction'][_0xa950('0x37')](_0x4b8e0d[_0xa950('0x38')],{})[_0xa950('0x22')](respondWithResult(_0x356258,0xc9))[_0xa950('0x36')](handleError(_0x356258,null));};exports[_0xa950('0x21')]=function(_0xe3aeb,_0xd7f55d){if(_0xe3aeb[_0xa950('0x38')]['id']){delete _0xe3aeb[_0xa950('0x38')]['id'];}return db[_0xa950('0x2c')]['find']({'where':{'id':_0xe3aeb[_0xa950('0x29')]['id']}})['then'](handleEntityNotFound(_0xd7f55d,null))[_0xa950('0x22')](saveUpdates(_0xe3aeb[_0xa950('0x38')],null))['then'](respondWithResult(_0xd7f55d,null))['catch'](handleError(_0xd7f55d,null));};exports[_0xa950('0x23')]=function(_0x1d924b,_0x57e9cb){return db[_0xa950('0x2c')][_0xa950('0x35')]({'where':{'id':_0x1d924b['params']['id']}})[_0xa950('0x22')](handleEntityNotFound(_0x57e9cb,null))[_0xa950('0x22')](removeEntity(_0x57e9cb,null))[_0xa950('0x36')](handleError(_0x57e9cb,null));};