Built motion from commit (unavailable).|2.5.3
[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 _0xdcf6=['error','code','message','result','catch','GetFaxAccount','FaxAccount','options','raw','where','attributes','limit','map','include','model','then','NotifyFaxAccount','body','fax','describe','Sequelize','ValidationError','no\x20available\x20attributes','difference','keys','createdAt','updatedAt','CompanyId','ListId','isNil','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','find','account','CmList','List','CmContact','Contacts','DESC','FaxApplication','Applications','get','applications','list','orderBy','priority','defaults','from','mapKey','create','contact','FaxInteraction','Contact\x20not\x20found','spread','length','close','unmanaged','*,*,*,*','created','interaction','FaxMessage','AttachmentId','UserId','User','name','unshift','agent','Start','util','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','rpc','../../config/environment','client','http','localhost','redis','./faxAccount.socket','register','request','info','FaxAccount,\x20%s,\x20%s','request\x20sent','debug','FaxAccount,\x20%s,\x20%s,\x20%s','stringify'];(function(_0x24fa88,_0x4007b2){var _0x2a7377=function(_0x32b955){while(--_0x32b955){_0x24fa88['push'](_0x24fa88['shift']());}};_0x2a7377(++_0x4007b2);}(_0xdcf6,0x1b6));var _0x6dcf=function(_0x18fe54,_0xff789){_0x18fe54=_0x18fe54-0x0;var _0xccb1ee=_0xdcf6[_0x18fe54];return _0xccb1ee;};'use strict';var _=require('lodash');var util=require(_0x6dcf('0x0'));var moment=require(_0x6dcf('0x1'));var BPromise=require(_0x6dcf('0x2'));var rs=require(_0x6dcf('0x3'));var fs=require('fs');var Redis=require(_0x6dcf('0x4'));var db=require(_0x6dcf('0x5'))['db'];var utils=require(_0x6dcf('0x6'));var logger=require('../../config/logger')(_0x6dcf('0x7'));var config=require(_0x6dcf('0x8'));var jayson=require('jayson/promise');var client=jayson[_0x6dcf('0x9')][_0x6dcf('0xa')]({'port':0x232c});config['redis']=_['defaults'](config['redis'],{'host':_0x6dcf('0xb'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x6dcf('0xc')]));require(_0x6dcf('0xd'))[_0x6dcf('0xe')](socket);function respondWithRpcPromise(_0x4eda69,_0x527a65,_0x5b65a7){return new BPromise(function(_0x443c93,_0x23f052){return client[_0x6dcf('0xf')](_0x4eda69,_0x5b65a7)['then'](function(_0x23fce1){logger[_0x6dcf('0x10')](_0x6dcf('0x11'),_0x527a65,_0x6dcf('0x12'));logger[_0x6dcf('0x13')](_0x6dcf('0x14'),_0x527a65,_0x6dcf('0x12'),JSON[_0x6dcf('0x15')](_0x23fce1));if(_0x23fce1[_0x6dcf('0x16')]){if(_0x23fce1[_0x6dcf('0x16')][_0x6dcf('0x17')]===0x1f4){logger[_0x6dcf('0x16')](_0x6dcf('0x11'),_0x527a65,_0x23fce1[_0x6dcf('0x16')][_0x6dcf('0x18')]);return _0x23f052(_0x23fce1[_0x6dcf('0x16')][_0x6dcf('0x18')]);}logger['error'](_0x6dcf('0x11'),_0x527a65,_0x23fce1[_0x6dcf('0x16')][_0x6dcf('0x18')]);return _0x443c93(_0x23fce1['error'][_0x6dcf('0x18')]);}else{logger[_0x6dcf('0x10')](_0x6dcf('0x11'),_0x527a65,_0x6dcf('0x12'));_0x443c93(_0x23fce1[_0x6dcf('0x19')][_0x6dcf('0x18')]);}})[_0x6dcf('0x1a')](function(_0x2b5cd4){logger['error'](_0x6dcf('0x11'),_0x527a65,_0x2b5cd4);_0x23f052(_0x2b5cd4);});});}exports[_0x6dcf('0x1b')]=function(_0x35c30b){var _0x2d2169=this;return new Promise(function(_0x3c9cbb,_0x200994){return db[_0x6dcf('0x1c')]['findAll']({'raw':_0x35c30b[_0x6dcf('0x1d')]?_0x35c30b['options'][_0x6dcf('0x1e')]===undefined?!![]:![]:!![],'where':_0x35c30b[_0x6dcf('0x1d')]?_0x35c30b[_0x6dcf('0x1d')][_0x6dcf('0x1f')]||null:null,'attributes':_0x35c30b['options']?_0x35c30b['options'][_0x6dcf('0x20')]||null:null,'limit':_0x35c30b['options']?_0x35c30b[_0x6dcf('0x1d')][_0x6dcf('0x21')]||null:null,'include':_0x35c30b[_0x6dcf('0x1d')]?_0x35c30b[_0x6dcf('0x1d')]['include']?_[_0x6dcf('0x22')](_0x35c30b[_0x6dcf('0x1d')][_0x6dcf('0x23')],function(_0x124853){return{'model':db[_0x124853['model']],'as':_0x124853['as'],'attributes':_0x124853[_0x6dcf('0x20')],'include':_0x124853[_0x6dcf('0x23')]?_[_0x6dcf('0x22')](_0x124853[_0x6dcf('0x23')],function(_0x16e8c4){return{'model':db[_0x16e8c4[_0x6dcf('0x24')]],'as':_0x16e8c4['as'],'attributes':_0x16e8c4[_0x6dcf('0x20')],'include':_0x16e8c4[_0x6dcf('0x23')]?_[_0x6dcf('0x22')](_0x16e8c4[_0x6dcf('0x23')],function(_0x2f9558){return{'model':db[_0x2f9558[_0x6dcf('0x24')]],'as':_0x2f9558['as'],'attributes':_0x2f9558['attributes']};}):[]};}):[]};}):[]:[]})[_0x6dcf('0x25')](function(_0x1d3b73){logger['info']('GetFaxAccount',_0x35c30b);logger['debug']('GetFaxAccount',_0x35c30b,JSON[_0x6dcf('0x15')](_0x1d3b73));_0x3c9cbb(_0x1d3b73);})[_0x6dcf('0x1a')](function(_0x4c106c){logger[_0x6dcf('0x16')](_0x6dcf('0x1b'),_0x4c106c[_0x6dcf('0x18')],_0x35c30b);_0x200994(_0x2d2169[_0x6dcf('0x16')](0x1f4,_0x4c106c['message']));});});};exports[_0x6dcf('0x26')]=function(_0x7730b0,_0x1031d5,_0x24a56e){var _0x1dd58c=this;return new Promise(function(_0x1c78d4,_0x7f01d4){var _0x18dc28={'body':_0x7730b0[_0x6dcf('0x27')],'channel':_0x6dcf('0x28')};var _0x3ef3c8=[];var _0x20f59d=[];var _0x1591cf={};return db['CmContact'][_0x6dcf('0x29')]()[_0x6dcf('0x25')](function(_0x4f8dd1){if(!_0x4f8dd1){throw new db[(_0x6dcf('0x2a'))][(_0x6dcf('0x2b'))](_0x6dcf('0x2c'));}_0x3ef3c8=_[_0x6dcf('0x2d')](_[_0x6dcf('0x2e')](_0x4f8dd1),[_0x6dcf('0x2f'),_0x6dcf('0x30')]);_0x20f59d=_[_0x6dcf('0x2d')](_['keys'](_0x4f8dd1),[_0x6dcf('0x2f'),'updatedAt',_0x6dcf('0x31'),_0x6dcf('0x32')]);if(_0x7730b0[_0x6dcf('0x27')]['id']){delete _0x7730b0[_0x6dcf('0x27')]['id'];}if(_[_0x6dcf('0x33')](_0x7730b0[_0x6dcf('0x27')]['from'])){throw new db[(_0x6dcf('0x2a'))]['ValidationError'](_0x6dcf('0x34'));}if(_['isNil'](_0x7730b0[_0x6dcf('0x27')][_0x6dcf('0x27')])||_0x7730b0[_0x6dcf('0x27')]['body']===''){throw new db[(_0x6dcf('0x2a'))]['ValidationError'](_0x6dcf('0x35'));}if(_['isNil'](_0x7730b0[_0x6dcf('0x27')]['mapKey'])){throw new db[(_0x6dcf('0x2a'))][(_0x6dcf('0x2b'))](_0x6dcf('0x36')+_0x20f59d);}if(!_['includes'](_0x20f59d,_0x7730b0[_0x6dcf('0x27')]['mapKey'])){throw new db[(_0x6dcf('0x2a'))][(_0x6dcf('0x2b'))](_0x6dcf('0x37')+_0x20f59d);}_0x1591cf[_0x7730b0[_0x6dcf('0x27')]['mapKey']]=_0x7730b0[_0x6dcf('0x27')]['from'];})[_0x6dcf('0x25')](function(){return db[_0x6dcf('0x1c')][_0x6dcf('0x38')]({'where':{'id':_0x7730b0[_0x6dcf('0x39')]['id']},'include':[{'model':db[_0x6dcf('0x3a')],'as':_0x6dcf('0x3b'),'include':[{'model':db[_0x6dcf('0x3c')],'as':_0x6dcf('0x3d'),'where':_0x1591cf,'limit':0x1,'order':[[_0x6dcf('0x30'),_0x6dcf('0x3e')]]}]},{'model':db[_0x6dcf('0x3f')],'as':_0x6dcf('0x40')}]});})[_0x6dcf('0x25')](function(_0x2dba6b){if(_0x2dba6b&&_0x2dba6b[_0x6dcf('0x3b')]){var _0x1a9d07=_0x2dba6b[_0x6dcf('0x41')]({'plain':!![]});_0x18dc28[_0x6dcf('0x39')]=_0x1a9d07;_0x18dc28[_0x6dcf('0x42')]=_0x1a9d07[_0x6dcf('0x40')];_0x18dc28[_0x6dcf('0x43')]=_0x1a9d07[_0x6dcf('0x3b')];_0x18dc28[_0x6dcf('0x42')]=_[_0x6dcf('0x44')](_0x18dc28[_0x6dcf('0x42')],[_0x6dcf('0x45')],['asc']);if(_0x18dc28['account'][_0x6dcf('0x40')]){delete _0x18dc28[_0x6dcf('0x39')][_0x6dcf('0x40')];}if(_0x18dc28['account'][_0x6dcf('0x3b')]&&_0x18dc28[_0x6dcf('0x39')]['List'][_0x6dcf('0x3d')]['length']){return _0x18dc28[_0x6dcf('0x39')][_0x6dcf('0x3b')][_0x6dcf('0x3d')][0x0];}var _0x39b3f8=_[_0x6dcf('0x46')](_0x7730b0[_0x6dcf('0x27')],{'firstName':_0x7730b0[_0x6dcf('0x27')][_0x6dcf('0x47')],'ListId':_0x1a9d07[_0x6dcf('0x32')]});_0x39b3f8[_0x7730b0[_0x6dcf('0x27')][_0x6dcf('0x48')]]=_0x7730b0[_0x6dcf('0x27')]['from'];return db[_0x6dcf('0x3c')][_0x6dcf('0x49')](_0x39b3f8,{'fields':_0x3ef3c8,'raw':!![]});}})[_0x6dcf('0x25')](function(_0x114d13){_0x18dc28[_0x6dcf('0x4a')]=_0x114d13;if(_0x114d13){var _0x27debd={'ContactId':_0x114d13['id'],'FaxAccountId':_0x7730b0[_0x6dcf('0x39')]['id'],'fax':_0x114d13[_0x6dcf('0x28')]};return db[_0x6dcf('0x4b')][_0x6dcf('0x38')]({'where':{'ContactId':_0x114d13['id'],'closed':![],'FaxAccountId':_0x7730b0[_0x6dcf('0x39')]['id']}})[_0x6dcf('0x25')](function(_0x324a41){if(_0x324a41){return[_0x324a41,![]];}return db[_0x6dcf('0x4b')]['create'](_0x27debd)['then'](function(_0x220047){return[_0x220047,!![]];});});}else{throw new Error(_0x6dcf('0x4c'));}})[_0x6dcf('0x4d')](function(_0x5aa12f,_0x3918b4){var _0x2d4534=_0x5aa12f[_0x6dcf('0x41')]({'plain':!![]});if(_0x3918b4){if(_0x18dc28['account']['autoclose']){_0x18dc28[_0x6dcf('0x42')]['push']({'id':0x0,'priority':_0x18dc28['applications'][_0x6dcf('0x4e')]+0x1,'app':_0x6dcf('0x4f'),'appdata':_0x6dcf('0x50'),'interval':_0x6dcf('0x51')});}_0x2d4534['created']=!![];}else{_0x2d4534[_0x6dcf('0x52')]=![];}_0x18dc28[_0x6dcf('0x53')]=_0x2d4534;return db[_0x6dcf('0x54')][_0x6dcf('0x49')]({'body':_0x7730b0[_0x6dcf('0x27')][_0x6dcf('0x27')],'FaxAccountId':_0x7730b0['account']['id'],'FaxInteractionId':_0x5aa12f['id'],'direction':'in','ContactId':_0x5aa12f['ContactId'],'AttachmentId':_0x7730b0[_0x6dcf('0x27')][_0x6dcf('0x55')]});})[_0x6dcf('0x25')](function(_0x458fd1){_0x18dc28['message']=_0x458fd1;if(_0x18dc28['interaction'][_0x6dcf('0x56')]){return db[_0x6dcf('0x57')]['find']({'attributes':['id',_0x6dcf('0x58')],'where':{'id':_0x18dc28[_0x6dcf('0x53')][_0x6dcf('0x56')]}})['then'](function(_0x4dd9a7){if(_0x4dd9a7){_0x18dc28[_0x6dcf('0x42')][_0x6dcf('0x59')]({'id':0x0,'priority':0x0,'app':_0x6dcf('0x5a'),'appdata':_0x4dd9a7['name']+','+(_0x18dc28[_0x6dcf('0x39')]['waitForTheAssignedAgent']||0xa),'interval':'*,*,*,*'});}return respondWithRpcPromise(_0x6dcf('0x5b'),'startRouting',_0x18dc28);});}return respondWithRpcPromise(_0x6dcf('0x5b'),'startRouting',_0x18dc28);})[_0x6dcf('0x25')](function(_0x47978d){_0x1c78d4(_0x47978d);})[_0x6dcf('0x1a')](function(_0x136d0c){_0x7f01d4(_0x1dd58c[_0x6dcf('0x16')](0x1f4,_0x136d0c['message']));});});};