Built motion from commit bbec7235.|2.6.20
[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 _0x23e5=['WhatsappQueue,\x20%s,\x20%s','request\x20sent','WhatsappQueue,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','GetWhatsappQueue','WhatsappQueue','findAll','options','raw','attributes','include','map','model','debug','catch','ShowWhatsappQueue','find','where','util','bluebird','randomstring','../../mysqldb','../../config/utils','../../config/logger','../../config/environment','jayson/promise','client','http','redis','defaults','localhost','socket.io-emitter','request','then','info'];(function(_0x16db8b,_0xca7d28){var _0x5ba017=function(_0x35b933){while(--_0x35b933){_0x16db8b['push'](_0x16db8b['shift']());}};_0x5ba017(++_0xca7d28);}(_0x23e5,0x1ea));var _0x523e=function(_0x35d239,_0x234a02){_0x35d239=_0x35d239-0x0;var _0x42f8fe=_0x23e5[_0x35d239];return _0x42f8fe;};'use strict';var _=require('lodash');var util=require(_0x523e('0x0'));var moment=require('moment');var BPromise=require(_0x523e('0x1'));var rs=require(_0x523e('0x2'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0x523e('0x3'))['db'];var utils=require(_0x523e('0x4'));var logger=require(_0x523e('0x5'))('rpc');var config=require(_0x523e('0x6'));var jayson=require(_0x523e('0x7'));var client=jayson[_0x523e('0x8')][_0x523e('0x9')]({'port':0x232a});config[_0x523e('0xa')]=_[_0x523e('0xb')](config['redis'],{'host':_0x523e('0xc'),'port':0x18eb});var socket=require(_0x523e('0xd'))(new Redis(config['redis']));require('./whatsappQueue.socket')['register'](socket);function respondWithRpcPromise(_0x282a76,_0x1e43d5,_0x3bebfb){return new BPromise(function(_0x432351,_0x5295cc){return client[_0x523e('0xe')](_0x282a76,_0x3bebfb)[_0x523e('0xf')](function(_0x4f5032){logger[_0x523e('0x10')](_0x523e('0x11'),_0x1e43d5,_0x523e('0x12'));logger['debug'](_0x523e('0x13'),_0x1e43d5,_0x523e('0x12'),JSON[_0x523e('0x14')](_0x4f5032));if(_0x4f5032[_0x523e('0x15')]){if(_0x4f5032['error'][_0x523e('0x16')]===0x1f4){logger[_0x523e('0x15')]('WhatsappQueue,\x20%s,\x20%s',_0x1e43d5,_0x4f5032[_0x523e('0x15')]['message']);return _0x5295cc(_0x4f5032[_0x523e('0x15')]['message']);}logger['error']('WhatsappQueue,\x20%s,\x20%s',_0x1e43d5,_0x4f5032[_0x523e('0x15')][_0x523e('0x17')]);return _0x432351(_0x4f5032['error'][_0x523e('0x17')]);}else{logger[_0x523e('0x10')](_0x523e('0x11'),_0x1e43d5,_0x523e('0x12'));_0x432351(_0x4f5032[_0x523e('0x18')][_0x523e('0x17')]);}})['catch'](function(_0x160bbd){logger['error'](_0x523e('0x11'),_0x1e43d5,_0x160bbd);_0x5295cc(_0x160bbd);});});}exports[_0x523e('0x19')]=function(_0x3dc679){var _0x2f6024=this;return new Promise(function(_0x474f09,_0x2c6244){return db[_0x523e('0x1a')][_0x523e('0x1b')]({'raw':_0x3dc679['options']?_0x3dc679[_0x523e('0x1c')][_0x523e('0x1d')]===undefined?!![]:![]:!![],'where':_0x3dc679[_0x523e('0x1c')]?_0x3dc679[_0x523e('0x1c')]['where']||null:null,'attributes':_0x3dc679[_0x523e('0x1c')]?_0x3dc679[_0x523e('0x1c')][_0x523e('0x1e')]||null:null,'limit':_0x3dc679[_0x523e('0x1c')]?_0x3dc679[_0x523e('0x1c')]['limit']||null:null,'include':_0x3dc679[_0x523e('0x1c')]?_0x3dc679[_0x523e('0x1c')][_0x523e('0x1f')]?_[_0x523e('0x20')](_0x3dc679[_0x523e('0x1c')][_0x523e('0x1f')],function(_0x3c61f3){return{'model':db[_0x3c61f3[_0x523e('0x21')]],'as':_0x3c61f3['as'],'attributes':_0x3c61f3['attributes'],'include':_0x3c61f3[_0x523e('0x1f')]?_['map'](_0x3c61f3['include'],function(_0x329fbb){return{'model':db[_0x329fbb['model']],'as':_0x329fbb['as'],'attributes':_0x329fbb[_0x523e('0x1e')],'include':_0x329fbb[_0x523e('0x1f')]?_['map'](_0x329fbb['include'],function(_0x47a93a){return{'model':db[_0x47a93a[_0x523e('0x21')]],'as':_0x47a93a['as'],'attributes':_0x47a93a[_0x523e('0x1e')]};}):[]};}):[]};}):[]:[]})[_0x523e('0xf')](function(_0x201385){logger[_0x523e('0x10')](_0x523e('0x19'),_0x3dc679);logger[_0x523e('0x22')](_0x523e('0x19'),_0x3dc679,JSON[_0x523e('0x14')](_0x201385));_0x474f09(_0x201385);})[_0x523e('0x23')](function(_0x472076){logger[_0x523e('0x15')]('GetWhatsappQueue',_0x472076[_0x523e('0x17')],_0x3dc679);_0x2c6244(_0x2f6024[_0x523e('0x15')](0x1f4,_0x472076[_0x523e('0x17')]));});});};exports[_0x523e('0x24')]=function(_0x461f2c){var _0x368ae4=this;return new Promise(function(_0x4d2fad,_0x1f1949){return db[_0x523e('0x1a')][_0x523e('0x25')]({'raw':_0x461f2c[_0x523e('0x1c')]?_0x461f2c[_0x523e('0x1c')][_0x523e('0x1d')]===undefined?!![]:![]:!![],'where':_0x461f2c[_0x523e('0x1c')]?_0x461f2c[_0x523e('0x1c')][_0x523e('0x26')]||null:null,'attributes':_0x461f2c[_0x523e('0x1c')]?_0x461f2c[_0x523e('0x1c')]['attributes']||null:null,'include':_0x461f2c[_0x523e('0x1c')]?_0x461f2c[_0x523e('0x1c')][_0x523e('0x1f')]?_[_0x523e('0x20')](_0x461f2c[_0x523e('0x1c')][_0x523e('0x1f')],function(_0x4c8a7a){return{'model':db[_0x4c8a7a[_0x523e('0x21')]],'as':_0x4c8a7a['as'],'attributes':_0x4c8a7a[_0x523e('0x1e')],'include':_0x4c8a7a[_0x523e('0x1f')]?_['map'](_0x4c8a7a[_0x523e('0x1f')],function(_0x558de9){return{'model':db[_0x558de9[_0x523e('0x21')]],'as':_0x558de9['as'],'attributes':_0x558de9[_0x523e('0x1e')],'include':_0x558de9[_0x523e('0x1f')]?_[_0x523e('0x20')](_0x558de9[_0x523e('0x1f')],function(_0x163da0){return{'model':db[_0x163da0[_0x523e('0x21')]],'as':_0x163da0['as'],'attributes':_0x163da0[_0x523e('0x1e')]};}):[]};}):[]};}):[]:[]})[_0x523e('0xf')](function(_0x9d5aad){logger[_0x523e('0x10')](_0x523e('0x24'),_0x461f2c);logger[_0x523e('0x22')](_0x523e('0x24'),_0x461f2c,JSON['stringify'](_0x9d5aad));_0x4d2fad(_0x9d5aad);})[_0x523e('0x23')](function(_0x128675){logger['error']('ShowWhatsappQueue',_0x128675['message'],_0x461f2c);_0x1f1949(_0x368ae4[_0x523e('0x15')](0x1f4,_0x128675[_0x523e('0x17')]));});});};