Built motion from commit 775e2a94.|2.6.3
[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 _0x6684=['options','raw','CreateWhatsappMessage','catch','lodash','util','moment','bluebird','randomstring','ioredis','../../config/utils','../../config/logger','rpc','../../config/environment','client','http','redis','localhost','./whatsappMessage.socket','register','request','then','info','WhatsappMessage,\x20%s,\x20%s','request\x20sent','debug','WhatsappMessage,\x20%s,\x20%s,\x20%s','stringify','error','message','result','WhatsappMessage','create'];(function(_0x1facfa,_0x1acf7d){var _0x9ec701=function(_0x115e37){while(--_0x115e37){_0x1facfa['push'](_0x1facfa['shift']());}};_0x9ec701(++_0x1acf7d);}(_0x6684,0x190));var _0x4668=function(_0x270a54,_0x307ff6){_0x270a54=_0x270a54-0x0;var _0x4d07d0=_0x6684[_0x270a54];return _0x4d07d0;};'use strict';var _=require(_0x4668('0x0'));var util=require(_0x4668('0x1'));var moment=require(_0x4668('0x2'));var BPromise=require(_0x4668('0x3'));var rs=require(_0x4668('0x4'));var fs=require('fs');var Redis=require(_0x4668('0x5'));var db=require('../../mysqldb')['db'];var utils=require(_0x4668('0x6'));var logger=require(_0x4668('0x7'))(_0x4668('0x8'));var config=require(_0x4668('0x9'));var jayson=require('jayson/promise');var client=jayson[_0x4668('0xa')][_0x4668('0xb')]({'port':0x232a});config[_0x4668('0xc')]=_['defaults'](config['redis'],{'host':_0x4668('0xd'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0x4668('0xe'))[_0x4668('0xf')](socket);function respondWithRpcPromise(_0x41272e,_0x1c6f3b,_0x568ae5){return new BPromise(function(_0x2284e0,_0x585740){return client[_0x4668('0x10')](_0x41272e,_0x568ae5)[_0x4668('0x11')](function(_0x552656){logger[_0x4668('0x12')](_0x4668('0x13'),_0x1c6f3b,_0x4668('0x14'));logger[_0x4668('0x15')](_0x4668('0x16'),_0x1c6f3b,_0x4668('0x14'),JSON[_0x4668('0x17')](_0x552656));if(_0x552656[_0x4668('0x18')]){if(_0x552656['error']['code']===0x1f4){logger[_0x4668('0x18')](_0x4668('0x13'),_0x1c6f3b,_0x552656[_0x4668('0x18')][_0x4668('0x19')]);return _0x585740(_0x552656['error'][_0x4668('0x19')]);}logger[_0x4668('0x18')]('WhatsappMessage,\x20%s,\x20%s',_0x1c6f3b,_0x552656[_0x4668('0x18')]['message']);return _0x2284e0(_0x552656[_0x4668('0x18')][_0x4668('0x19')]);}else{logger[_0x4668('0x12')](_0x4668('0x13'),_0x1c6f3b,_0x4668('0x14'));_0x2284e0(_0x552656[_0x4668('0x1a')][_0x4668('0x19')]);}})['catch'](function(_0x455a0f){logger[_0x4668('0x18')](_0x4668('0x13'),_0x1c6f3b,_0x455a0f);_0x585740(_0x455a0f);});});}exports['CreateWhatsappMessage']=function(_0x27b705){var _0x27c859=this;return new Promise(function(_0x45f249,_0x346658){return db[_0x4668('0x1b')][_0x4668('0x1c')](_0x27b705['body'],{'raw':_0x27b705[_0x4668('0x1d')]?_0x27b705[_0x4668('0x1d')][_0x4668('0x1e')]===undefined?!![]:![]:!![]})[_0x4668('0x11')](function(_0x5d4bd2){logger['info'](_0x4668('0x1f'),_0x27b705);logger[_0x4668('0x15')](_0x4668('0x1f'),_0x27b705,JSON[_0x4668('0x17')](_0x5d4bd2));_0x45f249(_0x5d4bd2);})[_0x4668('0x20')](function(_0x4bad50){logger[_0x4668('0x18')](_0x4668('0x1f'),_0x4bad50[_0x4668('0x19')],_0x27b705);_0x346658(_0x27c859[_0x4668('0x18')](0x1f4,_0x4bad50[_0x4668('0x19')]));});});};