6edf39a1d872eee911392424065895cc8231acbd
[motion2.git] / server / api / whatsappInteraction / whatsappInteraction.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 _0x98b6=['debug','stringify','error','code','message','info','request\x20sent','result','catch','WhatsappInteraction','update','options','where','attributes','limit','then','UpdateWhatsappInteraction','AddTagsToWhatsappInteraction','find','body','ids','omit','spread','AddTags','lodash','util','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/environment','client','redis','localhost','./whatsappInteraction.socket','register','request','WhatsappInteraction,\x20%s,\x20%s'];(function(_0x2351c4,_0x1dca54){var _0x1dd3f8=function(_0x4c3fa2){while(--_0x4c3fa2){_0x2351c4['push'](_0x2351c4['shift']());}};_0x1dd3f8(++_0x1dca54);}(_0x98b6,0x130));var _0x698b=function(_0x43891f,_0x459095){_0x43891f=_0x43891f-0x0;var _0x3f15c6=_0x98b6[_0x43891f];return _0x3f15c6;};'use strict';var _=require(_0x698b('0x0'));var util=require(_0x698b('0x1'));var moment=require(_0x698b('0x2'));var BPromise=require(_0x698b('0x3'));var rs=require(_0x698b('0x4'));var fs=require('fs');var Redis=require(_0x698b('0x5'));var db=require(_0x698b('0x6'))['db'];var utils=require(_0x698b('0x7'));var logger=require('../../config/logger')('rpc');var config=require(_0x698b('0x8'));var jayson=require('jayson/promise');var client=jayson[_0x698b('0x9')]['http']({'port':0x232a});config['redis']=_['defaults'](config[_0x698b('0xa')],{'host':_0x698b('0xb'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x698b('0xa')]));require(_0x698b('0xc'))[_0x698b('0xd')](socket);function respondWithRpcPromise(_0xb7b979,_0x1efbf7,_0x37bef6){return new BPromise(function(_0x5e790d,_0xe12525){return client[_0x698b('0xe')](_0xb7b979,_0x37bef6)['then'](function(_0x1f20d0){logger['info'](_0x698b('0xf'),_0x1efbf7,'request\x20sent');logger[_0x698b('0x10')]('WhatsappInteraction,\x20%s,\x20%s,\x20%s',_0x1efbf7,'request\x20sent',JSON[_0x698b('0x11')](_0x1f20d0));if(_0x1f20d0[_0x698b('0x12')]){if(_0x1f20d0[_0x698b('0x12')][_0x698b('0x13')]===0x1f4){logger['error'](_0x698b('0xf'),_0x1efbf7,_0x1f20d0[_0x698b('0x12')][_0x698b('0x14')]);return _0xe12525(_0x1f20d0[_0x698b('0x12')][_0x698b('0x14')]);}logger[_0x698b('0x12')](_0x698b('0xf'),_0x1efbf7,_0x1f20d0[_0x698b('0x12')][_0x698b('0x14')]);return _0x5e790d(_0x1f20d0[_0x698b('0x12')][_0x698b('0x14')]);}else{logger[_0x698b('0x15')]('WhatsappInteraction,\x20%s,\x20%s',_0x1efbf7,_0x698b('0x16'));_0x5e790d(_0x1f20d0[_0x698b('0x17')]['message']);}})[_0x698b('0x18')](function(_0x3827f3){logger['error'](_0x698b('0xf'),_0x1efbf7,_0x3827f3);_0xe12525(_0x3827f3);});});}exports['UpdateWhatsappInteraction']=function(_0x1fbe5a){var _0x1f676c=this;return new Promise(function(_0x35eff8,_0x11a13f){return db[_0x698b('0x19')][_0x698b('0x1a')](_0x1fbe5a['body'],{'raw':_0x1fbe5a[_0x698b('0x1b')]?_0x1fbe5a['options']['raw']===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x1fbe5a['options']?_0x1fbe5a['options'][_0x698b('0x1c')]||null:null,'attributes':_0x1fbe5a[_0x698b('0x1b')]?_0x1fbe5a[_0x698b('0x1b')][_0x698b('0x1d')]||null:null,'limit':_0x1fbe5a[_0x698b('0x1b')]?_0x1fbe5a[_0x698b('0x1b')][_0x698b('0x1e')]||null:null})[_0x698b('0x1f')](function(_0x4c2537){logger['info'](_0x698b('0x20'),_0x1fbe5a);logger[_0x698b('0x10')](_0x698b('0x20'),_0x1fbe5a,JSON[_0x698b('0x11')](_0x4c2537));_0x35eff8(_0x4c2537);})[_0x698b('0x18')](function(_0x1bf9e8){logger['error']('UpdateWhatsappInteraction',_0x1bf9e8[_0x698b('0x14')],_0x1fbe5a);_0x11a13f(_0x1f676c['error'](0x1f4,_0x1bf9e8[_0x698b('0x14')]));});});};exports[_0x698b('0x21')]=function(_0x5c2b79){return new Promise(function(_0x57c9c9,_0x47f154){return db[_0x698b('0x19')][_0x698b('0x22')]({'where':_0x5c2b79['options']?_0x5c2b79[_0x698b('0x1b')][_0x698b('0x1c')]||null:null})[_0x698b('0x1f')](function(_0x5dde82){if(_0x5dde82){return _0x5dde82['addTags'](_0x5c2b79[_0x698b('0x23')][_0x698b('0x24')],_[_0x698b('0x25')](_0x5c2b79['body'],[_0x698b('0x24'),'id'])||{});}})[_0x698b('0x26')](function(_0x327f9f){logger[_0x698b('0x15')]('AddTags',_0x5c2b79);logger[_0x698b('0x10')](_0x698b('0x27'),_0x5c2b79,JSON[_0x698b('0x11')](_0x327f9f));_0x57c9c9(_0x327f9f);})['catch'](function(_0x1b27bd){logger[_0x698b('0x12')](_0x698b('0x27'),_0x1b27bd[_0x698b('0x14')],_0x5c2b79);_0x47f154(_this[_0x698b('0x12')](0x1f4,_0x1b27bd['message']));});});};