baf456ad5fd23dd1b3c23552966dbaed8cf6351f
[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 _0xf5eb=['WhatsappMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','catch','CreateWhatsappMessage','create','options','raw','debug','util','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','redis','defaults','localhost','socket.io-emitter','./whatsappMessage.socket','register','request','then','info','WhatsappMessage,\x20%s,\x20%s','request\x20sent'];(function(_0xe42f5,_0x526183){var _0xc7b5ec=function(_0x31036e){while(--_0x31036e){_0xe42f5['push'](_0xe42f5['shift']());}};_0xc7b5ec(++_0x526183);}(_0xf5eb,0x181));var _0xbf5e=function(_0x25c26,_0x84fc41){_0x25c26=_0x25c26-0x0;var _0x321e20=_0xf5eb[_0x25c26];return _0x321e20;};'use strict';var _=require('lodash');var util=require(_0xbf5e('0x0'));var moment=require(_0xbf5e('0x1'));var BPromise=require(_0xbf5e('0x2'));var rs=require(_0xbf5e('0x3'));var fs=require('fs');var Redis=require(_0xbf5e('0x4'));var db=require(_0xbf5e('0x5'))['db'];var utils=require(_0xbf5e('0x6'));var logger=require(_0xbf5e('0x7'))(_0xbf5e('0x8'));var config=require(_0xbf5e('0x9'));var jayson=require(_0xbf5e('0xa'));var client=jayson[_0xbf5e('0xb')]['http']({'port':0x232a});config[_0xbf5e('0xc')]=_[_0xbf5e('0xd')](config[_0xbf5e('0xc')],{'host':_0xbf5e('0xe'),'port':0x18eb});var socket=require(_0xbf5e('0xf'))(new Redis(config[_0xbf5e('0xc')]));require(_0xbf5e('0x10'))[_0xbf5e('0x11')](socket);function respondWithRpcPromise(_0x5d1332,_0x2f1964,_0x22535e){return new BPromise(function(_0x5405b7,_0x41292a){return client[_0xbf5e('0x12')](_0x5d1332,_0x22535e)[_0xbf5e('0x13')](function(_0x45902a){logger[_0xbf5e('0x14')](_0xbf5e('0x15'),_0x2f1964,_0xbf5e('0x16'));logger['debug'](_0xbf5e('0x17'),_0x2f1964,_0xbf5e('0x16'),JSON[_0xbf5e('0x18')](_0x45902a));if(_0x45902a[_0xbf5e('0x19')]){if(_0x45902a[_0xbf5e('0x19')][_0xbf5e('0x1a')]===0x1f4){logger[_0xbf5e('0x19')](_0xbf5e('0x15'),_0x2f1964,_0x45902a[_0xbf5e('0x19')]['message']);return _0x41292a(_0x45902a[_0xbf5e('0x19')][_0xbf5e('0x1b')]);}logger['error'](_0xbf5e('0x15'),_0x2f1964,_0x45902a[_0xbf5e('0x19')][_0xbf5e('0x1b')]);return _0x5405b7(_0x45902a[_0xbf5e('0x19')][_0xbf5e('0x1b')]);}else{logger[_0xbf5e('0x14')](_0xbf5e('0x15'),_0x2f1964,'request\x20sent');_0x5405b7(_0x45902a['result'][_0xbf5e('0x1b')]);}})[_0xbf5e('0x1c')](function(_0x175160){logger[_0xbf5e('0x19')](_0xbf5e('0x15'),_0x2f1964,_0x175160);_0x41292a(_0x175160);});});}exports[_0xbf5e('0x1d')]=function(_0x3b9f2b){var _0x5441ff=this;return new Promise(function(_0x7da6ec,_0x532af1){return db['WhatsappMessage'][_0xbf5e('0x1e')](_0x3b9f2b['body'],{'raw':_0x3b9f2b[_0xbf5e('0x1f')]?_0x3b9f2b[_0xbf5e('0x1f')][_0xbf5e('0x20')]===undefined?!![]:![]:!![]})[_0xbf5e('0x13')](function(_0x4b4041){logger[_0xbf5e('0x14')](_0xbf5e('0x1d'),_0x3b9f2b);logger[_0xbf5e('0x21')](_0xbf5e('0x1d'),_0x3b9f2b,JSON[_0xbf5e('0x18')](_0x4b4041));_0x7da6ec(_0x4b4041);})['catch'](function(_0xd62326){logger[_0xbf5e('0x19')](_0xbf5e('0x1d'),_0xd62326['message'],_0x3b9f2b);_0x532af1(_0x5441ff[_0xbf5e('0x19')](0x1f4,_0xd62326[_0xbf5e('0x1b')]));});});};