059654c1b5efcec1f156ddbdb8f93b89c7fcb8a0
[motion2.git] / server / api / openchannelAccount / openchannelAccount.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 _0x54f8=['rimraf','fast-json-patch','request-promise','bluebird','mustache','util','sox','to-csv','ejs','lodash','squel','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','redis','defaults','./openchannelAccount.socket','register','jayson/promise','client','http','test','request','then','info','OpenchannelAccount,\x20%s,\x20%s','request\x20sent','OpenchannelAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','sendStatus','status','end','count','offset','Content-Range','json','apply','save','update','destroy','get','OpenchannelAccounts','UserProfileResource','stack','name','send','index','mandatoryDispositionPause','OpenchannelAccount','model','keys','query','filters','attributes','intersection','fields','hasOwnProperty','nolimit','limit','sort','where','pick','filter','merge','map','type','key','VIRTUAL','findAll','rows','catch','show','params','rawAttributes','length','include','options','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','addDisposition','OpnechannelAccountId','Disposition','getDispositions','findOne','includeAll','removeDispositions','addAnswer','CannedAnswer','getAnswers','order','OpenchannelAccountId','removeAnswers','notify','openchannel','CmContact','describe','Sequelize','ValidationError','no\x20available\x20attributes','updatedAt','difference','createdAt','ListId','isNil','from','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','List','Contacts','DESC','OpenchannelApplication','Applications','list','applications','orderBy','priority','asc','account','contact','firstName','threadId','OpenchannelInteraction','externalUrl','ContactId','spread','lastName','messageId','interaction','created','push','*,*,*,*','AttachmentId','UserId','User','unshift','agent','waitForTheAssignedAgent','startRouting','Start','EventManager','addApplications','sequelize','transaction','findAndCountAll','getApplications','Owner','internal','Tag','Tags','color','tag','addAgents','ids','omit','userOpenchannelAccount:save','removeAgents','isArray','emit','userOpenchannelAccount:remove','getAgents','out','OpenchannelMessage','Messages','dataValues','html-pdf','eml-format'];(function(_0xefb907,_0xfd84a2){var _0x58dc03=function(_0x1231f8){while(--_0x1231f8){_0xefb907['push'](_0xefb907['shift']());}};_0x58dc03(++_0xfd84a2);}(_0x54f8,0xbb));var _0x854f=function(_0x492682,_0x3fabb3){_0x492682=_0x492682-0x0;var _0x3ed422=_0x54f8[_0x492682];return _0x3ed422;};'use strict';var pdf=require(_0x854f('0x0'));var emlformat=require(_0x854f('0x1'));var rimraf=require(_0x854f('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0x854f('0x3'));var rp=require(_0x854f('0x4'));var moment=require('moment');var BPromise=require(_0x854f('0x5'));var Mustache=require(_0x854f('0x6'));var util=require(_0x854f('0x7'));var path=require('path');var sox=require(_0x854f('0x8'));var csv=require(_0x854f('0x9'));var ejs=require(_0x854f('0xa'));var fs=require('fs');var _=require(_0x854f('0xb'));var squel=require(_0x854f('0xc'));var crypto=require('crypto');var jsforce=require(_0x854f('0xd'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x854f('0xe'));var Papa=require(_0x854f('0xf'));var Redis=require(_0x854f('0x10'));var authService=require(_0x854f('0x11'));var qs=require('../../components/parsers/qs');var hardwareService=require(_0x854f('0x12'));var logger=require(_0x854f('0x13'))(_0x854f('0x14'));var utils=require(_0x854f('0x15'));var config=require(_0x854f('0x16'));var db=require(_0x854f('0x17'))['db'];config[_0x854f('0x18')]=_[_0x854f('0x19')](config[_0x854f('0x18')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0x854f('0x1a'))[_0x854f('0x1b')](socket);var jayson=require(_0x854f('0x1c'));var client=jayson[_0x854f('0x1d')][_0x854f('0x1e')]({'port':0x232c});var client9002=jayson[_0x854f('0x1d')][_0x854f('0x1e')]({'port':0x232a});function checkPasswordPattern(_0x2de53f,_0x38e881,_0x2ca27c){if(_0x2ca27c){var _0x130020=new RegExp(/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[?!@#\$%\^&\*~\-_=+[{\]\}])(?=.{8,})/);if(_0x130020[_0x854f('0x1f')](_0x38e881)){return _0x2de53f;}else{throw new Error('The\x20password\x20must\x20be\x20at\x20least\x208\x20characters\x20long\x20and\x20have\x201\x20lowercase\x20character,\x201\x20uppercase\x20character,\x201\x20number\x20and\x201\x20special\x20character\x20~!@#$%^&-_=+[{]}.');}}else{return _0x2de53f;}}function respondWithRpcPromise(_0x2dad16,_0x5bb3d2,_0x3f2162,_0x51d10f){return new BPromise(function(_0x45182f,_0x49211a){var _0x1f8e4e=_0x51d10f||client;return _0x1f8e4e[_0x854f('0x20')](_0x2dad16,_0x3f2162)[_0x854f('0x21')](function(_0x4244bc){logger[_0x854f('0x22')](_0x854f('0x23'),_0x5bb3d2,_0x854f('0x24'));logger['debug'](_0x854f('0x25'),_0x5bb3d2,_0x854f('0x24'),JSON[_0x854f('0x26')](_0x4244bc));if(_0x4244bc[_0x854f('0x27')]){if(_0x4244bc[_0x854f('0x27')][_0x854f('0x28')]===0x1f4){logger[_0x854f('0x27')]('OpenchannelAccount,\x20%s,\x20%s',_0x5bb3d2,_0x4244bc[_0x854f('0x27')]['message']);return _0x49211a(_0x4244bc['error'][_0x854f('0x29')]);}logger['error'](_0x854f('0x23'),_0x5bb3d2,_0x4244bc[_0x854f('0x27')]['message']);return _0x45182f(_0x4244bc['error'][_0x854f('0x29')]);}else{logger['info'](_0x854f('0x23'),_0x5bb3d2,_0x854f('0x24'));_0x45182f(_0x4244bc['result']['message']);}})['catch'](function(_0x262fab){logger[_0x854f('0x27')](_0x854f('0x23'),_0x5bb3d2,_0x262fab);_0x49211a(_0x262fab);});});}function respondWithStatusCode(_0x18e07b,_0x2c78fe){_0x2c78fe=_0x2c78fe||0xcc;return function(_0x66d945){if(_0x66d945){return _0x18e07b[_0x854f('0x2a')](_0x2c78fe);}return _0x18e07b[_0x854f('0x2b')](_0x2c78fe)[_0x854f('0x2c')]();};}function respondWithResult(_0x389873,_0x3d0008){_0x3d0008=_0x3d0008||0xc8;return function(_0x39d7c8){if(_0x39d7c8){return _0x389873['status'](_0x3d0008)['json'](_0x39d7c8);}};}function respondWithFilteredResult(_0x5add4b,_0x3d5cce){return function(_0x1b71ee){if(_0x1b71ee){var _0x1053b3=_0x1b71ee[_0x854f('0x2d')],_0x312334=_0x3d5cce['offset'],_0x23f9e0=_0x3d5cce[_0x854f('0x2e')]+_0x3d5cce['limit'],_0x28aadd;if(_0x23f9e0>=_0x1053b3){_0x23f9e0=_0x1053b3;_0x28aadd=0xc8;}else{_0x28aadd=0xce;}_0x5add4b['status'](_0x28aadd);return _0x5add4b['set'](_0x854f('0x2f'),_0x312334+'-'+_0x23f9e0+'/'+_0x1053b3)[_0x854f('0x30')](_0x1b71ee);}return null;};}function patchUpdates(_0x8b637a){return function(_0x2ac739){try{jsonpatch[_0x854f('0x31')](_0x2ac739,_0x8b637a,!![]);}catch(_0x292a71){return BPromise['reject'](_0x292a71);}return _0x2ac739[_0x854f('0x32')]();};}function saveUpdates(_0x3a2aa9,_0xef2fb7){return function(_0x2cf58e){if(_0x2cf58e){return _0x2cf58e[_0x854f('0x33')](_0x3a2aa9)['then'](function(_0x3d7116){return _0x3d7116;});}return null;};}function removeEntity(_0x3c4652,_0x1f7215){return function(_0x5a3adc){if(_0x5a3adc){return _0x5a3adc[_0x854f('0x34')]()[_0x854f('0x21')](function(){var _0x31935a=_0x5a3adc[_0x854f('0x35')]({'plain':!![]});var _0x1366e7=_0x854f('0x36');return db[_0x854f('0x37')][_0x854f('0x34')]({'where':{'type':_0x1366e7,'resourceId':_0x31935a['id']}})['then'](function(){return _0x5a3adc;});})['then'](function(){_0x3c4652[_0x854f('0x2b')](0xcc)[_0x854f('0x2c')]();});}};}function handleEntityNotFound(_0x58a31d,_0xe469b0){return function(_0x410235){if(!_0x410235){_0x58a31d[_0x854f('0x2a')](0x194);}return _0x410235;};}function handleError(_0xc70c60,_0x3c1c1b){_0x3c1c1b=_0x3c1c1b||0x1f4;return function(_0x192864){logger[_0x854f('0x27')](_0x192864[_0x854f('0x38')]);if(_0x192864[_0x854f('0x39')]){delete _0x192864[_0x854f('0x39')];}_0xc70c60['status'](_0x3c1c1b)[_0x854f('0x3a')](_0x192864);};}exports[_0x854f('0x3b')]=function(_0x43586c,_0x53082c){var _0x48daca={'include':[{'model':db['Pause'],'as':_0x854f('0x3c')}]},_0x3fca69={},_0x4bdc42={'count':0x0,'rows':[]};var _0x2b8193=db[_0x854f('0x3d')]['rawAttributes'];_0x3fca69[_0x854f('0x3e')]=_[_0x854f('0x3f')](_0x2b8193);_0x3fca69[_0x854f('0x40')]=_[_0x854f('0x3f')](_0x43586c[_0x854f('0x40')]);_0x3fca69[_0x854f('0x41')]=_['intersection'](_0x3fca69[_0x854f('0x3e')],_0x3fca69['query']);_0x48daca[_0x854f('0x42')]=_[_0x854f('0x43')](_0x3fca69[_0x854f('0x3e')],qs[_0x854f('0x44')](_0x43586c[_0x854f('0x40')][_0x854f('0x44')]));_0x48daca[_0x854f('0x42')]=_0x48daca['attributes']['length']?_0x48daca[_0x854f('0x42')]:_0x3fca69[_0x854f('0x3e')];if(!_0x43586c['query'][_0x854f('0x45')](_0x854f('0x46'))){_0x48daca[_0x854f('0x47')]=qs[_0x854f('0x47')](_0x43586c[_0x854f('0x40')]['limit']);_0x48daca[_0x854f('0x2e')]=qs[_0x854f('0x2e')](_0x43586c['query'][_0x854f('0x2e')]);}_0x48daca['order']=qs[_0x854f('0x48')](_0x43586c[_0x854f('0x40')]['sort']);_0x48daca[_0x854f('0x49')]=qs[_0x854f('0x41')](_[_0x854f('0x4a')](_0x43586c[_0x854f('0x40')],_0x3fca69[_0x854f('0x41')]));if(_0x43586c['query'][_0x854f('0x4b')]){_0x48daca[_0x854f('0x49')]=_[_0x854f('0x4c')](_0x48daca[_0x854f('0x49')],{'$or':_[_0x854f('0x4d')](_0x2b8193,function(_0x79d26c){if(_0x79d26c[_0x854f('0x4e')][_0x854f('0x4f')]!==_0x854f('0x50')){var _0x257ec9={};_0x257ec9[_0x79d26c['field']]={'$like':'%'+_0x43586c['query']['filter']+'%'};return _0x257ec9;}})});}_0x48daca=_['merge']({},_0x48daca,_0x43586c['options']);var _0x48e2f9={'where':_0x48daca[_0x854f('0x49')]};return db[_0x854f('0x3d')][_0x854f('0x2d')](_0x48e2f9)['then'](function(_0x374f9c){_0x4bdc42[_0x854f('0x2d')]=_0x374f9c;if(_0x43586c['query']['includeAll']){_0x48daca['include']=[{'all':!![]}];}return db[_0x854f('0x3d')][_0x854f('0x51')](_0x48daca);})[_0x854f('0x21')](function(_0x3d69fc){_0x4bdc42[_0x854f('0x52')]=_0x3d69fc;return _0x4bdc42;})['then'](respondWithFilteredResult(_0x53082c,_0x48daca))[_0x854f('0x53')](handleError(_0x53082c,null));};exports[_0x854f('0x54')]=function(_0x331461,_0x4f40fb){var _0x4f2fb6={'raw':![],'where':{'id':_0x331461[_0x854f('0x55')]['id']},'include':[{'model':db['Pause'],'as':_0x854f('0x3c')}]},_0x1a5af1={};_0x1a5af1['model']=_[_0x854f('0x3f')](db[_0x854f('0x3d')][_0x854f('0x56')]);_0x1a5af1['query']=_[_0x854f('0x3f')](_0x331461[_0x854f('0x40')]);_0x1a5af1[_0x854f('0x41')]=_[_0x854f('0x43')](_0x1a5af1[_0x854f('0x3e')],_0x1a5af1[_0x854f('0x40')]);_0x4f2fb6['attributes']=_[_0x854f('0x43')](_0x1a5af1[_0x854f('0x3e')],qs[_0x854f('0x44')](_0x331461[_0x854f('0x40')]['fields']));_0x4f2fb6[_0x854f('0x42')]=_0x4f2fb6[_0x854f('0x42')][_0x854f('0x57')]?_0x4f2fb6[_0x854f('0x42')]:_0x1a5af1[_0x854f('0x3e')];if(_0x331461[_0x854f('0x40')]['includeAll']){_0x4f2fb6[_0x854f('0x58')]=[{'all':!![]}];}_0x4f2fb6=_[_0x854f('0x4c')]({},_0x4f2fb6,_0x331461[_0x854f('0x59')]);return db[_0x854f('0x3d')][_0x854f('0x5a')](_0x4f2fb6)[_0x854f('0x21')](handleEntityNotFound(_0x4f40fb,null))[_0x854f('0x21')](respondWithResult(_0x4f40fb,null))[_0x854f('0x53')](handleError(_0x4f40fb,null));};exports[_0x854f('0x5b')]=function(_0x597c22,_0x414251){return db[_0x854f('0x3d')][_0x854f('0x5b')](_0x597c22[_0x854f('0x5c')],{})[_0x854f('0x21')](function(_0x362e10){var _0x39128a=_0x597c22[_0x854f('0x5d')]['get']({'plain':!![]});if(!_0x39128a)throw new Error(_0x854f('0x5e'));if(_0x39128a[_0x854f('0x5f')]===_0x854f('0x5d')){var _0x812ada=_0x362e10[_0x854f('0x35')]({'plain':!![]});var _0x5d2cd6=_0x854f('0x36');return db[_0x854f('0x60')]['find']({'where':{'name':_0x5d2cd6,'userProfileId':_0x39128a[_0x854f('0x61')]},'raw':!![]})[_0x854f('0x21')](function(_0x2a11d6){if(_0x2a11d6&&_0x2a11d6[_0x854f('0x62')]===0x0){return db[_0x854f('0x37')][_0x854f('0x5b')]({'name':_0x812ada['name'],'resourceId':_0x812ada['id'],'type':_0x2a11d6[_0x854f('0x39')],'sectionId':_0x2a11d6['id']},{})[_0x854f('0x21')](function(){return _0x362e10;});}else{return _0x362e10;}})[_0x854f('0x53')](function(_0x4822c6){logger['error'](_0x854f('0x63'),_0x4822c6);throw _0x4822c6;});}return _0x362e10;})[_0x854f('0x21')](respondWithResult(_0x414251,0xc9))[_0x854f('0x53')](handleError(_0x414251,null));};exports['update']=function(_0x2d5664,_0x4f3605){if(_0x2d5664['body']['id']){delete _0x2d5664[_0x854f('0x5c')]['id'];}return db['OpenchannelAccount'][_0x854f('0x5a')]({'where':{'id':_0x2d5664[_0x854f('0x55')]['id']},'include':[{'model':db['Pause'],'as':_0x854f('0x3c')}]})[_0x854f('0x21')](handleEntityNotFound(_0x4f3605,null))[_0x854f('0x21')](saveUpdates(_0x2d5664['body'],null))[_0x854f('0x21')](respondWithResult(_0x4f3605,null))[_0x854f('0x53')](handleError(_0x4f3605,null));};exports[_0x854f('0x34')]=function(_0x3a2800,_0x415f57){return db[_0x854f('0x3d')]['find']({'where':{'id':_0x3a2800[_0x854f('0x55')]['id']}})['then'](handleEntityNotFound(_0x415f57,null))[_0x854f('0x21')](removeEntity(_0x415f57,null))[_0x854f('0x53')](handleError(_0x415f57,null));};exports['describe']=function(_0x4c557c,_0x1988bb){return db[_0x854f('0x3d')]['describe']()['then'](respondWithResult(_0x1988bb,null))[_0x854f('0x53')](handleError(_0x1988bb,null));};exports[_0x854f('0x64')]=function(_0xea8393,_0x2f02c2,_0x390e7d){if(_0xea8393['body']['id']){delete _0xea8393['body']['id'];}return db[_0x854f('0x3d')][_0x854f('0x5a')]({'where':{'id':_0xea8393[_0x854f('0x55')]['id']}})[_0x854f('0x21')](handleEntityNotFound(_0x2f02c2,null))[_0x854f('0x21')](function(_0x111b4f){if(_0x111b4f){_0xea8393['body'][_0x854f('0x65')]=_0x111b4f['id'];return db[_0x854f('0x66')][_0x854f('0x5b')](_0xea8393['body']);}})[_0x854f('0x21')](respondWithResult(_0x2f02c2,null))['catch'](handleError(_0x2f02c2,null));};exports[_0x854f('0x67')]=function(_0x349971,_0x499acd,_0x1f0617){var _0x210b90={'raw':![],'where':{}};var _0x40292c={};var _0x415cc1={'count':0x0,'rows':[]};return db[_0x854f('0x3d')][_0x854f('0x68')]({'where':{'id':_0x349971['params']['id']}})[_0x854f('0x21')](handleEntityNotFound(_0x499acd,null))[_0x854f('0x21')](function(_0x54a3d3){if(_0x54a3d3){_0x40292c[_0x854f('0x3e')]=_['keys'](db[_0x854f('0x66')]['rawAttributes']);_0x40292c[_0x854f('0x40')]=_['keys'](_0x349971['query']);_0x40292c[_0x854f('0x41')]=_[_0x854f('0x43')](_0x40292c[_0x854f('0x3e')],_0x40292c['query']);_0x210b90[_0x854f('0x42')]=_[_0x854f('0x43')](_0x40292c[_0x854f('0x3e')],qs[_0x854f('0x44')](_0x349971['query'][_0x854f('0x44')]));_0x210b90[_0x854f('0x42')]=_0x210b90[_0x854f('0x42')][_0x854f('0x57')]?_0x210b90['attributes']:_0x40292c[_0x854f('0x3e')];if(!_0x349971[_0x854f('0x40')][_0x854f('0x45')]('nolimit')){_0x210b90[_0x854f('0x47')]=qs[_0x854f('0x47')](_0x349971[_0x854f('0x40')]['limit']);_0x210b90['offset']=qs[_0x854f('0x2e')](_0x349971[_0x854f('0x40')][_0x854f('0x2e')]);}_0x210b90['order']=qs[_0x854f('0x48')](_0x349971[_0x854f('0x40')][_0x854f('0x48')]);_0x210b90[_0x854f('0x49')]=qs[_0x854f('0x41')](_[_0x854f('0x4a')](_0x349971['query'],_0x40292c[_0x854f('0x41')]));_0x210b90['where']['OpenchannelAccountId']=_0x54a3d3['id'];if(_0x349971[_0x854f('0x40')]['filter']){_0x210b90[_0x854f('0x49')]=_[_0x854f('0x4c')](_0x210b90[_0x854f('0x49')],{'$or':_[_0x854f('0x4d')](_0x210b90['attributes'],function(_0x19ef64){var _0x255b93={};_0x255b93[_0x19ef64]={'$like':'%'+_0x349971[_0x854f('0x40')][_0x854f('0x4b')]+'%'};return _0x255b93;})});}_0x210b90=_[_0x854f('0x4c')]({},_0x210b90,_0x349971['options']);return db[_0x854f('0x66')][_0x854f('0x2d')]({'where':_0x210b90[_0x854f('0x49')]})[_0x854f('0x21')](function(_0x37e9d7){_0x415cc1['count']=_0x37e9d7;if(_0x349971[_0x854f('0x40')][_0x854f('0x69')]){_0x210b90['include']=[{'all':!![]}];}return db[_0x854f('0x66')]['findAll'](_0x210b90);})[_0x854f('0x21')](function(_0x604e9d){_0x415cc1[_0x854f('0x52')]=_0x604e9d;return _0x415cc1;});}})[_0x854f('0x21')](respondWithFilteredResult(_0x499acd,_0x210b90))[_0x854f('0x53')](handleError(_0x499acd,null));};exports['removeDispositions']=function(_0x1c1bba,_0x15e297,_0x19e01b){return db['OpenchannelAccount'][_0x854f('0x5a')]({'where':{'id':_0x1c1bba['params']['id']}})[_0x854f('0x21')](handleEntityNotFound(_0x15e297,null))[_0x854f('0x21')](function(_0x33e6d2){if(_0x33e6d2){return _0x33e6d2[_0x854f('0x6a')](_0x1c1bba[_0x854f('0x40')]['ids']);}})[_0x854f('0x21')](respondWithStatusCode(_0x15e297,null))[_0x854f('0x53')](handleError(_0x15e297,null));};exports[_0x854f('0x6b')]=function(_0x36652c,_0x2ee678,_0x31d206){if(_0x36652c[_0x854f('0x5c')]['id']){delete _0x36652c[_0x854f('0x5c')]['id'];}return db[_0x854f('0x3d')][_0x854f('0x5a')]({'where':{'id':_0x36652c[_0x854f('0x55')]['id']}})[_0x854f('0x21')](handleEntityNotFound(_0x2ee678,null))['then'](function(_0x566415){if(_0x566415){_0x36652c[_0x854f('0x5c')]['OpenchannelAccountId']=_0x566415['id'];return db[_0x854f('0x6c')][_0x854f('0x5b')](_0x36652c[_0x854f('0x5c')]);}})[_0x854f('0x21')](respondWithResult(_0x2ee678,null))['catch'](handleError(_0x2ee678,null));};exports[_0x854f('0x6d')]=function(_0x456db6,_0x5ce4a2,_0x3da046){var _0x537d2d={'raw':![],'where':{}};var _0x17c611={};var _0x5cea8f={'count':0x0,'rows':[]};return db[_0x854f('0x3d')][_0x854f('0x68')]({'where':{'id':_0x456db6[_0x854f('0x55')]['id']}})[_0x854f('0x21')](handleEntityNotFound(_0x5ce4a2,null))[_0x854f('0x21')](function(_0x2a8855){if(_0x2a8855){_0x17c611['model']=_[_0x854f('0x3f')](db[_0x854f('0x6c')][_0x854f('0x56')]);_0x17c611[_0x854f('0x40')]=_['keys'](_0x456db6['query']);_0x17c611['filters']=_[_0x854f('0x43')](_0x17c611[_0x854f('0x3e')],_0x17c611['query']);_0x537d2d['attributes']=_[_0x854f('0x43')](_0x17c611[_0x854f('0x3e')],qs[_0x854f('0x44')](_0x456db6['query'][_0x854f('0x44')]));_0x537d2d[_0x854f('0x42')]=_0x537d2d['attributes']['length']?_0x537d2d['attributes']:_0x17c611['model'];if(!_0x456db6['query']['hasOwnProperty'](_0x854f('0x46'))){_0x537d2d[_0x854f('0x47')]=qs[_0x854f('0x47')](_0x456db6[_0x854f('0x40')][_0x854f('0x47')]);_0x537d2d['offset']=qs['offset'](_0x456db6['query'][_0x854f('0x2e')]);}_0x537d2d[_0x854f('0x6e')]=qs[_0x854f('0x48')](_0x456db6['query'][_0x854f('0x48')]);_0x537d2d['where']=qs[_0x854f('0x41')](_[_0x854f('0x4a')](_0x456db6[_0x854f('0x40')],_0x17c611['filters']));_0x537d2d[_0x854f('0x49')][_0x854f('0x6f')]=_0x2a8855['id'];if(_0x456db6[_0x854f('0x40')][_0x854f('0x4b')]){_0x537d2d[_0x854f('0x49')]=_[_0x854f('0x4c')](_0x537d2d[_0x854f('0x49')],{'$or':_['map'](_0x537d2d[_0x854f('0x42')],function(_0xdff73b){var _0x1007f1={};_0x1007f1[_0xdff73b]={'$like':'%'+_0x456db6[_0x854f('0x40')][_0x854f('0x4b')]+'%'};return _0x1007f1;})});}_0x537d2d=_['merge']({},_0x537d2d,_0x456db6[_0x854f('0x59')]);return db[_0x854f('0x6c')][_0x854f('0x2d')]({'where':_0x537d2d[_0x854f('0x49')]})[_0x854f('0x21')](function(_0x1df5a9){_0x5cea8f['count']=_0x1df5a9;if(_0x456db6[_0x854f('0x40')][_0x854f('0x69')]){_0x537d2d[_0x854f('0x58')]=[{'all':!![]}];}return db[_0x854f('0x6c')][_0x854f('0x51')](_0x537d2d);})['then'](function(_0x4cd678){_0x5cea8f[_0x854f('0x52')]=_0x4cd678;return _0x5cea8f;});}})[_0x854f('0x21')](respondWithFilteredResult(_0x5ce4a2,_0x537d2d))[_0x854f('0x53')](handleError(_0x5ce4a2,null));};exports[_0x854f('0x70')]=function(_0x223069,_0x132615,_0x371e0d){return db[_0x854f('0x3d')]['find']({'where':{'id':_0x223069['params']['id']}})[_0x854f('0x21')](handleEntityNotFound(_0x132615,null))[_0x854f('0x21')](function(_0x5561c1){if(_0x5561c1){return _0x5561c1['removeAnswers'](_0x223069['query']['ids']);}})[_0x854f('0x21')](respondWithStatusCode(_0x132615,null))[_0x854f('0x53')](handleError(_0x132615,null));};exports[_0x854f('0x71')]=function(_0x249da8,_0x48c91f,_0x2c1e3a){var _0x246058={'body':_0x249da8['body'],'channel':_0x854f('0x72')};var _0x5315e6=[];var _0x1ca7aa=[];var _0x3877fd={};var _0x516747=![];return db[_0x854f('0x73')][_0x854f('0x74')]()[_0x854f('0x21')](function(_0x171078){if(!_0x171078){throw new db[(_0x854f('0x75'))][(_0x854f('0x76'))](_0x854f('0x77'));}_0x5315e6=_['difference'](_['keys'](_0x171078),['createdAt',_0x854f('0x78')]);_0x1ca7aa=_[_0x854f('0x79')](_[_0x854f('0x3f')](_0x171078),[_0x854f('0x7a'),_0x854f('0x78'),'CompanyId',_0x854f('0x7b')]);if(_0x249da8[_0x854f('0x5c')]['id']){delete _0x249da8[_0x854f('0x5c')]['id'];}if(_[_0x854f('0x7c')](_0x249da8[_0x854f('0x5c')][_0x854f('0x7d')])){throw new db[(_0x854f('0x75'))][(_0x854f('0x76'))]('from\x20is\x20mandatory');}if(_[_0x854f('0x7c')](_0x249da8[_0x854f('0x5c')][_0x854f('0x5c')])||_0x249da8['body'][_0x854f('0x5c')]===''){throw new db[(_0x854f('0x75'))][(_0x854f('0x76'))](_0x854f('0x7e'));}if(_[_0x854f('0x7c')](_0x249da8[_0x854f('0x5c')][_0x854f('0x7f')])){throw new db[(_0x854f('0x75'))][(_0x854f('0x76'))](_0x854f('0x80')+_0x1ca7aa);}if(!_[_0x854f('0x81')](_0x1ca7aa,_0x249da8[_0x854f('0x5c')][_0x854f('0x7f')])){throw new db[(_0x854f('0x75'))]['ValidationError'](_0x854f('0x82')+_0x1ca7aa);}_0x3877fd[_0x249da8[_0x854f('0x5c')]['mapKey']]=_0x249da8[_0x854f('0x5c')][_0x854f('0x7d')];})[_0x854f('0x21')](function(){return db['OpenchannelAccount']['find']({'where':{'id':_0x249da8['params']['id']},'include':[{'model':db[_0x854f('0x83')],'as':_0x854f('0x84'),'include':[{'model':db['CmContact'],'as':_0x854f('0x85'),'where':_0x3877fd,'limit':0x1,'order':[[_0x854f('0x78'),_0x854f('0x86')]]}]},{'model':db[_0x854f('0x87')],'as':_0x854f('0x88')}]});})[_0x854f('0x21')](handleEntityNotFound(_0x48c91f,null))[_0x854f('0x21')](function(_0x36a2de){if(_0x36a2de&&_0x36a2de[_0x854f('0x84')]){_0x246058['account']=_0x36a2de;_0x246058['applications']=_0x36a2de[_0x854f('0x88')];_0x246058[_0x854f('0x89')]=_0x36a2de[_0x854f('0x84')];_0x246058[_0x854f('0x8a')]=_[_0x854f('0x8b')](_0x246058[_0x854f('0x8a')],[_0x854f('0x8c')],[_0x854f('0x8d')]);if(_0x246058[_0x854f('0x8e')]['Applications']){delete _0x246058[_0x854f('0x8e')][_0x854f('0x88')];}if(_0x246058['account'][_0x854f('0x84')]&&_0x246058['account'][_0x854f('0x84')][_0x854f('0x85')]['length']){return _0x246058[_0x854f('0x8e')][_0x854f('0x84')][_0x854f('0x85')][0x0];}var _0x408cd9=_[_0x854f('0x19')](_0x249da8[_0x854f('0x5c')],{'firstName':_0x249da8[_0x854f('0x5c')][_0x854f('0x7d')],'ListId':_0x36a2de['ListId']});_0x408cd9[_0x249da8[_0x854f('0x5c')]['mapKey']]=_0x249da8['body'][_0x854f('0x7d')];return db[_0x854f('0x73')]['create'](_0x408cd9,{'fields':_0x5315e6,'raw':!![]});}})[_0x854f('0x21')](handleEntityNotFound(_0x48c91f,null))[_0x854f('0x21')](function(_0x35cb85){_0x246058[_0x854f('0x8f')]=_0x35cb85;if(_0x35cb85){var _0x18ba71={'ContactId':_0x35cb85['id'],'OpenchannelAccountId':_0x249da8[_0x854f('0x55')]['id'],'from':(_0x35cb85[_0x854f('0x90')]||'')+'\x20'+(_0x35cb85['lastName']||'')};var _0x3b4992={'OpenchannelAccountId':_0x249da8['params']['id'],'closed':![]};if(_0x249da8[_0x854f('0x5c')][_0x854f('0x91')]){_0x3b4992['threadId']=_0x249da8[_0x854f('0x5c')]['threadId'];return db[_0x854f('0x92')][_0x854f('0x5a')]({'where':_0x3b4992})[_0x854f('0x21')](function(_0x1d5e6e){if(_0x1d5e6e){return[_0x1d5e6e,![]];}_0x18ba71[_0x854f('0x91')]=_0x249da8[_0x854f('0x5c')]['threadId'];_0x18ba71[_0x854f('0x93')]=_0x249da8['body'][_0x854f('0x93')];return db[_0x854f('0x92')]['create'](_0x18ba71)[_0x854f('0x21')](function(_0x4dad4c){return[_0x4dad4c,!![]];});});}else{_0x3b4992['threadId']=null;}_0x3b4992[_0x854f('0x94')]=_0x35cb85['id'];return db[_0x854f('0x92')][_0x854f('0x5a')]({'where':_0x3b4992})[_0x854f('0x21')](function(_0x88ecea){if(_0x88ecea){return[_0x88ecea,![]];}return db[_0x854f('0x92')][_0x854f('0x5b')](_0x18ba71)[_0x854f('0x21')](function(_0x4fe1af){return[_0x4fe1af,!![]];});});}})[_0x854f('0x95')](function(_0x359608,_0x5ed4e7){if(_0x359608){_0x516747=_0x5ed4e7;if(!_0x5ed4e7){var _0x424b1e={'from':(_0x246058[_0x854f('0x8f')][_0x854f('0x90')]||'')+'\x20'+(_0x246058['contact'][_0x854f('0x96')]||'')};if(_0x249da8[_0x854f('0x5c')][_0x854f('0x91')]&&_0x249da8[_0x854f('0x5c')]['messageId']&&_0x249da8['body'][_0x854f('0x91')]!=_0x249da8['body'][_0x854f('0x97')]){_0x424b1e[_0x854f('0x91')]=_0x249da8[_0x854f('0x5c')][_0x854f('0x97')];}return _0x359608['update'](_0x424b1e);}else{return _0x359608;}}})['then'](function(_0xcd618){_0x246058[_0x854f('0x98')]=_0xcd618['get']({'plain':!![]});_0x246058[_0x854f('0x98')][_0x854f('0x99')]=_0x516747;if(_0x246058[_0x854f('0x98')]['created']){if(_0x246058[_0x854f('0x8e')]['autoclose']){_0x246058['applications'][_0x854f('0x9a')]({'id':0x0,'priority':_0x246058[_0x854f('0x8a')][_0x854f('0x57')]+0x1,'app':'close','appdata':'unmanaged','interval':_0x854f('0x9b')});}}return db['OpenchannelMessage'][_0x854f('0x5b')]({'body':_0x249da8['body'][_0x854f('0x5c')],'OpenchannelAccountId':_0x249da8[_0x854f('0x55')]['id'],'OpenchannelInteractionId':_0xcd618['id'],'direction':'in','ContactId':_0x246058['contact']['id'],'AttachmentId':_0x249da8[_0x854f('0x5c')][_0x854f('0x9c')]});})[_0x854f('0x21')](function(_0xa47424){_0x246058[_0x854f('0x29')]=_0xa47424;if(_0x246058[_0x854f('0x98')][_0x854f('0x9d')]){return db[_0x854f('0x9e')][_0x854f('0x5a')]({'attributes':['id','name'],'where':{'id':_0x246058[_0x854f('0x98')]['UserId']}})[_0x854f('0x21')](function(_0x1713f8){if(_0x1713f8){_0x246058['applications'][_0x854f('0x9f')]({'id':0x0,'priority':0x0,'app':_0x854f('0xa0'),'appdata':_0x1713f8[_0x854f('0x39')]+','+(_0x246058[_0x854f('0x8e')][_0x854f('0xa1')]||0xa),'interval':_0x854f('0x9b')});_0x246058['forcedOwnership']=![];}return respondWithRpcPromise('Start',_0x854f('0xa2'),_0x246058);});}return respondWithRpcPromise(_0x854f('0xa3'),_0x854f('0xa2'),_0x246058);})[_0x854f('0x21')](function(_0x31e044){respondWithRpcPromise(_0x854f('0xa4'),_0x854f('0xa4'),{'event':'notify','message':_0x31e044},client9002);return _0x31e044;})[_0x854f('0x21')](respondWithResult(_0x48c91f,null))[_0x854f('0x53')](handleError(_0x48c91f,null));};exports[_0x854f('0xa5')]=function(_0x467117,_0x16442f,_0x2b21ad){return db[_0x854f('0x3d')][_0x854f('0x68')]({'where':{'id':_0x467117[_0x854f('0x55')]['id']}})[_0x854f('0x21')](handleEntityNotFound(_0x16442f,null))[_0x854f('0x21')](function(_0x1cf554){if(_0x1cf554){return db[_0x854f('0xa6')][_0x854f('0xa7')](function(_0x3491e4){return db[_0x854f('0x87')][_0x854f('0x34')]({'where':{'OpenchannelAccountId':_0x467117[_0x854f('0x55')]['id']},'transaction':_0x3491e4})[_0x854f('0x21')](function(_0x2b9923){var _0x1f3170=_[_0x854f('0x4d')](_0x467117[_0x854f('0x5c')],function(_0x551da5){_0x551da5[_0x854f('0x6f')]=_0x467117[_0x854f('0x55')]['id'];return _0x551da5;});return db[_0x854f('0x87')]['bulkCreate'](_0x1f3170,{'transaction':_0x3491e4});});})[_0x854f('0x21')](function(){return db[_0x854f('0x87')][_0x854f('0xa8')]({'where':{'OpenchannelAccountId':_0x467117[_0x854f('0x55')]['id']},'order':_0x854f('0x8c')});});}})[_0x854f('0x21')](respondWithResult(_0x16442f,null))[_0x854f('0x53')](handleError(_0x16442f,null));};exports['getApplications']=function(_0x1e4956,_0x4cd7d3,_0x3c2135){var _0x332e26={};var _0x556c43={};var _0x4e8af0;var _0x8d0c30;return db[_0x854f('0x3d')][_0x854f('0x68')]({'where':{'id':_0x1e4956['params']['id']}})[_0x854f('0x21')](handleEntityNotFound(_0x4cd7d3,null))[_0x854f('0x21')](function(_0x870091){if(_0x870091){_0x4e8af0=_0x870091;_0x556c43['model']=_['keys'](db['OpenchannelApplication'][_0x854f('0x56')]);_0x556c43['query']=_['keys'](_0x1e4956[_0x854f('0x40')]);_0x556c43[_0x854f('0x41')]=_[_0x854f('0x43')](_0x556c43[_0x854f('0x3e')],_0x556c43[_0x854f('0x40')]);_0x332e26[_0x854f('0x42')]=_['intersection'](_0x556c43['model'],qs[_0x854f('0x44')](_0x1e4956['query'][_0x854f('0x44')]));_0x332e26[_0x854f('0x42')]=_0x332e26[_0x854f('0x42')][_0x854f('0x57')]?_0x332e26['attributes']:_0x556c43[_0x854f('0x3e')];_0x332e26[_0x854f('0x6e')]=qs[_0x854f('0x48')](_0x1e4956['query'][_0x854f('0x48')]);_0x332e26['where']=qs['filters'](_[_0x854f('0x4a')](_0x1e4956[_0x854f('0x40')],_0x556c43[_0x854f('0x41')]));if(_0x1e4956[_0x854f('0x40')]['filter']){_0x332e26[_0x854f('0x49')]=_['merge'](_0x332e26[_0x854f('0x49')],{'$or':_[_0x854f('0x4d')](_0x332e26['attributes'],function(_0x3e1d35){var _0x2e497b={};_0x2e497b[_0x3e1d35]={'$like':'%'+_0x1e4956[_0x854f('0x40')]['filter']+'%'};return _0x2e497b;})});}_0x332e26=_[_0x854f('0x4c')]({},_0x332e26,_0x1e4956[_0x854f('0x59')]);return _0x4e8af0['getApplications'](_0x332e26);}})[_0x854f('0x21')](function(_0x1f8fe4){if(_0x1f8fe4){_0x8d0c30=_0x1f8fe4['length'];if(!_0x1e4956[_0x854f('0x40')][_0x854f('0x45')](_0x854f('0x46'))){_0x332e26[_0x854f('0x47')]=qs[_0x854f('0x47')](_0x1e4956[_0x854f('0x40')][_0x854f('0x47')]);_0x332e26[_0x854f('0x2e')]=qs[_0x854f('0x2e')](_0x1e4956[_0x854f('0x40')][_0x854f('0x2e')]);}return _0x4e8af0[_0x854f('0xa9')](_0x332e26);}})[_0x854f('0x21')](function(_0xd3bdb1){if(_0xd3bdb1){return _0xd3bdb1?{'count':_0x8d0c30,'rows':_0xd3bdb1}:null;}})['then'](respondWithResult(_0x4cd7d3,null))[_0x854f('0x53')](handleError(_0x4cd7d3,null));};exports['getInteractions']=function(_0x467930,_0x4330b5,_0x61f1e6){var _0xcbe41e={'raw':![],'where':{}};var _0xb10b91={};var _0x5a03b5={'count':0x0,'rows':[]};return db[_0x854f('0x3d')][_0x854f('0x68')]({'where':{'id':_0x467930[_0x854f('0x55')]['id']}})[_0x854f('0x21')](handleEntityNotFound(_0x4330b5,null))[_0x854f('0x21')](function(_0x14a887){if(_0x14a887){_0xb10b91['model']=_['keys'](db['OpenchannelInteraction']['rawAttributes']);_0xb10b91[_0x854f('0x40')]=_[_0x854f('0x3f')](_0x467930[_0x854f('0x40')]);_0xb10b91[_0x854f('0x41')]=_[_0x854f('0x43')](_0xb10b91['model'],_0xb10b91[_0x854f('0x40')]);_0xcbe41e[_0x854f('0x42')]=_[_0x854f('0x43')](_0xb10b91[_0x854f('0x3e')],qs[_0x854f('0x44')](_0x467930[_0x854f('0x40')][_0x854f('0x44')]));_0xcbe41e[_0x854f('0x42')]=_0xcbe41e[_0x854f('0x42')][_0x854f('0x57')]?_0xcbe41e[_0x854f('0x42')]:_0xb10b91[_0x854f('0x3e')];if(!_0x467930['query'][_0x854f('0x45')](_0x854f('0x46'))){_0xcbe41e[_0x854f('0x47')]=qs[_0x854f('0x47')](_0x467930[_0x854f('0x40')][_0x854f('0x47')]);_0xcbe41e[_0x854f('0x2e')]=qs[_0x854f('0x2e')](_0x467930['query'][_0x854f('0x2e')]);}_0xcbe41e['order']=qs[_0x854f('0x48')](_0x467930['query'][_0x854f('0x48')]);_0xcbe41e[_0x854f('0x49')]=qs[_0x854f('0x41')](_[_0x854f('0x4a')](_0x467930['query'],_0xb10b91['filters']));_0xcbe41e[_0x854f('0x49')][_0x854f('0x6f')]=_0x14a887['id'];if(_0x467930[_0x854f('0x40')][_0x854f('0x4b')]){_0xcbe41e[_0x854f('0x49')]=_['merge'](_0xcbe41e[_0x854f('0x49')],{'$or':_[_0x854f('0x4d')](_0xcbe41e['attributes'],function(_0x212b94){var _0x10cb68={};_0x10cb68[_0x212b94]={'$like':'%'+_0x467930['query'][_0x854f('0x4b')]+'%'};return _0x10cb68;})});}_0xcbe41e=_[_0x854f('0x4c')]({},_0xcbe41e,_0x467930[_0x854f('0x59')]);return db[_0x854f('0x92')][_0x854f('0x2d')]({'where':_0xcbe41e[_0x854f('0x49')]})[_0x854f('0x21')](function(_0x136c35){_0x5a03b5['count']=_0x136c35;if(_0x467930[_0x854f('0x40')][_0x854f('0x69')]){_0xcbe41e['include']=[{'model':db[_0x854f('0x73')],'as':'Contact','required':![]},{'model':db[_0x854f('0x9e')],'as':_0x854f('0xaa'),'attributes':['name','fullname',_0x854f('0xab')],'required':![]},{'model':db[_0x854f('0xac')],'as':_0x854f('0xad'),'attributes':['id','name',_0x854f('0xae')],'where':_0x467930['query']['tag']?{'id':_0x467930[_0x854f('0x40')]['tag']}:undefined,'required':_0x467930['query'][_0x854f('0xaf')]?!![]:![]}];}return db[_0x854f('0x92')]['findAll'](_0xcbe41e);})['then'](function(_0x10db1d){_0x5a03b5[_0x854f('0x52')]=_0x10db1d;return _0x5a03b5;});}})[_0x854f('0x21')](respondWithFilteredResult(_0x4330b5,_0xcbe41e))[_0x854f('0x53')](handleError(_0x4330b5,null));};exports[_0x854f('0xb0')]=function(_0x26df66,_0x117df7,_0x1620df){return db[_0x854f('0x3d')][_0x854f('0x5a')]({'where':{'id':_0x26df66[_0x854f('0x55')]['id']}})[_0x854f('0x21')](handleEntityNotFound(_0x117df7,null))[_0x854f('0x21')](function(_0x1fb7ff){if(_0x1fb7ff){return _0x1fb7ff[_0x854f('0xb0')](_0x26df66['body'][_0x854f('0xb1')],_[_0x854f('0xb2')](_0x26df66[_0x854f('0x5c')],[_0x854f('0xb1'),'id'])||{})[_0x854f('0x95')](function(_0x521c68){for(var _0x42036f=0x0;_0x42036f<_0x26df66['body'][_0x854f('0xb1')][_0x854f('0x57')];_0x42036f+=0x1){socket['emit'](_0x854f('0xb3'),{'UserId':_0x26df66['body'][_0x854f('0xb1')][_0x42036f],'OpenchannelAccountId':_0x26df66[_0x854f('0x55')]['id']});}return _0x521c68;});}})['then'](respondWithResult(_0x117df7,null))[_0x854f('0x53')](handleError(_0x117df7,null));};exports[_0x854f('0xb4')]=function(_0x43004e,_0x3c7347,_0x4ea177){return db[_0x854f('0x3d')]['find']({'where':{'id':_0x43004e[_0x854f('0x55')]['id']}})['then'](handleEntityNotFound(_0x3c7347,null))[_0x854f('0x21')](function(_0x411198){if(_0x411198){return _0x411198['removeAgents'](_0x43004e[_0x854f('0x40')][_0x854f('0xb1')])[_0x854f('0x21')](function(){if(_[_0x854f('0xb5')](_0x43004e[_0x854f('0x40')][_0x854f('0xb1')])){for(var _0x5bfeb8=0x0;_0x5bfeb8<_0x43004e[_0x854f('0x40')]['ids'][_0x854f('0x57')];_0x5bfeb8+=0x1){socket[_0x854f('0xb6')](_0x854f('0xb7'),{'UserId':Number(_0x43004e[_0x854f('0x40')][_0x854f('0xb1')][_0x5bfeb8]),'OpenchannelAccountId':Number(_0x43004e[_0x854f('0x55')]['id'])});}}else{socket['emit'](_0x854f('0xb7'),{'UserId':Number(_0x43004e[_0x854f('0x40')]['ids']),'OpenchannelAccountId':Number(_0x43004e[_0x854f('0x55')]['id'])});}});}})[_0x854f('0x21')](respondWithStatusCode(_0x3c7347,null))[_0x854f('0x53')](handleError(_0x3c7347,null));};exports[_0x854f('0xb8')]=function(_0x438436,_0x11ac54,_0x1e9e24){var _0xa45f3a={};var _0x34adc1={};var _0x725cc8;var _0x10d772;return db[_0x854f('0x3d')][_0x854f('0x68')]({'where':{'id':_0x438436[_0x854f('0x55')]['id']}})[_0x854f('0x21')](handleEntityNotFound(_0x11ac54,null))['then'](function(_0x55c534){if(_0x55c534){_0x725cc8=_0x55c534;_0x34adc1[_0x854f('0x3e')]=_[_0x854f('0x3f')](db[_0x854f('0x9e')]['rawAttributes']);_0x34adc1[_0x854f('0x40')]=_[_0x854f('0x3f')](_0x438436[_0x854f('0x40')]);_0x34adc1[_0x854f('0x41')]=_[_0x854f('0x43')](_0x34adc1[_0x854f('0x3e')],_0x34adc1[_0x854f('0x40')]);_0xa45f3a[_0x854f('0x42')]=_['intersection'](_0x34adc1[_0x854f('0x3e')],qs[_0x854f('0x44')](_0x438436[_0x854f('0x40')][_0x854f('0x44')]));_0xa45f3a[_0x854f('0x42')]=_0xa45f3a['attributes'][_0x854f('0x57')]?_0xa45f3a[_0x854f('0x42')]:_0x34adc1['model'];_0xa45f3a[_0x854f('0x6e')]=qs['sort'](_0x438436[_0x854f('0x40')]['sort']);_0xa45f3a['where']=qs[_0x854f('0x41')](_[_0x854f('0x4a')](_0x438436[_0x854f('0x40')],_0x34adc1[_0x854f('0x41')]));if(_0x438436[_0x854f('0x40')][_0x854f('0x4b')]){_0xa45f3a[_0x854f('0x49')]=_[_0x854f('0x4c')](_0xa45f3a[_0x854f('0x49')],{'$or':_[_0x854f('0x4d')](_0xa45f3a['attributes'],function(_0x9aa932){var _0x3327cd={};_0x3327cd[_0x9aa932]={'$like':'%'+_0x438436[_0x854f('0x40')][_0x854f('0x4b')]+'%'};return _0x3327cd;})});}_0xa45f3a=_[_0x854f('0x4c')]({},_0xa45f3a,_0x438436[_0x854f('0x59')]);return _0x725cc8[_0x854f('0xb8')](_0xa45f3a);}})[_0x854f('0x21')](function(_0x6cd230){if(_0x6cd230){_0x10d772=_0x6cd230[_0x854f('0x57')];if(!_0x438436['query'][_0x854f('0x45')]('nolimit')){_0xa45f3a[_0x854f('0x47')]=qs['limit'](_0x438436[_0x854f('0x40')][_0x854f('0x47')]);_0xa45f3a[_0x854f('0x2e')]=qs[_0x854f('0x2e')](_0x438436[_0x854f('0x40')]['offset']);}return _0x725cc8[_0x854f('0xb8')](_0xa45f3a);}})[_0x854f('0x21')](function(_0x39e727){if(_0x39e727){return _0x39e727?{'count':_0x10d772,'rows':_0x39e727}:null;}})[_0x854f('0x21')](respondWithResult(_0x11ac54,null))[_0x854f('0x53')](handleError(_0x11ac54,null));};exports[_0x854f('0x3a')]=function(_0x2ecf8e,_0x1f2c45,_0xef440){var _0x4209c8,_0x176965,_0x26abe7;if(_['isNil'](_0x2ecf8e['body']['body'])||_0x2ecf8e['body'][_0x854f('0x5c')]===''){throw new db['Sequelize'][(_0x854f('0x76'))](_0x854f('0x7e'));}if(_[_0x854f('0x7c')](_0x2ecf8e[_0x854f('0x5c')]['to'])){}_0x4209c8=_0x2ecf8e[_0x854f('0x5c')]['to'];return db['OpenchannelAccount']['findOne']({'where':{'id':_0x2ecf8e[_0x854f('0x55')]['id']}})[_0x854f('0x21')](handleEntityNotFound(_0x1f2c45,null))[_0x854f('0x21')](function(_0x1d904d){if(_0x1d904d){return db[_0x854f('0x3d')][_0x854f('0x5a')]({'where':{'id':_0x1d904d['id']},'include':[{'model':db[_0x854f('0x83')],'as':_0x854f('0x84'),'include':[{'model':db[_0x854f('0x73')],'as':_0x854f('0x85'),'where':{[_0x1d904d[_0x854f('0x7f')]]:_0x4209c8},'limit':0x1,'order':[[_0x854f('0x78'),_0x854f('0x86')]]}]}]})[_0x854f('0x21')](handleEntityNotFound(_0x1f2c45,null))[_0x854f('0x21')](function(_0x3e05da){if(_0x3e05da&&_0x3e05da[_0x854f('0x84')]){_0x176965=_0x3e05da['get']({'plain':!![]});if(_0x176965[_0x854f('0x84')]&&_0x176965[_0x854f('0x84')][_0x854f('0x85')]['length']){return _0x176965['List'][_0x854f('0x85')][0x0];}return db[_0x854f('0x73')][_0x854f('0x5b')](_[_0x854f('0x19')](_0x2ecf8e['body'],{'firstName':_0x4209c8,[_0x3e05da[_0x854f('0x7f')]]:_0x4209c8,'phone':_0x4209c8,'ListId':_0x176965[_0x854f('0x7b')]}));}})['then'](handleEntityNotFound(_0x1f2c45,null))[_0x854f('0x21')](function(_0x40339d){if(_0x40339d){_0x26abe7=_0x40339d;return db[_0x854f('0x92')][_0x854f('0x5a')]({'where':{'ContactId':_0x26abe7['id'],'closed':![],'OpenchannelAccountId':_0x176965['id']}})[_0x854f('0x21')](function(_0x58f3c6){if(_0x58f3c6){return[_0x58f3c6,![]];}return db[_0x854f('0x92')][_0x854f('0x5b')]({'UserId':_0x2ecf8e[_0x854f('0x5d')]['id'],'ContactId':_0x26abe7['id'],'OpenchannelAccountId':_0x176965['id'],'lastMsgDirection':_0x854f('0xb9'),'Messages':[_['merge'](_0x2ecf8e[_0x854f('0x5c')],{'read':![],'body':_0x2ecf8e[_0x854f('0x5c')][_0x854f('0x5c')],'OpenchannelAccountId':_0x176965['id'],'UserId':_0x2ecf8e[_0x854f('0x5d')]['id'],'ContactId':_0x26abe7['id']})]},{'include':[{'model':db[_0x854f('0xba')],'as':_0x854f('0xbb')}]})[_0x854f('0x21')](function(_0x47ecbc){return[_0x47ecbc,!![]];});});}})[_0x854f('0x95')](function(_0x4b0d7e,_0x1f96a2){if(_0x1f96a2){return _0x4b0d7e;}return db[_0x854f('0xba')][_0x854f('0x5b')](_[_0x854f('0x4c')](_0x2ecf8e[_0x854f('0x5c')],{'read':![],'body':_0x2ecf8e['body']['body'],'OpenchannelAccountId':_0x176965['id'],'OpenchannelInteractionId':_0x4b0d7e['id'],'UserId':_0x2ecf8e[_0x854f('0x5d')]['id'],'ContactId':_0x26abe7['id']}))[_0x854f('0x21')](function(_0x4f7d07){_0x4b0d7e['dataValues'][_0x854f('0xbb')]=[];_0x4b0d7e[_0x854f('0xbc')][_0x854f('0xbb')][_0x854f('0x9a')](_0x4f7d07[_0x854f('0xbc')]);return _0x4b0d7e;});});}})[_0x854f('0x21')](respondWithResult(_0x1f2c45,null))['catch'](handleError(_0x1f2c45,null));};