47d964df8943d31fb79f92cfca54882081b0533f
[motion2.git] / server / api / whatsappMessage / whatsappMessage.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 _0x7458=['register','then','info','request\x20sent','debug','WhatsappMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','WhatsappMessage,\x20%s,\x20%s','message','result','catch','CreateWhatsappMessage','WhatsappMessage','create','body','options','raw','util','moment','randomstring','../../mysqldb','rpc','jayson/promise','client','http','redis','defaults','localhost','./whatsappMessage.socket'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x7458,0x149));var _0x8745=function(_0x254d20,_0x47176e){_0x254d20=_0x254d20-0x0;var _0x219511=_0x7458[_0x254d20];return _0x219511;};'use strict';var _=require('lodash');var util=require(_0x8745('0x0'));var moment=require(_0x8745('0x1'));var BPromise=require('bluebird');var rs=require(_0x8745('0x2'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0x8745('0x3'))['db'];var utils=require('../../config/utils');var logger=require('../../config/logger')(_0x8745('0x4'));var config=require('../../config/environment');var jayson=require(_0x8745('0x5'));var client=jayson[_0x8745('0x6')][_0x8745('0x7')]({'port':0x232a});config[_0x8745('0x8')]=_[_0x8745('0x9')](config[_0x8745('0x8')],{'host':_0x8745('0xa'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x8745('0x8')]));require(_0x8745('0xb'))[_0x8745('0xc')](socket);function respondWithRpcPromise(_0x2644e9,_0x5f0c10,_0x5ccc9a){return new BPromise(function(_0x12e99d,_0x213872){return client['request'](_0x2644e9,_0x5ccc9a)[_0x8745('0xd')](function(_0x57b998){logger[_0x8745('0xe')]('WhatsappMessage,\x20%s,\x20%s',_0x5f0c10,_0x8745('0xf'));logger[_0x8745('0x10')](_0x8745('0x11'),_0x5f0c10,_0x8745('0xf'),JSON[_0x8745('0x12')](_0x57b998));if(_0x57b998['error']){if(_0x57b998[_0x8745('0x13')][_0x8745('0x14')]===0x1f4){logger[_0x8745('0x13')](_0x8745('0x15'),_0x5f0c10,_0x57b998[_0x8745('0x13')][_0x8745('0x16')]);return _0x213872(_0x57b998[_0x8745('0x13')]['message']);}logger[_0x8745('0x13')](_0x8745('0x15'),_0x5f0c10,_0x57b998[_0x8745('0x13')][_0x8745('0x16')]);return _0x12e99d(_0x57b998['error'][_0x8745('0x16')]);}else{logger[_0x8745('0xe')](_0x8745('0x15'),_0x5f0c10,'request\x20sent');_0x12e99d(_0x57b998[_0x8745('0x17')]['message']);}})[_0x8745('0x18')](function(_0x2c68fb){logger['error'](_0x8745('0x15'),_0x5f0c10,_0x2c68fb);_0x213872(_0x2c68fb);});});}exports[_0x8745('0x19')]=function(_0x31b165){var _0x42792f=this;return new Promise(function(_0x1237a3,_0xff4a1d){return db[_0x8745('0x1a')][_0x8745('0x1b')](_0x31b165[_0x8745('0x1c')],{'raw':_0x31b165[_0x8745('0x1d')]?_0x31b165['options'][_0x8745('0x1e')]===undefined?!![]:![]:!![]})['then'](function(_0x43773d){logger['info'](_0x8745('0x19'),_0x31b165);logger[_0x8745('0x10')](_0x8745('0x19'),_0x31b165,JSON['stringify'](_0x43773d));_0x1237a3(_0x43773d);})[_0x8745('0x18')](function(_0x561270){logger['error'](_0x8745('0x19'),_0x561270[_0x8745('0x16')],_0x31b165);_0xff4a1d(_0x42792f[_0x8745('0x13')](0x1f4,_0x561270[_0x8745('0x16')]));});});};