Built motion from commit da617fac.|2.6.6
[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 _0x40b4=['request\x20sent','WhatsappMessage,\x20%s,\x20%s,\x20%s','stringify','error','message','info','catch','CreateWhatsappMessage','WhatsappMessage','create','body','options','raw','lodash','util','moment','bluebird','ioredis','../../mysqldb','../../config/logger','rpc','../../config/environment','jayson/promise','http','defaults','redis','localhost','socket.io-emitter','./whatsappMessage.socket','register','then','WhatsappMessage,\x20%s,\x20%s'];(function(_0x214266,_0x1f6f52){var _0x568f75=function(_0x541904){while(--_0x541904){_0x214266['push'](_0x214266['shift']());}};_0x568f75(++_0x1f6f52);}(_0x40b4,0x10d));var _0x440b=function(_0x3dd3ee,_0x3dbf50){_0x3dd3ee=_0x3dd3ee-0x0;var _0x59b7a9=_0x40b4[_0x3dd3ee];return _0x59b7a9;};'use strict';var _=require(_0x440b('0x0'));var util=require(_0x440b('0x1'));var moment=require(_0x440b('0x2'));var BPromise=require(_0x440b('0x3'));var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x440b('0x4'));var db=require(_0x440b('0x5'))['db'];var utils=require('../../config/utils');var logger=require(_0x440b('0x6'))(_0x440b('0x7'));var config=require(_0x440b('0x8'));var jayson=require(_0x440b('0x9'));var client=jayson['client'][_0x440b('0xa')]({'port':0x232a});config['redis']=_[_0x440b('0xb')](config[_0x440b('0xc')],{'host':_0x440b('0xd'),'port':0x18eb});var socket=require(_0x440b('0xe'))(new Redis(config['redis']));require(_0x440b('0xf'))[_0x440b('0x10')](socket);function respondWithRpcPromise(_0x172904,_0x10c3d6,_0x16c0de){return new BPromise(function(_0x22ef2c,_0x5a77b9){return client['request'](_0x172904,_0x16c0de)[_0x440b('0x11')](function(_0x16507e){logger['info'](_0x440b('0x12'),_0x10c3d6,_0x440b('0x13'));logger['debug'](_0x440b('0x14'),_0x10c3d6,'request\x20sent',JSON[_0x440b('0x15')](_0x16507e));if(_0x16507e[_0x440b('0x16')]){if(_0x16507e[_0x440b('0x16')]['code']===0x1f4){logger['error']('WhatsappMessage,\x20%s,\x20%s',_0x10c3d6,_0x16507e[_0x440b('0x16')][_0x440b('0x17')]);return _0x5a77b9(_0x16507e[_0x440b('0x16')][_0x440b('0x17')]);}logger[_0x440b('0x16')](_0x440b('0x12'),_0x10c3d6,_0x16507e['error'][_0x440b('0x17')]);return _0x22ef2c(_0x16507e[_0x440b('0x16')][_0x440b('0x17')]);}else{logger[_0x440b('0x18')]('WhatsappMessage,\x20%s,\x20%s',_0x10c3d6,_0x440b('0x13'));_0x22ef2c(_0x16507e['result'][_0x440b('0x17')]);}})[_0x440b('0x19')](function(_0x497023){logger[_0x440b('0x16')](_0x440b('0x12'),_0x10c3d6,_0x497023);_0x5a77b9(_0x497023);});});}exports[_0x440b('0x1a')]=function(_0x37abcd){var _0xe892e2=this;return new Promise(function(_0x655c0a,_0x326af1){return db[_0x440b('0x1b')][_0x440b('0x1c')](_0x37abcd[_0x440b('0x1d')],{'raw':_0x37abcd['options']?_0x37abcd[_0x440b('0x1e')][_0x440b('0x1f')]===undefined?!![]:![]:!![]})[_0x440b('0x11')](function(_0x597b63){logger['info'](_0x440b('0x1a'),_0x37abcd);logger['debug'](_0x440b('0x1a'),_0x37abcd,JSON[_0x440b('0x15')](_0x597b63));_0x655c0a(_0x597b63);})['catch'](function(_0x24a791){logger['error'](_0x440b('0x1a'),_0x24a791[_0x440b('0x17')],_0x37abcd);_0x326af1(_0xe892e2['error'](0x1f4,_0x24a791[_0x440b('0x17')]));});});};