Built motion from commit (unavailable).|2.5.26
[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 _0xce9c=['findAll','options','raw','where','attributes','limit','include','model','map','catch','ShowWhatsappQueue','find','util','randomstring','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','http','redis','localhost','socket.io-emitter','register','request','then','debug','WhatsappQueue,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','WhatsappQueue,\x20%s,\x20%s','info','result','GetWhatsappQueue'];(function(_0xef2a14,_0x4c359a){var _0x242a4d=function(_0x3227c9){while(--_0x3227c9){_0xef2a14['push'](_0xef2a14['shift']());}};_0x242a4d(++_0x4c359a);}(_0xce9c,0x13c));var _0xcce9=function(_0x4acfa2,_0x526ee0){_0x4acfa2=_0x4acfa2-0x0;var _0x4ceb70=_0xce9c[_0x4acfa2];return _0x4ceb70;};'use strict';var _=require('lodash');var util=require(_0xcce9('0x0'));var moment=require('moment');var BPromise=require('bluebird');var rs=require(_0xcce9('0x1'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0xcce9('0x2'))['db'];var utils=require(_0xcce9('0x3'));var logger=require(_0xcce9('0x4'))(_0xcce9('0x5'));var config=require(_0xcce9('0x6'));var jayson=require(_0xcce9('0x7'));var client=jayson['client'][_0xcce9('0x8')]({'port':0x232a});config[_0xcce9('0x9')]=_['defaults'](config['redis'],{'host':_0xcce9('0xa'),'port':0x18eb});var socket=require(_0xcce9('0xb'))(new Redis(config[_0xcce9('0x9')]));require('./whatsappQueue.socket')[_0xcce9('0xc')](socket);function respondWithRpcPromise(_0xf448f1,_0x1871e1,_0x5d1b7a){return new BPromise(function(_0x216c16,_0x4f16ef){return client[_0xcce9('0xd')](_0xf448f1,_0x5d1b7a)[_0xcce9('0xe')](function(_0x3beb16){logger['info']('WhatsappQueue,\x20%s,\x20%s',_0x1871e1,'request\x20sent');logger[_0xcce9('0xf')](_0xcce9('0x10'),_0x1871e1,_0xcce9('0x11'),JSON[_0xcce9('0x12')](_0x3beb16));if(_0x3beb16[_0xcce9('0x13')]){if(_0x3beb16[_0xcce9('0x13')][_0xcce9('0x14')]===0x1f4){logger[_0xcce9('0x13')]('WhatsappQueue,\x20%s,\x20%s',_0x1871e1,_0x3beb16[_0xcce9('0x13')][_0xcce9('0x15')]);return _0x4f16ef(_0x3beb16['error'][_0xcce9('0x15')]);}logger['error'](_0xcce9('0x16'),_0x1871e1,_0x3beb16[_0xcce9('0x13')][_0xcce9('0x15')]);return _0x216c16(_0x3beb16[_0xcce9('0x13')][_0xcce9('0x15')]);}else{logger[_0xcce9('0x17')](_0xcce9('0x16'),_0x1871e1,_0xcce9('0x11'));_0x216c16(_0x3beb16[_0xcce9('0x18')][_0xcce9('0x15')]);}})['catch'](function(_0x28b929){logger[_0xcce9('0x13')](_0xcce9('0x16'),_0x1871e1,_0x28b929);_0x4f16ef(_0x28b929);});});}exports[_0xcce9('0x19')]=function(_0x1083f0){var _0x2b9c8c=this;return new Promise(function(_0x25227f,_0x29a982){return db['WhatsappQueue'][_0xcce9('0x1a')]({'raw':_0x1083f0[_0xcce9('0x1b')]?_0x1083f0[_0xcce9('0x1b')][_0xcce9('0x1c')]===undefined?!![]:![]:!![],'where':_0x1083f0[_0xcce9('0x1b')]?_0x1083f0[_0xcce9('0x1b')][_0xcce9('0x1d')]||null:null,'attributes':_0x1083f0[_0xcce9('0x1b')]?_0x1083f0[_0xcce9('0x1b')][_0xcce9('0x1e')]||null:null,'limit':_0x1083f0[_0xcce9('0x1b')]?_0x1083f0[_0xcce9('0x1b')][_0xcce9('0x1f')]||null:null,'include':_0x1083f0[_0xcce9('0x1b')]?_0x1083f0[_0xcce9('0x1b')]['include']?_['map'](_0x1083f0[_0xcce9('0x1b')][_0xcce9('0x20')],function(_0x38757d){return{'model':db[_0x38757d[_0xcce9('0x21')]],'as':_0x38757d['as'],'attributes':_0x38757d[_0xcce9('0x1e')],'include':_0x38757d[_0xcce9('0x20')]?_[_0xcce9('0x22')](_0x38757d[_0xcce9('0x20')],function(_0x40f841){return{'model':db[_0x40f841[_0xcce9('0x21')]],'as':_0x40f841['as'],'attributes':_0x40f841[_0xcce9('0x1e')],'include':_0x40f841[_0xcce9('0x20')]?_['map'](_0x40f841[_0xcce9('0x20')],function(_0x5e940f){return{'model':db[_0x5e940f[_0xcce9('0x21')]],'as':_0x5e940f['as'],'attributes':_0x5e940f[_0xcce9('0x1e')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x2acbed){logger[_0xcce9('0x17')](_0xcce9('0x19'),_0x1083f0);logger['debug']('GetWhatsappQueue',_0x1083f0,JSON[_0xcce9('0x12')](_0x2acbed));_0x25227f(_0x2acbed);})[_0xcce9('0x23')](function(_0x4ea977){logger[_0xcce9('0x13')](_0xcce9('0x19'),_0x4ea977[_0xcce9('0x15')],_0x1083f0);_0x29a982(_0x2b9c8c[_0xcce9('0x13')](0x1f4,_0x4ea977[_0xcce9('0x15')]));});});};exports[_0xcce9('0x24')]=function(_0x4cc680){var _0xa30e42=this;return new Promise(function(_0xdfc29,_0x2bc760){return db['WhatsappQueue'][_0xcce9('0x25')]({'raw':_0x4cc680[_0xcce9('0x1b')]?_0x4cc680[_0xcce9('0x1b')][_0xcce9('0x1c')]===undefined?!![]:![]:!![],'where':_0x4cc680[_0xcce9('0x1b')]?_0x4cc680[_0xcce9('0x1b')]['where']||null:null,'attributes':_0x4cc680[_0xcce9('0x1b')]?_0x4cc680[_0xcce9('0x1b')][_0xcce9('0x1e')]||null:null,'include':_0x4cc680[_0xcce9('0x1b')]?_0x4cc680[_0xcce9('0x1b')][_0xcce9('0x20')]?_[_0xcce9('0x22')](_0x4cc680[_0xcce9('0x1b')][_0xcce9('0x20')],function(_0x1bf1d4){return{'model':db[_0x1bf1d4[_0xcce9('0x21')]],'as':_0x1bf1d4['as'],'attributes':_0x1bf1d4[_0xcce9('0x1e')],'include':_0x1bf1d4[_0xcce9('0x20')]?_['map'](_0x1bf1d4[_0xcce9('0x20')],function(_0x4aacec){return{'model':db[_0x4aacec['model']],'as':_0x4aacec['as'],'attributes':_0x4aacec['attributes'],'include':_0x4aacec[_0xcce9('0x20')]?_[_0xcce9('0x22')](_0x4aacec[_0xcce9('0x20')],function(_0x24e6ac){return{'model':db[_0x24e6ac['model']],'as':_0x24e6ac['as'],'attributes':_0x24e6ac[_0xcce9('0x1e')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x2a7f3d){logger['info'](_0xcce9('0x24'),_0x4cc680);logger[_0xcce9('0xf')](_0xcce9('0x24'),_0x4cc680,JSON['stringify'](_0x2a7f3d));_0xdfc29(_0x2a7f3d);})[_0xcce9('0x23')](function(_0x1b4838){logger[_0xcce9('0x13')](_0xcce9('0x24'),_0x1b4838[_0xcce9('0x15')],_0x4cc680);_0x2bc760(_0xa30e42['error'](0x1f4,_0x1b4838[_0xcce9('0x15')]));});});};