9f878668698afc409d0c3dbb308db3299419c3bc
[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 _0xd2ca=['../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','http','redis','defaults','socket.io-emitter','register','then','info','WhatsappMessage,\x20%s,\x20%s','debug','stringify','error','message','CreateWhatsappMessage','WhatsappMessage','create','options','raw','lodash','util','moment','bluebird','randomstring','ioredis','../../mysqldb'];(function(_0x10a904,_0x2bf292){var _0x53815a=function(_0x2e6ce4){while(--_0x2e6ce4){_0x10a904['push'](_0x10a904['shift']());}};_0x53815a(++_0x2bf292);}(_0xd2ca,0xcb));var _0xad2c=function(_0x5ea3bf,_0x5c3a8d){_0x5ea3bf=_0x5ea3bf-0x0;var _0x7cd8b9=_0xd2ca[_0x5ea3bf];return _0x7cd8b9;};'use strict';var _=require(_0xad2c('0x0'));var util=require(_0xad2c('0x1'));var moment=require(_0xad2c('0x2'));var BPromise=require(_0xad2c('0x3'));var rs=require(_0xad2c('0x4'));var fs=require('fs');var Redis=require(_0xad2c('0x5'));var db=require(_0xad2c('0x6'))['db'];var utils=require(_0xad2c('0x7'));var logger=require(_0xad2c('0x8'))(_0xad2c('0x9'));var config=require(_0xad2c('0xa'));var jayson=require(_0xad2c('0xb'));var client=jayson[_0xad2c('0xc')][_0xad2c('0xd')]({'port':0x232a});config[_0xad2c('0xe')]=_[_0xad2c('0xf')](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0xad2c('0x10'))(new Redis(config[_0xad2c('0xe')]));require('./whatsappMessage.socket')[_0xad2c('0x11')](socket);function respondWithRpcPromise(_0x516390,_0x5e86d8,_0x43262e){return new BPromise(function(_0x37a890,_0x3f065d){return client['request'](_0x516390,_0x43262e)[_0xad2c('0x12')](function(_0x413461){logger[_0xad2c('0x13')](_0xad2c('0x14'),_0x5e86d8,'request\x20sent');logger[_0xad2c('0x15')]('WhatsappMessage,\x20%s,\x20%s,\x20%s',_0x5e86d8,'request\x20sent',JSON[_0xad2c('0x16')](_0x413461));if(_0x413461['error']){if(_0x413461['error']['code']===0x1f4){logger[_0xad2c('0x17')](_0xad2c('0x14'),_0x5e86d8,_0x413461[_0xad2c('0x17')]['message']);return _0x3f065d(_0x413461[_0xad2c('0x17')][_0xad2c('0x18')]);}logger[_0xad2c('0x17')](_0xad2c('0x14'),_0x5e86d8,_0x413461[_0xad2c('0x17')][_0xad2c('0x18')]);return _0x37a890(_0x413461[_0xad2c('0x17')][_0xad2c('0x18')]);}else{logger[_0xad2c('0x13')](_0xad2c('0x14'),_0x5e86d8,'request\x20sent');_0x37a890(_0x413461['result'][_0xad2c('0x18')]);}})['catch'](function(_0x2ad282){logger[_0xad2c('0x17')](_0xad2c('0x14'),_0x5e86d8,_0x2ad282);_0x3f065d(_0x2ad282);});});}exports[_0xad2c('0x19')]=function(_0x4c75aa){var _0x45e508=this;return new Promise(function(_0x480393,_0x3cbaa2){return db[_0xad2c('0x1a')][_0xad2c('0x1b')](_0x4c75aa['body'],{'raw':_0x4c75aa[_0xad2c('0x1c')]?_0x4c75aa[_0xad2c('0x1c')][_0xad2c('0x1d')]===undefined?!![]:![]:!![]})['then'](function(_0x350602){logger['info'](_0xad2c('0x19'),_0x4c75aa);logger[_0xad2c('0x15')](_0xad2c('0x19'),_0x4c75aa,JSON[_0xad2c('0x16')](_0x350602));_0x480393(_0x350602);})['catch'](function(_0x37df40){logger[_0xad2c('0x17')](_0xad2c('0x19'),_0x37df40['message'],_0x4c75aa);_0x3cbaa2(_0x45e508[_0xad2c('0x17')](0x1f4,_0x37df40[_0xad2c('0x18')]));});});};