Built motion from commit f3da74b7.|2.5.36
[motion2.git] / server / api / chatQueue / chatQueue.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 _0x8383=['../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','redis','defaults','localhost','./chatQueue.socket','register','request','then','info','request\x20sent','debug','ChatQueue,\x20%s,\x20%s,\x20%s','stringify','error','code','ChatQueue,\x20%s,\x20%s','message','result','catch','ChatQueue','options','where','attributes','include','map','model','GetChatQueue','raw','ShowChatQueue','lodash','bluebird','randomstring','ioredis'];(function(_0x2d1022,_0x292ba7){var _0x35dc62=function(_0x3ef12a){while(--_0x3ef12a){_0x2d1022['push'](_0x2d1022['shift']());}};_0x35dc62(++_0x292ba7);}(_0x8383,0x98));var _0x3838=function(_0x3f5a54,_0x121e75){_0x3f5a54=_0x3f5a54-0x0;var _0x331ec9=_0x8383[_0x3f5a54];return _0x331ec9;};'use strict';var _=require(_0x3838('0x0'));var util=require('util');var moment=require('moment');var BPromise=require(_0x3838('0x1'));var rs=require(_0x3838('0x2'));var fs=require('fs');var Redis=require(_0x3838('0x3'));var db=require(_0x3838('0x4'))['db'];var utils=require(_0x3838('0x5'));var logger=require(_0x3838('0x6'))(_0x3838('0x7'));var config=require(_0x3838('0x8'));var jayson=require(_0x3838('0x9'));var client=jayson[_0x3838('0xa')]['http']({'port':0x232a});config[_0x3838('0xb')]=_[_0x3838('0xc')](config['redis'],{'host':_0x3838('0xd'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x3838('0xb')]));require(_0x3838('0xe'))[_0x3838('0xf')](socket);function respondWithRpcPromise(_0x550a5c,_0x2af70d,_0xeccb09){return new BPromise(function(_0x15c28a,_0x545100){return client[_0x3838('0x10')](_0x550a5c,_0xeccb09)[_0x3838('0x11')](function(_0x9161a2){logger[_0x3838('0x12')]('ChatQueue,\x20%s,\x20%s',_0x2af70d,_0x3838('0x13'));logger[_0x3838('0x14')](_0x3838('0x15'),_0x2af70d,'request\x20sent',JSON[_0x3838('0x16')](_0x9161a2));if(_0x9161a2['error']){if(_0x9161a2[_0x3838('0x17')][_0x3838('0x18')]===0x1f4){logger[_0x3838('0x17')](_0x3838('0x19'),_0x2af70d,_0x9161a2[_0x3838('0x17')]['message']);return _0x545100(_0x9161a2[_0x3838('0x17')][_0x3838('0x1a')]);}logger[_0x3838('0x17')](_0x3838('0x19'),_0x2af70d,_0x9161a2[_0x3838('0x17')]['message']);return _0x15c28a(_0x9161a2[_0x3838('0x17')][_0x3838('0x1a')]);}else{logger[_0x3838('0x12')]('ChatQueue,\x20%s,\x20%s',_0x2af70d,_0x3838('0x13'));_0x15c28a(_0x9161a2[_0x3838('0x1b')]['message']);}})[_0x3838('0x1c')](function(_0x2fe3c8){logger['error'](_0x3838('0x19'),_0x2af70d,_0x2fe3c8);_0x545100(_0x2fe3c8);});});}exports['GetChatQueue']=function(_0x26580){var _0x37f607=this;return new Promise(function(_0x1ae6c9,_0x2f9965){return db[_0x3838('0x1d')]['findAll']({'raw':_0x26580['options']?_0x26580[_0x3838('0x1e')]['raw']===undefined?!![]:![]:!![],'where':_0x26580[_0x3838('0x1e')]?_0x26580[_0x3838('0x1e')][_0x3838('0x1f')]||null:null,'attributes':_0x26580[_0x3838('0x1e')]?_0x26580[_0x3838('0x1e')][_0x3838('0x20')]||null:null,'limit':_0x26580[_0x3838('0x1e')]?_0x26580[_0x3838('0x1e')]['limit']||null:null,'include':_0x26580[_0x3838('0x1e')]?_0x26580['options'][_0x3838('0x21')]?_[_0x3838('0x22')](_0x26580['options'][_0x3838('0x21')],function(_0x265099){return{'model':db[_0x265099['model']],'as':_0x265099['as'],'attributes':_0x265099[_0x3838('0x20')],'include':_0x265099[_0x3838('0x21')]?_['map'](_0x265099[_0x3838('0x21')],function(_0x4c1efb){return{'model':db[_0x4c1efb[_0x3838('0x23')]],'as':_0x4c1efb['as'],'attributes':_0x4c1efb['attributes'],'include':_0x4c1efb['include']?_[_0x3838('0x22')](_0x4c1efb[_0x3838('0x21')],function(_0x41bb45){return{'model':db[_0x41bb45[_0x3838('0x23')]],'as':_0x41bb45['as'],'attributes':_0x41bb45[_0x3838('0x20')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x1baf56){logger[_0x3838('0x12')](_0x3838('0x24'),_0x26580);logger['debug'](_0x3838('0x24'),_0x26580,JSON['stringify'](_0x1baf56));_0x1ae6c9(_0x1baf56);})[_0x3838('0x1c')](function(_0x4b1a0c){logger[_0x3838('0x17')](_0x3838('0x24'),_0x4b1a0c['message'],_0x26580);_0x2f9965(_0x37f607[_0x3838('0x17')](0x1f4,_0x4b1a0c['message']));});});};exports['ShowChatQueue']=function(_0x19ec76){var _0x25b81c=this;return new Promise(function(_0x5c74ac,_0x5b594d){return db[_0x3838('0x1d')]['find']({'raw':_0x19ec76[_0x3838('0x1e')]?_0x19ec76[_0x3838('0x1e')][_0x3838('0x25')]===undefined?!![]:![]:!![],'where':_0x19ec76[_0x3838('0x1e')]?_0x19ec76[_0x3838('0x1e')][_0x3838('0x1f')]||null:null,'attributes':_0x19ec76['options']?_0x19ec76[_0x3838('0x1e')][_0x3838('0x20')]||null:null,'include':_0x19ec76[_0x3838('0x1e')]?_0x19ec76[_0x3838('0x1e')][_0x3838('0x21')]?_[_0x3838('0x22')](_0x19ec76[_0x3838('0x1e')][_0x3838('0x21')],function(_0x368298){return{'model':db[_0x368298[_0x3838('0x23')]],'as':_0x368298['as'],'attributes':_0x368298[_0x3838('0x20')],'include':_0x368298['include']?_[_0x3838('0x22')](_0x368298[_0x3838('0x21')],function(_0x3518c9){return{'model':db[_0x3518c9[_0x3838('0x23')]],'as':_0x3518c9['as'],'attributes':_0x3518c9['attributes'],'include':_0x3518c9[_0x3838('0x21')]?_[_0x3838('0x22')](_0x3518c9[_0x3838('0x21')],function(_0x1f4331){return{'model':db[_0x1f4331['model']],'as':_0x1f4331['as'],'attributes':_0x1f4331[_0x3838('0x20')]};}):[]};}):[]};}):[]:[]})[_0x3838('0x11')](function(_0x1c752e){logger[_0x3838('0x12')]('ShowChatQueue',_0x19ec76);logger[_0x3838('0x14')](_0x3838('0x26'),_0x19ec76,JSON[_0x3838('0x16')](_0x1c752e));_0x5c74ac(_0x1c752e);})['catch'](function(_0x5b3383){logger[_0x3838('0x17')](_0x3838('0x26'),_0x5b3383[_0x3838('0x1a')],_0x19ec76);_0x5b594d(_0x25b81c[_0x3838('0x17')](0x1f4,_0x5b3383[_0x3838('0x1a')]));});});};