Built motion from commit bab6f49e.|2.6.17
[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 _0xa994=['WhatsappMessage,\x20%s,\x20%s,\x20%s','error','code','WhatsappMessage,\x20%s,\x20%s','message','result','CreateWhatsappMessage','WhatsappMessage','options','raw','stringify','catch','lodash','util','moment','bluebird','randomstring','ioredis','../../mysqldb','rpc','../../config/environment','client','defaults','redis','localhost','./whatsappMessage.socket','register','request','then','info','request\x20sent'];(function(_0x371158,_0x11fb15){var _0x1835f2=function(_0x22d481){while(--_0x22d481){_0x371158['push'](_0x371158['shift']());}};_0x1835f2(++_0x11fb15);}(_0xa994,0xa7));var _0x4a99=function(_0x175f93,_0x1a01c5){_0x175f93=_0x175f93-0x0;var _0x4b9d82=_0xa994[_0x175f93];return _0x4b9d82;};'use strict';var _=require(_0x4a99('0x0'));var util=require(_0x4a99('0x1'));var moment=require(_0x4a99('0x2'));var BPromise=require(_0x4a99('0x3'));var rs=require(_0x4a99('0x4'));var fs=require('fs');var Redis=require(_0x4a99('0x5'));var db=require(_0x4a99('0x6'))['db'];var utils=require('../../config/utils');var logger=require('../../config/logger')(_0x4a99('0x7'));var config=require(_0x4a99('0x8'));var jayson=require('jayson/promise');var client=jayson[_0x4a99('0x9')]['http']({'port':0x232a});config['redis']=_[_0x4a99('0xa')](config[_0x4a99('0xb')],{'host':_0x4a99('0xc'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x4a99('0xb')]));require(_0x4a99('0xd'))[_0x4a99('0xe')](socket);function respondWithRpcPromise(_0x176ea3,_0x14a522,_0x1a2002){return new BPromise(function(_0x593e6e,_0x447969){return client[_0x4a99('0xf')](_0x176ea3,_0x1a2002)[_0x4a99('0x10')](function(_0x28cf30){logger[_0x4a99('0x11')]('WhatsappMessage,\x20%s,\x20%s',_0x14a522,_0x4a99('0x12'));logger['debug'](_0x4a99('0x13'),_0x14a522,_0x4a99('0x12'),JSON['stringify'](_0x28cf30));if(_0x28cf30['error']){if(_0x28cf30[_0x4a99('0x14')][_0x4a99('0x15')]===0x1f4){logger[_0x4a99('0x14')](_0x4a99('0x16'),_0x14a522,_0x28cf30['error'][_0x4a99('0x17')]);return _0x447969(_0x28cf30[_0x4a99('0x14')]['message']);}logger[_0x4a99('0x14')](_0x4a99('0x16'),_0x14a522,_0x28cf30[_0x4a99('0x14')][_0x4a99('0x17')]);return _0x593e6e(_0x28cf30['error'][_0x4a99('0x17')]);}else{logger[_0x4a99('0x11')]('WhatsappMessage,\x20%s,\x20%s',_0x14a522,'request\x20sent');_0x593e6e(_0x28cf30[_0x4a99('0x18')]['message']);}})['catch'](function(_0x23da2d){logger[_0x4a99('0x14')](_0x4a99('0x16'),_0x14a522,_0x23da2d);_0x447969(_0x23da2d);});});}exports[_0x4a99('0x19')]=function(_0x2cfc8b){var _0x48f959=this;return new Promise(function(_0x44c12a,_0x4f7f32){return db[_0x4a99('0x1a')]['create'](_0x2cfc8b['body'],{'raw':_0x2cfc8b['options']?_0x2cfc8b[_0x4a99('0x1b')][_0x4a99('0x1c')]===undefined?!![]:![]:!![]})[_0x4a99('0x10')](function(_0x54e83f){logger[_0x4a99('0x11')]('CreateWhatsappMessage',_0x2cfc8b);logger['debug']('CreateWhatsappMessage',_0x2cfc8b,JSON[_0x4a99('0x1d')](_0x54e83f));_0x44c12a(_0x54e83f);})[_0x4a99('0x1e')](function(_0x5c7148){logger[_0x4a99('0x14')](_0x4a99('0x19'),_0x5c7148[_0x4a99('0x17')],_0x2cfc8b);_0x4f7f32(_0x48f959[_0x4a99('0x14')](0x1f4,_0x5c7148[_0x4a99('0x17')]));});});};