647179990c337733421aee107fe277c76063303e
[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 _0xa4be=['./whatsappQueue.socket','register','request','then','debug','WhatsappQueue,\x20%s,\x20%s,\x20%s','stringify','error','WhatsappQueue,\x20%s,\x20%s','message','info','request\x20sent','catch','GetWhatsappQueue','findAll','options','raw','where','attributes','limit','include','map','model','ShowWhatsappQueue','WhatsappQueue','find','lodash','moment','randomstring','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','http','redis','defaults','localhost','socket.io-emitter'];(function(_0x224549,_0x1093ae){var _0x2cc567=function(_0x58e060){while(--_0x58e060){_0x224549['push'](_0x224549['shift']());}};_0x2cc567(++_0x1093ae);}(_0xa4be,0x15a));var _0xea4b=function(_0x34e3fc,_0xcd76af){_0x34e3fc=_0x34e3fc-0x0;var _0x3d4e25=_0xa4be[_0x34e3fc];return _0x3d4e25;};'use strict';var _=require(_0xea4b('0x0'));var util=require('util');var moment=require(_0xea4b('0x1'));var BPromise=require('bluebird');var rs=require(_0xea4b('0x2'));var fs=require('fs');var Redis=require('ioredis');var db=require('../../mysqldb')['db'];var utils=require(_0xea4b('0x3'));var logger=require(_0xea4b('0x4'))(_0xea4b('0x5'));var config=require(_0xea4b('0x6'));var jayson=require(_0xea4b('0x7'));var client=jayson[_0xea4b('0x8')][_0xea4b('0x9')]({'port':0x232a});config[_0xea4b('0xa')]=_[_0xea4b('0xb')](config['redis'],{'host':_0xea4b('0xc'),'port':0x18eb});var socket=require(_0xea4b('0xd'))(new Redis(config[_0xea4b('0xa')]));require(_0xea4b('0xe'))[_0xea4b('0xf')](socket);function respondWithRpcPromise(_0xc01de6,_0x17bf47,_0x14181b){return new BPromise(function(_0x38f8dc,_0x4900bf){return client[_0xea4b('0x10')](_0xc01de6,_0x14181b)[_0xea4b('0x11')](function(_0x5f3029){logger['info']('WhatsappQueue,\x20%s,\x20%s',_0x17bf47,'request\x20sent');logger[_0xea4b('0x12')](_0xea4b('0x13'),_0x17bf47,'request\x20sent',JSON[_0xea4b('0x14')](_0x5f3029));if(_0x5f3029[_0xea4b('0x15')]){if(_0x5f3029[_0xea4b('0x15')]['code']===0x1f4){logger[_0xea4b('0x15')](_0xea4b('0x16'),_0x17bf47,_0x5f3029[_0xea4b('0x15')]['message']);return _0x4900bf(_0x5f3029['error']['message']);}logger[_0xea4b('0x15')](_0xea4b('0x16'),_0x17bf47,_0x5f3029[_0xea4b('0x15')][_0xea4b('0x17')]);return _0x38f8dc(_0x5f3029[_0xea4b('0x15')][_0xea4b('0x17')]);}else{logger[_0xea4b('0x18')](_0xea4b('0x16'),_0x17bf47,_0xea4b('0x19'));_0x38f8dc(_0x5f3029['result']['message']);}})[_0xea4b('0x1a')](function(_0xa2ad20){logger[_0xea4b('0x15')](_0xea4b('0x16'),_0x17bf47,_0xa2ad20);_0x4900bf(_0xa2ad20);});});}exports[_0xea4b('0x1b')]=function(_0x5cf663){var _0x20b0ac=this;return new Promise(function(_0x48c4ea,_0x14ff20){return db['WhatsappQueue'][_0xea4b('0x1c')]({'raw':_0x5cf663[_0xea4b('0x1d')]?_0x5cf663[_0xea4b('0x1d')][_0xea4b('0x1e')]===undefined?!![]:![]:!![],'where':_0x5cf663[_0xea4b('0x1d')]?_0x5cf663[_0xea4b('0x1d')][_0xea4b('0x1f')]||null:null,'attributes':_0x5cf663[_0xea4b('0x1d')]?_0x5cf663['options'][_0xea4b('0x20')]||null:null,'limit':_0x5cf663[_0xea4b('0x1d')]?_0x5cf663[_0xea4b('0x1d')][_0xea4b('0x21')]||null:null,'include':_0x5cf663[_0xea4b('0x1d')]?_0x5cf663['options'][_0xea4b('0x22')]?_[_0xea4b('0x23')](_0x5cf663['options'][_0xea4b('0x22')],function(_0x538e49){return{'model':db[_0x538e49[_0xea4b('0x24')]],'as':_0x538e49['as'],'attributes':_0x538e49[_0xea4b('0x20')],'include':_0x538e49[_0xea4b('0x22')]?_[_0xea4b('0x23')](_0x538e49[_0xea4b('0x22')],function(_0x54521f){return{'model':db[_0x54521f[_0xea4b('0x24')]],'as':_0x54521f['as'],'attributes':_0x54521f[_0xea4b('0x20')],'include':_0x54521f[_0xea4b('0x22')]?_[_0xea4b('0x23')](_0x54521f['include'],function(_0x59a39b){return{'model':db[_0x59a39b['model']],'as':_0x59a39b['as'],'attributes':_0x59a39b[_0xea4b('0x20')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x1ad36d){logger[_0xea4b('0x18')](_0xea4b('0x1b'),_0x5cf663);logger[_0xea4b('0x12')](_0xea4b('0x1b'),_0x5cf663,JSON[_0xea4b('0x14')](_0x1ad36d));_0x48c4ea(_0x1ad36d);})[_0xea4b('0x1a')](function(_0x1654a5){logger[_0xea4b('0x15')](_0xea4b('0x1b'),_0x1654a5[_0xea4b('0x17')],_0x5cf663);_0x14ff20(_0x20b0ac[_0xea4b('0x15')](0x1f4,_0x1654a5[_0xea4b('0x17')]));});});};exports[_0xea4b('0x25')]=function(_0x3518ce){var _0x16f856=this;return new Promise(function(_0x13060e,_0x5dab20){return db[_0xea4b('0x26')][_0xea4b('0x27')]({'raw':_0x3518ce['options']?_0x3518ce['options'][_0xea4b('0x1e')]===undefined?!![]:![]:!![],'where':_0x3518ce['options']?_0x3518ce[_0xea4b('0x1d')][_0xea4b('0x1f')]||null:null,'attributes':_0x3518ce['options']?_0x3518ce[_0xea4b('0x1d')][_0xea4b('0x20')]||null:null,'include':_0x3518ce[_0xea4b('0x1d')]?_0x3518ce[_0xea4b('0x1d')]['include']?_[_0xea4b('0x23')](_0x3518ce[_0xea4b('0x1d')][_0xea4b('0x22')],function(_0x3bca36){return{'model':db[_0x3bca36[_0xea4b('0x24')]],'as':_0x3bca36['as'],'attributes':_0x3bca36[_0xea4b('0x20')],'include':_0x3bca36[_0xea4b('0x22')]?_[_0xea4b('0x23')](_0x3bca36[_0xea4b('0x22')],function(_0x242bef){return{'model':db[_0x242bef[_0xea4b('0x24')]],'as':_0x242bef['as'],'attributes':_0x242bef[_0xea4b('0x20')],'include':_0x242bef[_0xea4b('0x22')]?_[_0xea4b('0x23')](_0x242bef[_0xea4b('0x22')],function(_0x326537){return{'model':db[_0x326537[_0xea4b('0x24')]],'as':_0x326537['as'],'attributes':_0x326537[_0xea4b('0x20')]};}):[]};}):[]};}):[]:[]})[_0xea4b('0x11')](function(_0x3951cf){logger[_0xea4b('0x18')]('ShowWhatsappQueue',_0x3518ce);logger[_0xea4b('0x12')](_0xea4b('0x25'),_0x3518ce,JSON[_0xea4b('0x14')](_0x3951cf));_0x13060e(_0x3951cf);})[_0xea4b('0x1a')](function(_0x5a77d0){logger[_0xea4b('0x15')](_0xea4b('0x25'),_0x5a77d0['message'],_0x3518ce);_0x5dab20(_0x16f856['error'](0x1f4,_0x5a77d0[_0xea4b('0x17')]));});});};