28c93db69e86063fbd9c67558f4ed89c1959d93d
[motion2.git] / server / api / faxAccount / faxAccount.rpc.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 _0x5b35=['include','map','model','body','fax','CmContact','describe','Sequelize','ValidationError','no\x20available\x20attributes','difference','keys','createdAt','updatedAt','CompanyId','ListId','from','from\x20is\x20mandatory','isNil','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','find','account','CmList','List','Contacts','DESC','get','applications','orderBy','priority','asc','Applications','defaults','create','contact','FaxInteraction','Contact\x20not\x20found','autoclose','push','length','close','unmanaged','*,*,*,*','created','interaction','FaxMessage','AttachmentId','UserId','unshift','agent','name','waitForTheAssignedAgent','Start','startRouting','lodash','util','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','redis','localhost','./faxAccount.socket','register','then','info','FaxAccount,\x20%s,\x20%s','request\x20sent','debug','FaxAccount,\x20%s,\x20%s,\x20%s','stringify','code','error','message','result','catch','GetFaxAccount','FaxAccount','findAll','options','raw','attributes','limit'];(function(_0x27dba4,_0x419253){var _0x35ec9d=function(_0x2d13b2){while(--_0x2d13b2){_0x27dba4['push'](_0x27dba4['shift']());}};_0x35ec9d(++_0x419253);}(_0x5b35,0x194));var _0x55b3=function(_0x40a045,_0x516f0e){_0x40a045=_0x40a045-0x0;var _0x1a687c=_0x5b35[_0x40a045];return _0x1a687c;};'use strict';var _=require(_0x55b3('0x0'));var util=require(_0x55b3('0x1'));var moment=require('moment');var BPromise=require('bluebird');var rs=require(_0x55b3('0x2'));var fs=require('fs');var Redis=require(_0x55b3('0x3'));var db=require(_0x55b3('0x4'))['db'];var utils=require(_0x55b3('0x5'));var logger=require(_0x55b3('0x6'))(_0x55b3('0x7'));var config=require('../../config/environment');var jayson=require('jayson/promise');var client=jayson['client']['http']({'port':0x232c});config[_0x55b3('0x8')]=_['defaults'](config[_0x55b3('0x8')],{'host':_0x55b3('0x9'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x55b3('0x8')]));require(_0x55b3('0xa'))[_0x55b3('0xb')](socket);function respondWithRpcPromise(_0xea1223,_0xe48b02,_0x4173a0){return new BPromise(function(_0xcef083,_0x2669d9){return client['request'](_0xea1223,_0x4173a0)[_0x55b3('0xc')](function(_0x361cf6){logger[_0x55b3('0xd')](_0x55b3('0xe'),_0xe48b02,_0x55b3('0xf'));logger[_0x55b3('0x10')](_0x55b3('0x11'),_0xe48b02,_0x55b3('0xf'),JSON[_0x55b3('0x12')](_0x361cf6));if(_0x361cf6['error']){if(_0x361cf6['error'][_0x55b3('0x13')]===0x1f4){logger['error'](_0x55b3('0xe'),_0xe48b02,_0x361cf6[_0x55b3('0x14')][_0x55b3('0x15')]);return _0x2669d9(_0x361cf6[_0x55b3('0x14')][_0x55b3('0x15')]);}logger['error'](_0x55b3('0xe'),_0xe48b02,_0x361cf6['error'][_0x55b3('0x15')]);return _0xcef083(_0x361cf6['error']['message']);}else{logger[_0x55b3('0xd')](_0x55b3('0xe'),_0xe48b02,_0x55b3('0xf'));_0xcef083(_0x361cf6[_0x55b3('0x16')][_0x55b3('0x15')]);}})[_0x55b3('0x17')](function(_0x351d53){logger[_0x55b3('0x14')]('FaxAccount,\x20%s,\x20%s',_0xe48b02,_0x351d53);_0x2669d9(_0x351d53);});});}exports[_0x55b3('0x18')]=function(_0xceabc0){var _0x3c5919=this;return new Promise(function(_0x1a1dec,_0x9709d2){return db[_0x55b3('0x19')][_0x55b3('0x1a')]({'raw':_0xceabc0[_0x55b3('0x1b')]?_0xceabc0[_0x55b3('0x1b')][_0x55b3('0x1c')]===undefined?!![]:![]:!![],'where':_0xceabc0[_0x55b3('0x1b')]?_0xceabc0[_0x55b3('0x1b')]['where']||null:null,'attributes':_0xceabc0[_0x55b3('0x1b')]?_0xceabc0['options'][_0x55b3('0x1d')]||null:null,'limit':_0xceabc0['options']?_0xceabc0[_0x55b3('0x1b')][_0x55b3('0x1e')]||null:null,'include':_0xceabc0[_0x55b3('0x1b')]?_0xceabc0['options'][_0x55b3('0x1f')]?_[_0x55b3('0x20')](_0xceabc0[_0x55b3('0x1b')][_0x55b3('0x1f')],function(_0x3bb7da){return{'model':db[_0x3bb7da['model']],'as':_0x3bb7da['as'],'attributes':_0x3bb7da[_0x55b3('0x1d')],'include':_0x3bb7da[_0x55b3('0x1f')]?_[_0x55b3('0x20')](_0x3bb7da[_0x55b3('0x1f')],function(_0x38bff7){return{'model':db[_0x38bff7[_0x55b3('0x21')]],'as':_0x38bff7['as'],'attributes':_0x38bff7[_0x55b3('0x1d')],'include':_0x38bff7['include']?_[_0x55b3('0x20')](_0x38bff7[_0x55b3('0x1f')],function(_0x1374a3){return{'model':db[_0x1374a3['model']],'as':_0x1374a3['as'],'attributes':_0x1374a3[_0x55b3('0x1d')]};}):[]};}):[]};}):[]:[]})[_0x55b3('0xc')](function(_0x4ec182){logger[_0x55b3('0xd')](_0x55b3('0x18'),_0xceabc0);logger['debug'](_0x55b3('0x18'),_0xceabc0,JSON[_0x55b3('0x12')](_0x4ec182));_0x1a1dec(_0x4ec182);})[_0x55b3('0x17')](function(_0x42f39e){logger[_0x55b3('0x14')]('GetFaxAccount',_0x42f39e[_0x55b3('0x15')],_0xceabc0);_0x9709d2(_0x3c5919['error'](0x1f4,_0x42f39e[_0x55b3('0x15')]));});});};exports['NotifyFaxAccount']=function(_0x4376b1,_0x102b18,_0x474db6){var _0x5a9a92=this;return new Promise(function(_0x4fa618,_0x3e5960){var _0x58919c={'body':_0x4376b1[_0x55b3('0x22')],'channel':_0x55b3('0x23')};var _0x20cdee=[];var _0x26d7db=[];var _0x460b0a={};return db[_0x55b3('0x24')][_0x55b3('0x25')]()[_0x55b3('0xc')](function(_0x12ec91){if(!_0x12ec91){throw new db[(_0x55b3('0x26'))][(_0x55b3('0x27'))](_0x55b3('0x28'));}_0x20cdee=_[_0x55b3('0x29')](_[_0x55b3('0x2a')](_0x12ec91),[_0x55b3('0x2b'),_0x55b3('0x2c')]);_0x26d7db=_[_0x55b3('0x29')](_[_0x55b3('0x2a')](_0x12ec91),[_0x55b3('0x2b'),'updatedAt',_0x55b3('0x2d'),_0x55b3('0x2e')]);if(_0x4376b1[_0x55b3('0x22')]['id']){delete _0x4376b1[_0x55b3('0x22')]['id'];}if(_['isNil'](_0x4376b1[_0x55b3('0x22')][_0x55b3('0x2f')])){throw new db[(_0x55b3('0x26'))][(_0x55b3('0x27'))](_0x55b3('0x30'));}if(_[_0x55b3('0x31')](_0x4376b1[_0x55b3('0x22')][_0x55b3('0x22')])||_0x4376b1[_0x55b3('0x22')][_0x55b3('0x22')]===''){throw new db[(_0x55b3('0x26'))][(_0x55b3('0x27'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_['isNil'](_0x4376b1[_0x55b3('0x22')][_0x55b3('0x32')])){throw new db['Sequelize'][(_0x55b3('0x27'))](_0x55b3('0x33')+_0x26d7db);}if(!_[_0x55b3('0x34')](_0x26d7db,_0x4376b1[_0x55b3('0x22')]['mapKey'])){throw new db[(_0x55b3('0x26'))][(_0x55b3('0x27'))]('mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x26d7db);}_0x460b0a[_0x4376b1[_0x55b3('0x22')][_0x55b3('0x32')]]=_0x4376b1[_0x55b3('0x22')][_0x55b3('0x2f')];})[_0x55b3('0xc')](function(){return db[_0x55b3('0x19')][_0x55b3('0x35')]({'where':{'id':_0x4376b1[_0x55b3('0x36')]['id']},'include':[{'model':db[_0x55b3('0x37')],'as':_0x55b3('0x38'),'include':[{'model':db['CmContact'],'as':_0x55b3('0x39'),'where':_0x460b0a,'limit':0x1,'order':[[_0x55b3('0x2c'),_0x55b3('0x3a')]]}]},{'model':db['FaxApplication'],'as':'Applications'}]});})['then'](function(_0x3e3929){if(_0x3e3929&&_0x3e3929[_0x55b3('0x38')]){var _0x1dd297=_0x3e3929[_0x55b3('0x3b')]({'plain':!![]});_0x58919c[_0x55b3('0x36')]=_0x1dd297;_0x58919c[_0x55b3('0x3c')]=_0x1dd297['Applications'];_0x58919c['list']=_0x1dd297[_0x55b3('0x38')];_0x58919c[_0x55b3('0x3c')]=_[_0x55b3('0x3d')](_0x58919c[_0x55b3('0x3c')],[_0x55b3('0x3e')],[_0x55b3('0x3f')]);if(_0x58919c[_0x55b3('0x36')][_0x55b3('0x40')]){delete _0x58919c[_0x55b3('0x36')][_0x55b3('0x40')];}if(_0x58919c[_0x55b3('0x36')][_0x55b3('0x38')]&&_0x58919c[_0x55b3('0x36')][_0x55b3('0x38')][_0x55b3('0x39')]['length']){return _0x58919c[_0x55b3('0x36')][_0x55b3('0x38')][_0x55b3('0x39')][0x0];}var _0x512cbe=_[_0x55b3('0x41')](_0x4376b1[_0x55b3('0x22')],{'firstName':_0x4376b1[_0x55b3('0x22')][_0x55b3('0x2f')],'ListId':_0x1dd297['ListId']});_0x512cbe[_0x4376b1[_0x55b3('0x22')][_0x55b3('0x32')]]=_0x4376b1['body'][_0x55b3('0x2f')];return db[_0x55b3('0x24')][_0x55b3('0x42')](_0x512cbe,{'fields':_0x20cdee,'raw':!![]});}})['then'](function(_0x934731){_0x58919c[_0x55b3('0x43')]=_0x934731;if(_0x934731){var _0x4fdf25={'ContactId':_0x934731['id'],'FaxAccountId':_0x4376b1[_0x55b3('0x36')]['id'],'fax':_0x934731[_0x55b3('0x23')]};return db[_0x55b3('0x44')][_0x55b3('0x35')]({'where':{'ContactId':_0x934731['id'],'closed':![],'FaxAccountId':_0x4376b1[_0x55b3('0x36')]['id']}})['then'](function(_0x5ee6f9){if(_0x5ee6f9){return[_0x5ee6f9,![]];}return db[_0x55b3('0x44')][_0x55b3('0x42')](_0x4fdf25)[_0x55b3('0xc')](function(_0x449ed2){return[_0x449ed2,!![]];});});}else{throw new Error(_0x55b3('0x45'));}})['spread'](function(_0x2646c3,_0x4f7ecc){var _0x5bed66=_0x2646c3[_0x55b3('0x3b')]({'plain':!![]});if(_0x4f7ecc){if(_0x58919c[_0x55b3('0x36')][_0x55b3('0x46')]){_0x58919c[_0x55b3('0x3c')][_0x55b3('0x47')]({'id':0x0,'priority':_0x58919c[_0x55b3('0x3c')][_0x55b3('0x48')]+0x1,'app':_0x55b3('0x49'),'appdata':_0x55b3('0x4a'),'interval':_0x55b3('0x4b')});}_0x5bed66[_0x55b3('0x4c')]=!![];}else{_0x5bed66[_0x55b3('0x4c')]=![];}_0x58919c[_0x55b3('0x4d')]=_0x5bed66;return db[_0x55b3('0x4e')][_0x55b3('0x42')]({'body':_0x4376b1[_0x55b3('0x22')][_0x55b3('0x22')],'FaxAccountId':_0x4376b1[_0x55b3('0x36')]['id'],'FaxInteractionId':_0x2646c3['id'],'direction':'in','ContactId':_0x2646c3['ContactId'],'AttachmentId':_0x4376b1[_0x55b3('0x22')][_0x55b3('0x4f')]});})[_0x55b3('0xc')](function(_0x576d6e){_0x58919c[_0x55b3('0x15')]=_0x576d6e;if(_0x58919c[_0x55b3('0x4d')][_0x55b3('0x50')]){return db['User']['find']({'attributes':['id','name'],'where':{'id':_0x58919c[_0x55b3('0x4d')][_0x55b3('0x50')]}})[_0x55b3('0xc')](function(_0x4f0675){if(_0x4f0675){_0x58919c['applications'][_0x55b3('0x51')]({'id':0x0,'priority':0x0,'app':_0x55b3('0x52'),'appdata':_0x4f0675[_0x55b3('0x53')]+','+(_0x58919c['account'][_0x55b3('0x54')]||0xa),'interval':_0x55b3('0x4b')});}return respondWithRpcPromise(_0x55b3('0x55'),'startRouting',_0x58919c);});}return respondWithRpcPromise(_0x55b3('0x55'),_0x55b3('0x56'),_0x58919c);})[_0x55b3('0xc')](function(_0x1b0ff3){_0x4fa618(_0x1b0ff3);})[_0x55b3('0x17')](function(_0x28ab3f){_0x3e5960(_0x5a9a92[_0x55b3('0x14')](0x1f4,_0x28ab3f['message']));});});};