468d4ff610cf993daf01fe13c697321b491a5033
[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 _0x72b5=['message','info','catch','CreateWhatsappMessage','WhatsappMessage','create','body','options','raw','lodash','util','bluebird','randomstring','ioredis','../../config/utils','../../config/logger','jayson/promise','redis','localhost','socket.io-emitter','./whatsappMessage.socket','register','request','then','WhatsappMessage,\x20%s,\x20%s','request\x20sent','debug','WhatsappMessage,\x20%s,\x20%s,\x20%s','stringify','code','error'];(function(_0x5b644e,_0x2e5e07){var _0x49c6bf=function(_0x3032d9){while(--_0x3032d9){_0x5b644e['push'](_0x5b644e['shift']());}};_0x49c6bf(++_0x2e5e07);}(_0x72b5,0x120));var _0x572b=function(_0x37c56d,_0x52b6e3){_0x37c56d=_0x37c56d-0x0;var _0x536daf=_0x72b5[_0x37c56d];return _0x536daf;};'use strict';var _=require(_0x572b('0x0'));var util=require(_0x572b('0x1'));var moment=require('moment');var BPromise=require(_0x572b('0x2'));var rs=require(_0x572b('0x3'));var fs=require('fs');var Redis=require(_0x572b('0x4'));var db=require('../../mysqldb')['db'];var utils=require(_0x572b('0x5'));var logger=require(_0x572b('0x6'))('rpc');var config=require('../../config/environment');var jayson=require(_0x572b('0x7'));var client=jayson['client']['http']({'port':0x232a});config[_0x572b('0x8')]=_['defaults'](config[_0x572b('0x8')],{'host':_0x572b('0x9'),'port':0x18eb});var socket=require(_0x572b('0xa'))(new Redis(config[_0x572b('0x8')]));require(_0x572b('0xb'))[_0x572b('0xc')](socket);function respondWithRpcPromise(_0x1d6e75,_0x1c5192,_0x1f221d){return new BPromise(function(_0x6b37bb,_0x10b5dd){return client[_0x572b('0xd')](_0x1d6e75,_0x1f221d)[_0x572b('0xe')](function(_0x45ac12){logger['info'](_0x572b('0xf'),_0x1c5192,_0x572b('0x10'));logger[_0x572b('0x11')](_0x572b('0x12'),_0x1c5192,_0x572b('0x10'),JSON[_0x572b('0x13')](_0x45ac12));if(_0x45ac12['error']){if(_0x45ac12['error'][_0x572b('0x14')]===0x1f4){logger[_0x572b('0x15')](_0x572b('0xf'),_0x1c5192,_0x45ac12[_0x572b('0x15')]['message']);return _0x10b5dd(_0x45ac12[_0x572b('0x15')][_0x572b('0x16')]);}logger[_0x572b('0x15')]('WhatsappMessage,\x20%s,\x20%s',_0x1c5192,_0x45ac12['error'][_0x572b('0x16')]);return _0x6b37bb(_0x45ac12[_0x572b('0x15')][_0x572b('0x16')]);}else{logger[_0x572b('0x17')](_0x572b('0xf'),_0x1c5192,_0x572b('0x10'));_0x6b37bb(_0x45ac12['result'][_0x572b('0x16')]);}})[_0x572b('0x18')](function(_0x2fef3a){logger[_0x572b('0x15')]('WhatsappMessage,\x20%s,\x20%s',_0x1c5192,_0x2fef3a);_0x10b5dd(_0x2fef3a);});});}exports[_0x572b('0x19')]=function(_0x4cc203){var _0x31731f=this;return new Promise(function(_0x4d8f8e,_0x360d1b){return db[_0x572b('0x1a')][_0x572b('0x1b')](_0x4cc203[_0x572b('0x1c')],{'raw':_0x4cc203[_0x572b('0x1d')]?_0x4cc203[_0x572b('0x1d')][_0x572b('0x1e')]===undefined?!![]:![]:!![]})[_0x572b('0xe')](function(_0x14c038){logger[_0x572b('0x17')]('CreateWhatsappMessage',_0x4cc203);logger['debug'](_0x572b('0x19'),_0x4cc203,JSON[_0x572b('0x13')](_0x14c038));_0x4d8f8e(_0x14c038);})['catch'](function(_0x354ecb){logger[_0x572b('0x15')](_0x572b('0x19'),_0x354ecb[_0x572b('0x16')],_0x4cc203);_0x360d1b(_0x31731f['error'](0x1f4,_0x354ecb[_0x572b('0x16')]));});});};