85ab374847391c71a44f8e5e233f01fa128a517c
[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 _0xace4=['CreateWhatsappMessage','WhatsappMessage','create','options','raw','then','stringify','lodash','util','moment','randomstring','ioredis','../../mysqldb','../../config/utils','rpc','client','http','redis','localhost','socket.io-emitter','./whatsappMessage.socket','register','info','WhatsappMessage,\x20%s,\x20%s','request\x20sent','debug','WhatsappMessage,\x20%s,\x20%s,\x20%s','error','code','message','result','catch'];(function(_0x3e9b5c,_0x54ba4f){var _0x391e74=function(_0x39e3ef){while(--_0x39e3ef){_0x3e9b5c['push'](_0x3e9b5c['shift']());}};_0x391e74(++_0x54ba4f);}(_0xace4,0xe7));var _0x4ace=function(_0x5550b3,_0x2d0ee0){_0x5550b3=_0x5550b3-0x0;var _0x4b8fc4=_0xace4[_0x5550b3];return _0x4b8fc4;};'use strict';var _=require(_0x4ace('0x0'));var util=require(_0x4ace('0x1'));var moment=require(_0x4ace('0x2'));var BPromise=require('bluebird');var rs=require(_0x4ace('0x3'));var fs=require('fs');var Redis=require(_0x4ace('0x4'));var db=require(_0x4ace('0x5'))['db'];var utils=require(_0x4ace('0x6'));var logger=require('../../config/logger')(_0x4ace('0x7'));var config=require('../../config/environment');var jayson=require('jayson/promise');var client=jayson[_0x4ace('0x8')][_0x4ace('0x9')]({'port':0x232a});config[_0x4ace('0xa')]=_['defaults'](config[_0x4ace('0xa')],{'host':_0x4ace('0xb'),'port':0x18eb});var socket=require(_0x4ace('0xc'))(new Redis(config[_0x4ace('0xa')]));require(_0x4ace('0xd'))[_0x4ace('0xe')](socket);function respondWithRpcPromise(_0x4073ab,_0x115c65,_0x31180f){return new BPromise(function(_0x5b0805,_0x24f880){return client['request'](_0x4073ab,_0x31180f)['then'](function(_0x3ed287){logger[_0x4ace('0xf')](_0x4ace('0x10'),_0x115c65,_0x4ace('0x11'));logger[_0x4ace('0x12')](_0x4ace('0x13'),_0x115c65,_0x4ace('0x11'),JSON['stringify'](_0x3ed287));if(_0x3ed287[_0x4ace('0x14')]){if(_0x3ed287['error'][_0x4ace('0x15')]===0x1f4){logger[_0x4ace('0x14')](_0x4ace('0x10'),_0x115c65,_0x3ed287[_0x4ace('0x14')][_0x4ace('0x16')]);return _0x24f880(_0x3ed287['error'][_0x4ace('0x16')]);}logger[_0x4ace('0x14')](_0x4ace('0x10'),_0x115c65,_0x3ed287[_0x4ace('0x14')]['message']);return _0x5b0805(_0x3ed287['error'][_0x4ace('0x16')]);}else{logger['info'](_0x4ace('0x10'),_0x115c65,_0x4ace('0x11'));_0x5b0805(_0x3ed287[_0x4ace('0x17')][_0x4ace('0x16')]);}})[_0x4ace('0x18')](function(_0x1283b8){logger[_0x4ace('0x14')]('WhatsappMessage,\x20%s,\x20%s',_0x115c65,_0x1283b8);_0x24f880(_0x1283b8);});});}exports[_0x4ace('0x19')]=function(_0x28dc2d){var _0x4f1632=this;return new Promise(function(_0x4a5efd,_0x3e9330){return db[_0x4ace('0x1a')][_0x4ace('0x1b')](_0x28dc2d['body'],{'raw':_0x28dc2d[_0x4ace('0x1c')]?_0x28dc2d[_0x4ace('0x1c')][_0x4ace('0x1d')]===undefined?!![]:![]:!![]})[_0x4ace('0x1e')](function(_0x409c62){logger[_0x4ace('0xf')](_0x4ace('0x19'),_0x28dc2d);logger['debug'](_0x4ace('0x19'),_0x28dc2d,JSON[_0x4ace('0x1f')](_0x409c62));_0x4a5efd(_0x409c62);})['catch'](function(_0x50d82c){logger[_0x4ace('0x14')](_0x4ace('0x19'),_0x50d82c[_0x4ace('0x16')],_0x28dc2d);_0x3e9330(_0x4f1632[_0x4ace('0x14')](0x1f4,_0x50d82c[_0x4ace('0x16')]));});});};