a26496765d4bab0dd1202fc7757d966f98b95af5
[motion2.git] / server / api / whatsappQueue / whatsappQueue.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 _0x8164=['error','code','WhatsappQueue,\x20%s,\x20%s','message','catch','WhatsappQueue','findAll','options','raw','where','attributes','limit','map','include','model','info','GetWhatsappQueue','ShowWhatsappQueue','lodash','util','moment','bluebird','randomstring','ioredis','../../config/utils','rpc','../../config/environment','jayson/promise','http','defaults','redis','localhost','socket.io-emitter','./whatsappQueue.socket','register','request','then','debug','WhatsappQueue,\x20%s,\x20%s,\x20%s','request\x20sent','stringify'];(function(_0x245605,_0x240d98){var _0x1a9581=function(_0x411645){while(--_0x411645){_0x245605['push'](_0x245605['shift']());}};_0x1a9581(++_0x240d98);}(_0x8164,0x1ac));var _0x4816=function(_0x47ae1f,_0x328d68){_0x47ae1f=_0x47ae1f-0x0;var _0x2a0233=_0x8164[_0x47ae1f];return _0x2a0233;};'use strict';var _=require(_0x4816('0x0'));var util=require(_0x4816('0x1'));var moment=require(_0x4816('0x2'));var BPromise=require(_0x4816('0x3'));var rs=require(_0x4816('0x4'));var fs=require('fs');var Redis=require(_0x4816('0x5'));var db=require('../../mysqldb')['db'];var utils=require(_0x4816('0x6'));var logger=require('../../config/logger')(_0x4816('0x7'));var config=require(_0x4816('0x8'));var jayson=require(_0x4816('0x9'));var client=jayson['client'][_0x4816('0xa')]({'port':0x232a});config['redis']=_[_0x4816('0xb')](config[_0x4816('0xc')],{'host':_0x4816('0xd'),'port':0x18eb});var socket=require(_0x4816('0xe'))(new Redis(config[_0x4816('0xc')]));require(_0x4816('0xf'))[_0x4816('0x10')](socket);function respondWithRpcPromise(_0x189d59,_0x21f485,_0x2609ef){return new BPromise(function(_0x2bb35e,_0x2e21ad){return client[_0x4816('0x11')](_0x189d59,_0x2609ef)[_0x4816('0x12')](function(_0x180844){logger['info']('WhatsappQueue,\x20%s,\x20%s',_0x21f485,'request\x20sent');logger[_0x4816('0x13')](_0x4816('0x14'),_0x21f485,_0x4816('0x15'),JSON[_0x4816('0x16')](_0x180844));if(_0x180844['error']){if(_0x180844[_0x4816('0x17')][_0x4816('0x18')]===0x1f4){logger['error'](_0x4816('0x19'),_0x21f485,_0x180844[_0x4816('0x17')][_0x4816('0x1a')]);return _0x2e21ad(_0x180844['error'][_0x4816('0x1a')]);}logger[_0x4816('0x17')](_0x4816('0x19'),_0x21f485,_0x180844['error'][_0x4816('0x1a')]);return _0x2bb35e(_0x180844['error']['message']);}else{logger['info']('WhatsappQueue,\x20%s,\x20%s',_0x21f485,_0x4816('0x15'));_0x2bb35e(_0x180844['result']['message']);}})[_0x4816('0x1b')](function(_0x37fe47){logger[_0x4816('0x17')](_0x4816('0x19'),_0x21f485,_0x37fe47);_0x2e21ad(_0x37fe47);});});}exports['GetWhatsappQueue']=function(_0x3c71de){var _0xd4bf5a=this;return new Promise(function(_0x1b0f23,_0x40c62f){return db[_0x4816('0x1c')][_0x4816('0x1d')]({'raw':_0x3c71de[_0x4816('0x1e')]?_0x3c71de[_0x4816('0x1e')][_0x4816('0x1f')]===undefined?!![]:![]:!![],'where':_0x3c71de[_0x4816('0x1e')]?_0x3c71de['options'][_0x4816('0x20')]||null:null,'attributes':_0x3c71de[_0x4816('0x1e')]?_0x3c71de[_0x4816('0x1e')][_0x4816('0x21')]||null:null,'limit':_0x3c71de[_0x4816('0x1e')]?_0x3c71de['options'][_0x4816('0x22')]||null:null,'include':_0x3c71de[_0x4816('0x1e')]?_0x3c71de[_0x4816('0x1e')]['include']?_[_0x4816('0x23')](_0x3c71de[_0x4816('0x1e')]['include'],function(_0x726982){return{'model':db[_0x726982['model']],'as':_0x726982['as'],'attributes':_0x726982[_0x4816('0x21')],'include':_0x726982[_0x4816('0x24')]?_[_0x4816('0x23')](_0x726982[_0x4816('0x24')],function(_0x444d2b){return{'model':db[_0x444d2b['model']],'as':_0x444d2b['as'],'attributes':_0x444d2b['attributes'],'include':_0x444d2b['include']?_['map'](_0x444d2b[_0x4816('0x24')],function(_0x86a4d6){return{'model':db[_0x86a4d6[_0x4816('0x25')]],'as':_0x86a4d6['as'],'attributes':_0x86a4d6[_0x4816('0x21')]};}):[]};}):[]};}):[]:[]})[_0x4816('0x12')](function(_0x93b6a0){logger[_0x4816('0x26')](_0x4816('0x27'),_0x3c71de);logger['debug']('GetWhatsappQueue',_0x3c71de,JSON[_0x4816('0x16')](_0x93b6a0));_0x1b0f23(_0x93b6a0);})[_0x4816('0x1b')](function(_0x59a5d2){logger[_0x4816('0x17')]('GetWhatsappQueue',_0x59a5d2[_0x4816('0x1a')],_0x3c71de);_0x40c62f(_0xd4bf5a[_0x4816('0x17')](0x1f4,_0x59a5d2[_0x4816('0x1a')]));});});};exports[_0x4816('0x28')]=function(_0x588fa9){var _0x4e34ec=this;return new Promise(function(_0x2befd1,_0x566dbe){return db['WhatsappQueue']['find']({'raw':_0x588fa9[_0x4816('0x1e')]?_0x588fa9[_0x4816('0x1e')]['raw']===undefined?!![]:![]:!![],'where':_0x588fa9[_0x4816('0x1e')]?_0x588fa9[_0x4816('0x1e')][_0x4816('0x20')]||null:null,'attributes':_0x588fa9['options']?_0x588fa9['options'][_0x4816('0x21')]||null:null,'include':_0x588fa9[_0x4816('0x1e')]?_0x588fa9[_0x4816('0x1e')][_0x4816('0x24')]?_[_0x4816('0x23')](_0x588fa9[_0x4816('0x1e')][_0x4816('0x24')],function(_0x467204){return{'model':db[_0x467204['model']],'as':_0x467204['as'],'attributes':_0x467204[_0x4816('0x21')],'include':_0x467204[_0x4816('0x24')]?_[_0x4816('0x23')](_0x467204['include'],function(_0x4c8599){return{'model':db[_0x4c8599[_0x4816('0x25')]],'as':_0x4c8599['as'],'attributes':_0x4c8599[_0x4816('0x21')],'include':_0x4c8599[_0x4816('0x24')]?_[_0x4816('0x23')](_0x4c8599[_0x4816('0x24')],function(_0x5272cc){return{'model':db[_0x5272cc[_0x4816('0x25')]],'as':_0x5272cc['as'],'attributes':_0x5272cc[_0x4816('0x21')]};}):[]};}):[]};}):[]:[]})[_0x4816('0x12')](function(_0x45dbf9){logger[_0x4816('0x26')](_0x4816('0x28'),_0x588fa9);logger[_0x4816('0x13')](_0x4816('0x28'),_0x588fa9,JSON[_0x4816('0x16')](_0x45dbf9));_0x2befd1(_0x45dbf9);})[_0x4816('0x1b')](function(_0x966f27){logger[_0x4816('0x17')](_0x4816('0x28'),_0x966f27[_0x4816('0x1a')],_0x588fa9);_0x566dbe(_0x4e34ec['error'](0x1f4,_0x966f27['message']));});});};