af1e10bb7483012a526cad4babd02130f33b36bb
[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 _0xe9b9=['error','code','message','result','WhatsappMessage','create','body','options','raw','CreateWhatsappMessage','catch','lodash','util','moment','bluebird','randomstring','../../config/utils','../../config/logger','rpc','http','redis','defaults','localhost','request','info','WhatsappMessage,\x20%s,\x20%s','request\x20sent','debug','stringify'];(function(_0xaadddb,_0x2e5965){var _0x5c9ba2=function(_0x12802a){while(--_0x12802a){_0xaadddb['push'](_0xaadddb['shift']());}};_0x5c9ba2(++_0x2e5965);}(_0xe9b9,0x1be));var _0x9e9b=function(_0x3133c8,_0x1ecaa8){_0x3133c8=_0x3133c8-0x0;var _0x1d4f12=_0xe9b9[_0x3133c8];return _0x1d4f12;};'use strict';var _=require(_0x9e9b('0x0'));var util=require(_0x9e9b('0x1'));var moment=require(_0x9e9b('0x2'));var BPromise=require(_0x9e9b('0x3'));var rs=require(_0x9e9b('0x4'));var fs=require('fs');var Redis=require('ioredis');var db=require('../../mysqldb')['db'];var utils=require(_0x9e9b('0x5'));var logger=require(_0x9e9b('0x6'))(_0x9e9b('0x7'));var config=require('../../config/environment');var jayson=require('jayson/promise');var client=jayson['client'][_0x9e9b('0x8')]({'port':0x232a});config[_0x9e9b('0x9')]=_[_0x9e9b('0xa')](config[_0x9e9b('0x9')],{'host':_0x9e9b('0xb'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x9e9b('0x9')]));require('./whatsappMessage.socket')['register'](socket);function respondWithRpcPromise(_0x18f075,_0x25a583,_0x35c2a6){return new BPromise(function(_0x2c4a52,_0x4c611a){return client[_0x9e9b('0xc')](_0x18f075,_0x35c2a6)['then'](function(_0x1cb834){logger[_0x9e9b('0xd')](_0x9e9b('0xe'),_0x25a583,_0x9e9b('0xf'));logger[_0x9e9b('0x10')]('WhatsappMessage,\x20%s,\x20%s,\x20%s',_0x25a583,'request\x20sent',JSON[_0x9e9b('0x11')](_0x1cb834));if(_0x1cb834[_0x9e9b('0x12')]){if(_0x1cb834['error'][_0x9e9b('0x13')]===0x1f4){logger[_0x9e9b('0x12')]('WhatsappMessage,\x20%s,\x20%s',_0x25a583,_0x1cb834['error']['message']);return _0x4c611a(_0x1cb834['error'][_0x9e9b('0x14')]);}logger[_0x9e9b('0x12')](_0x9e9b('0xe'),_0x25a583,_0x1cb834['error'][_0x9e9b('0x14')]);return _0x2c4a52(_0x1cb834['error'][_0x9e9b('0x14')]);}else{logger[_0x9e9b('0xd')](_0x9e9b('0xe'),_0x25a583,_0x9e9b('0xf'));_0x2c4a52(_0x1cb834[_0x9e9b('0x15')][_0x9e9b('0x14')]);}})['catch'](function(_0xaa773){logger[_0x9e9b('0x12')]('WhatsappMessage,\x20%s,\x20%s',_0x25a583,_0xaa773);_0x4c611a(_0xaa773);});});}exports['CreateWhatsappMessage']=function(_0x1bf2e6){var _0x4c170e=this;return new Promise(function(_0x468c81,_0x556086){return db[_0x9e9b('0x16')][_0x9e9b('0x17')](_0x1bf2e6[_0x9e9b('0x18')],{'raw':_0x1bf2e6[_0x9e9b('0x19')]?_0x1bf2e6[_0x9e9b('0x19')][_0x9e9b('0x1a')]===undefined?!![]:![]:!![]})['then'](function(_0x288998){logger[_0x9e9b('0xd')](_0x9e9b('0x1b'),_0x1bf2e6);logger[_0x9e9b('0x10')](_0x9e9b('0x1b'),_0x1bf2e6,JSON[_0x9e9b('0x11')](_0x288998));_0x468c81(_0x288998);})[_0x9e9b('0x1c')](function(_0x69dcc){logger['error'](_0x9e9b('0x1b'),_0x69dcc[_0x9e9b('0x14')],_0x1bf2e6);_0x556086(_0x4c170e[_0x9e9b('0x12')](0x1f4,_0x69dcc[_0x9e9b('0x14')]));});});};