a5396d5c932d9bd01264ff7d8fe91b5f53f0776f
[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 _0x6a40=['debug','WhatsappMessage,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','result','catch','WhatsappMessage','create','body','options','CreateWhatsappMessage','lodash','ioredis','rpc','../../config/environment','jayson/promise','client','http','redis','defaults','socket.io-emitter','./whatsappMessage.socket','register','request','then','info','WhatsappMessage,\x20%s,\x20%s'];(function(_0x21a757,_0x140d70){var _0x2da773=function(_0x4a2a22){while(--_0x4a2a22){_0x21a757['push'](_0x21a757['shift']());}};_0x2da773(++_0x140d70);}(_0x6a40,0xc2));var _0x06a4=function(_0x20ea53,_0xde3e0a){_0x20ea53=_0x20ea53-0x0;var _0x4ddf4e=_0x6a40[_0x20ea53];return _0x4ddf4e;};'use strict';var _=require(_0x06a4('0x0'));var util=require('util');var moment=require('moment');var BPromise=require('bluebird');var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x06a4('0x1'));var db=require('../../mysqldb')['db'];var utils=require('../../config/utils');var logger=require('../../config/logger')(_0x06a4('0x2'));var config=require(_0x06a4('0x3'));var jayson=require(_0x06a4('0x4'));var client=jayson[_0x06a4('0x5')][_0x06a4('0x6')]({'port':0x232a});config[_0x06a4('0x7')]=_[_0x06a4('0x8')](config[_0x06a4('0x7')],{'host':'localhost','port':0x18eb});var socket=require(_0x06a4('0x9'))(new Redis(config['redis']));require(_0x06a4('0xa'))[_0x06a4('0xb')](socket);function respondWithRpcPromise(_0x55ef90,_0x17e484,_0x24e78b){return new BPromise(function(_0x1084e1,_0x508c91){return client[_0x06a4('0xc')](_0x55ef90,_0x24e78b)[_0x06a4('0xd')](function(_0x29479c){logger[_0x06a4('0xe')](_0x06a4('0xf'),_0x17e484,'request\x20sent');logger[_0x06a4('0x10')](_0x06a4('0x11'),_0x17e484,_0x06a4('0x12'),JSON[_0x06a4('0x13')](_0x29479c));if(_0x29479c[_0x06a4('0x14')]){if(_0x29479c[_0x06a4('0x14')][_0x06a4('0x15')]===0x1f4){logger[_0x06a4('0x14')](_0x06a4('0xf'),_0x17e484,_0x29479c['error'][_0x06a4('0x16')]);return _0x508c91(_0x29479c[_0x06a4('0x14')][_0x06a4('0x16')]);}logger[_0x06a4('0x14')]('WhatsappMessage,\x20%s,\x20%s',_0x17e484,_0x29479c[_0x06a4('0x14')][_0x06a4('0x16')]);return _0x1084e1(_0x29479c[_0x06a4('0x14')][_0x06a4('0x16')]);}else{logger[_0x06a4('0xe')](_0x06a4('0xf'),_0x17e484,_0x06a4('0x12'));_0x1084e1(_0x29479c[_0x06a4('0x17')][_0x06a4('0x16')]);}})[_0x06a4('0x18')](function(_0x4acfe8){logger[_0x06a4('0x14')](_0x06a4('0xf'),_0x17e484,_0x4acfe8);_0x508c91(_0x4acfe8);});});}exports['CreateWhatsappMessage']=function(_0x5f756f){var _0xd163ae=this;return new Promise(function(_0x28ddd7,_0x46a5fc){return db[_0x06a4('0x19')][_0x06a4('0x1a')](_0x5f756f[_0x06a4('0x1b')],{'raw':_0x5f756f[_0x06a4('0x1c')]?_0x5f756f[_0x06a4('0x1c')]['raw']===undefined?!![]:![]:!![]})[_0x06a4('0xd')](function(_0xfa3bd3){logger[_0x06a4('0xe')](_0x06a4('0x1d'),_0x5f756f);logger['debug']('CreateWhatsappMessage',_0x5f756f,JSON[_0x06a4('0x13')](_0xfa3bd3));_0x28ddd7(_0xfa3bd3);})[_0x06a4('0x18')](function(_0x344ef6){logger[_0x06a4('0x14')](_0x06a4('0x1d'),_0x344ef6['message'],_0x5f756f);_0x46a5fc(_0xd163ae[_0x06a4('0x14')](0x1f4,_0x344ef6[_0x06a4('0x16')]));});});};