Built motion from commit 497d3d92.|2.5.43
[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 _0x2795=['bluebird','ioredis','../../config/utils','rpc','client','http','redis','defaults','localhost','socket.io-emitter','./whatsappQueue.socket','register','request','then','WhatsappQueue,\x20%s,\x20%s','debug','WhatsappQueue,\x20%s,\x20%s,\x20%s','stringify','error','code','message','request\x20sent','result','GetWhatsappQueue','findAll','options','attributes','limit','map','include','model','info','catch','ShowWhatsappQueue','WhatsappQueue','where','lodash'];(function(_0x3ab51d,_0x2fa01d){var _0x29a04e=function(_0x7807b0){while(--_0x7807b0){_0x3ab51d['push'](_0x3ab51d['shift']());}};_0x29a04e(++_0x2fa01d);}(_0x2795,0x1e0));var _0x5279=function(_0x38fa4c,_0x439194){_0x38fa4c=_0x38fa4c-0x0;var _0x29fc0b=_0x2795[_0x38fa4c];return _0x29fc0b;};'use strict';var _=require(_0x5279('0x0'));var util=require('util');var moment=require('moment');var BPromise=require(_0x5279('0x1'));var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x5279('0x2'));var db=require('../../mysqldb')['db'];var utils=require(_0x5279('0x3'));var logger=require('../../config/logger')(_0x5279('0x4'));var config=require('../../config/environment');var jayson=require('jayson/promise');var client=jayson[_0x5279('0x5')][_0x5279('0x6')]({'port':0x232a});config[_0x5279('0x7')]=_[_0x5279('0x8')](config[_0x5279('0x7')],{'host':_0x5279('0x9'),'port':0x18eb});var socket=require(_0x5279('0xa'))(new Redis(config[_0x5279('0x7')]));require(_0x5279('0xb'))[_0x5279('0xc')](socket);function respondWithRpcPromise(_0x51d4e2,_0x20fde1,_0x2e21b6){return new BPromise(function(_0x40af86,_0x2638b6){return client[_0x5279('0xd')](_0x51d4e2,_0x2e21b6)[_0x5279('0xe')](function(_0x5b33fe){logger['info'](_0x5279('0xf'),_0x20fde1,'request\x20sent');logger[_0x5279('0x10')](_0x5279('0x11'),_0x20fde1,'request\x20sent',JSON[_0x5279('0x12')](_0x5b33fe));if(_0x5b33fe[_0x5279('0x13')]){if(_0x5b33fe['error'][_0x5279('0x14')]===0x1f4){logger[_0x5279('0x13')](_0x5279('0xf'),_0x20fde1,_0x5b33fe[_0x5279('0x13')][_0x5279('0x15')]);return _0x2638b6(_0x5b33fe[_0x5279('0x13')][_0x5279('0x15')]);}logger['error'](_0x5279('0xf'),_0x20fde1,_0x5b33fe[_0x5279('0x13')][_0x5279('0x15')]);return _0x40af86(_0x5b33fe[_0x5279('0x13')][_0x5279('0x15')]);}else{logger['info'](_0x5279('0xf'),_0x20fde1,_0x5279('0x16'));_0x40af86(_0x5b33fe[_0x5279('0x17')][_0x5279('0x15')]);}})['catch'](function(_0x20ca9c){logger[_0x5279('0x13')](_0x5279('0xf'),_0x20fde1,_0x20ca9c);_0x2638b6(_0x20ca9c);});});}exports[_0x5279('0x18')]=function(_0x108d32){var _0x56239f=this;return new Promise(function(_0x427106,_0x2f5976){return db['WhatsappQueue'][_0x5279('0x19')]({'raw':_0x108d32[_0x5279('0x1a')]?_0x108d32['options']['raw']===undefined?!![]:![]:!![],'where':_0x108d32[_0x5279('0x1a')]?_0x108d32[_0x5279('0x1a')]['where']||null:null,'attributes':_0x108d32['options']?_0x108d32[_0x5279('0x1a')][_0x5279('0x1b')]||null:null,'limit':_0x108d32[_0x5279('0x1a')]?_0x108d32['options'][_0x5279('0x1c')]||null:null,'include':_0x108d32['options']?_0x108d32[_0x5279('0x1a')]['include']?_[_0x5279('0x1d')](_0x108d32[_0x5279('0x1a')][_0x5279('0x1e')],function(_0x41104d){return{'model':db[_0x41104d[_0x5279('0x1f')]],'as':_0x41104d['as'],'attributes':_0x41104d[_0x5279('0x1b')],'include':_0x41104d[_0x5279('0x1e')]?_[_0x5279('0x1d')](_0x41104d[_0x5279('0x1e')],function(_0x10083c){return{'model':db[_0x10083c[_0x5279('0x1f')]],'as':_0x10083c['as'],'attributes':_0x10083c[_0x5279('0x1b')],'include':_0x10083c['include']?_['map'](_0x10083c[_0x5279('0x1e')],function(_0x4a8472){return{'model':db[_0x4a8472['model']],'as':_0x4a8472['as'],'attributes':_0x4a8472[_0x5279('0x1b')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x9e70bc){logger[_0x5279('0x20')](_0x5279('0x18'),_0x108d32);logger[_0x5279('0x10')](_0x5279('0x18'),_0x108d32,JSON['stringify'](_0x9e70bc));_0x427106(_0x9e70bc);})[_0x5279('0x21')](function(_0x292f2d){logger[_0x5279('0x13')]('GetWhatsappQueue',_0x292f2d[_0x5279('0x15')],_0x108d32);_0x2f5976(_0x56239f[_0x5279('0x13')](0x1f4,_0x292f2d[_0x5279('0x15')]));});});};exports[_0x5279('0x22')]=function(_0x56e3ea){var _0x37509e=this;return new Promise(function(_0x598f95,_0x4a0ade){return db[_0x5279('0x23')]['find']({'raw':_0x56e3ea[_0x5279('0x1a')]?_0x56e3ea[_0x5279('0x1a')]['raw']===undefined?!![]:![]:!![],'where':_0x56e3ea['options']?_0x56e3ea[_0x5279('0x1a')][_0x5279('0x24')]||null:null,'attributes':_0x56e3ea[_0x5279('0x1a')]?_0x56e3ea[_0x5279('0x1a')][_0x5279('0x1b')]||null:null,'include':_0x56e3ea[_0x5279('0x1a')]?_0x56e3ea[_0x5279('0x1a')][_0x5279('0x1e')]?_['map'](_0x56e3ea['options'][_0x5279('0x1e')],function(_0x240d1f){return{'model':db[_0x240d1f[_0x5279('0x1f')]],'as':_0x240d1f['as'],'attributes':_0x240d1f[_0x5279('0x1b')],'include':_0x240d1f['include']?_['map'](_0x240d1f[_0x5279('0x1e')],function(_0x390f0c){return{'model':db[_0x390f0c[_0x5279('0x1f')]],'as':_0x390f0c['as'],'attributes':_0x390f0c[_0x5279('0x1b')],'include':_0x390f0c[_0x5279('0x1e')]?_['map'](_0x390f0c['include'],function(_0xf12f09){return{'model':db[_0xf12f09['model']],'as':_0xf12f09['as'],'attributes':_0xf12f09[_0x5279('0x1b')]};}):[]};}):[]};}):[]:[]})[_0x5279('0xe')](function(_0x3ba9ed){logger[_0x5279('0x20')]('ShowWhatsappQueue',_0x56e3ea);logger['debug'](_0x5279('0x22'),_0x56e3ea,JSON[_0x5279('0x12')](_0x3ba9ed));_0x598f95(_0x3ba9ed);})[_0x5279('0x21')](function(_0x37d24a){logger[_0x5279('0x13')]('ShowWhatsappQueue',_0x37d24a[_0x5279('0x15')],_0x56e3ea);_0x4a0ade(_0x37509e[_0x5279('0x13')](0x1f4,_0x37d24a[_0x5279('0x15')]));});});};