7f89b46d8aa2e27853e58730145584b51d042cf2
[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 _0xc23d=['map','stringify','ShowWhatsappQueue','WhatsappQueue','find','debug','moment','bluebird','../../config/utils','rpc','../../config/environment','jayson/promise','http','redis','defaults','localhost','socket.io-emitter','./whatsappQueue.socket','register','request','then','info','request\x20sent','code','error','WhatsappQueue,\x20%s,\x20%s','message','result','catch','GetWhatsappQueue','options','raw','where','attributes','include','model'];(function(_0x5a6742,_0x59b7f2){var _0x415bce=function(_0x179b1b){while(--_0x179b1b){_0x5a6742['push'](_0x5a6742['shift']());}};_0x415bce(++_0x59b7f2);}(_0xc23d,0x72));var _0xdc23=function(_0x261b8a,_0x553ec4){_0x261b8a=_0x261b8a-0x0;var _0x3455e8=_0xc23d[_0x261b8a];return _0x3455e8;};'use strict';var _=require('lodash');var util=require('util');var moment=require(_0xdc23('0x0'));var BPromise=require(_0xdc23('0x1'));var rs=require('randomstring');var fs=require('fs');var Redis=require('ioredis');var db=require('../../mysqldb')['db'];var utils=require(_0xdc23('0x2'));var logger=require('../../config/logger')(_0xdc23('0x3'));var config=require(_0xdc23('0x4'));var jayson=require(_0xdc23('0x5'));var client=jayson['client'][_0xdc23('0x6')]({'port':0x232a});config[_0xdc23('0x7')]=_[_0xdc23('0x8')](config['redis'],{'host':_0xdc23('0x9'),'port':0x18eb});var socket=require(_0xdc23('0xa'))(new Redis(config[_0xdc23('0x7')]));require(_0xdc23('0xb'))[_0xdc23('0xc')](socket);function respondWithRpcPromise(_0x3f980f,_0xa223a9,_0x2f6772){return new BPromise(function(_0x27a66a,_0x395a7f){return client[_0xdc23('0xd')](_0x3f980f,_0x2f6772)[_0xdc23('0xe')](function(_0x397b77){logger[_0xdc23('0xf')]('WhatsappQueue,\x20%s,\x20%s',_0xa223a9,_0xdc23('0x10'));logger['debug']('WhatsappQueue,\x20%s,\x20%s,\x20%s',_0xa223a9,_0xdc23('0x10'),JSON['stringify'](_0x397b77));if(_0x397b77['error']){if(_0x397b77['error'][_0xdc23('0x11')]===0x1f4){logger[_0xdc23('0x12')](_0xdc23('0x13'),_0xa223a9,_0x397b77['error'][_0xdc23('0x14')]);return _0x395a7f(_0x397b77[_0xdc23('0x12')][_0xdc23('0x14')]);}logger[_0xdc23('0x12')]('WhatsappQueue,\x20%s,\x20%s',_0xa223a9,_0x397b77[_0xdc23('0x12')][_0xdc23('0x14')]);return _0x27a66a(_0x397b77[_0xdc23('0x12')]['message']);}else{logger['info']('WhatsappQueue,\x20%s,\x20%s',_0xa223a9,_0xdc23('0x10'));_0x27a66a(_0x397b77[_0xdc23('0x15')][_0xdc23('0x14')]);}})[_0xdc23('0x16')](function(_0x10ceae){logger[_0xdc23('0x12')]('WhatsappQueue,\x20%s,\x20%s',_0xa223a9,_0x10ceae);_0x395a7f(_0x10ceae);});});}exports[_0xdc23('0x17')]=function(_0x2e6002){var _0x12ae35=this;return new Promise(function(_0x14cf1b,_0x15dac6){return db['WhatsappQueue']['findAll']({'raw':_0x2e6002[_0xdc23('0x18')]?_0x2e6002[_0xdc23('0x18')][_0xdc23('0x19')]===undefined?!![]:![]:!![],'where':_0x2e6002[_0xdc23('0x18')]?_0x2e6002[_0xdc23('0x18')][_0xdc23('0x1a')]||null:null,'attributes':_0x2e6002['options']?_0x2e6002[_0xdc23('0x18')][_0xdc23('0x1b')]||null:null,'limit':_0x2e6002[_0xdc23('0x18')]?_0x2e6002[_0xdc23('0x18')]['limit']||null:null,'include':_0x2e6002['options']?_0x2e6002[_0xdc23('0x18')][_0xdc23('0x1c')]?_['map'](_0x2e6002['options'][_0xdc23('0x1c')],function(_0x468af){return{'model':db[_0x468af[_0xdc23('0x1d')]],'as':_0x468af['as'],'attributes':_0x468af[_0xdc23('0x1b')],'include':_0x468af[_0xdc23('0x1c')]?_[_0xdc23('0x1e')](_0x468af[_0xdc23('0x1c')],function(_0x58cfb6){return{'model':db[_0x58cfb6[_0xdc23('0x1d')]],'as':_0x58cfb6['as'],'attributes':_0x58cfb6[_0xdc23('0x1b')],'include':_0x58cfb6[_0xdc23('0x1c')]?_['map'](_0x58cfb6['include'],function(_0x474ccb){return{'model':db[_0x474ccb['model']],'as':_0x474ccb['as'],'attributes':_0x474ccb[_0xdc23('0x1b')]};}):[]};}):[]};}):[]:[]})[_0xdc23('0xe')](function(_0x590d91){logger[_0xdc23('0xf')](_0xdc23('0x17'),_0x2e6002);logger['debug'](_0xdc23('0x17'),_0x2e6002,JSON[_0xdc23('0x1f')](_0x590d91));_0x14cf1b(_0x590d91);})[_0xdc23('0x16')](function(_0x4b0f13){logger[_0xdc23('0x12')]('GetWhatsappQueue',_0x4b0f13[_0xdc23('0x14')],_0x2e6002);_0x15dac6(_0x12ae35[_0xdc23('0x12')](0x1f4,_0x4b0f13[_0xdc23('0x14')]));});});};exports[_0xdc23('0x20')]=function(_0x282eb9){var _0x1cb329=this;return new Promise(function(_0xf10562,_0x50eb6f){return db[_0xdc23('0x21')][_0xdc23('0x22')]({'raw':_0x282eb9[_0xdc23('0x18')]?_0x282eb9[_0xdc23('0x18')][_0xdc23('0x19')]===undefined?!![]:![]:!![],'where':_0x282eb9['options']?_0x282eb9[_0xdc23('0x18')]['where']||null:null,'attributes':_0x282eb9[_0xdc23('0x18')]?_0x282eb9['options'][_0xdc23('0x1b')]||null:null,'include':_0x282eb9[_0xdc23('0x18')]?_0x282eb9[_0xdc23('0x18')][_0xdc23('0x1c')]?_[_0xdc23('0x1e')](_0x282eb9['options'][_0xdc23('0x1c')],function(_0x19a241){return{'model':db[_0x19a241[_0xdc23('0x1d')]],'as':_0x19a241['as'],'attributes':_0x19a241[_0xdc23('0x1b')],'include':_0x19a241[_0xdc23('0x1c')]?_[_0xdc23('0x1e')](_0x19a241[_0xdc23('0x1c')],function(_0xf10a5f){return{'model':db[_0xf10a5f[_0xdc23('0x1d')]],'as':_0xf10a5f['as'],'attributes':_0xf10a5f['attributes'],'include':_0xf10a5f[_0xdc23('0x1c')]?_[_0xdc23('0x1e')](_0xf10a5f['include'],function(_0x495340){return{'model':db[_0x495340[_0xdc23('0x1d')]],'as':_0x495340['as'],'attributes':_0x495340[_0xdc23('0x1b')]};}):[]};}):[]};}):[]:[]})[_0xdc23('0xe')](function(_0x5c03db){logger[_0xdc23('0xf')](_0xdc23('0x20'),_0x282eb9);logger[_0xdc23('0x23')](_0xdc23('0x20'),_0x282eb9,JSON['stringify'](_0x5c03db));_0xf10562(_0x5c03db);})[_0xdc23('0x16')](function(_0x5ba249){logger[_0xdc23('0x12')](_0xdc23('0x20'),_0x5ba249['message'],_0x282eb9);_0x50eb6f(_0x1cb329[_0xdc23('0x12')](0x1f4,_0x5ba249[_0xdc23('0x14')]));});});};