Built motion from commit 511216ff.|2.6.34
[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 _0xe184=['defaults','localhost','socket.io-emitter','./whatsappInteraction.socket','register','request','info','WhatsappInteraction,\x20%s,\x20%s','request\x20sent','WhatsappInteraction,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','UpdateWhatsappInteraction','update','body','options','raw','where','attributes','limit','then','debug','WhatsappInteraction','find','ids','omit','spread','AddTags','catch','moment','randomstring','../../config/logger','../../config/environment','jayson/promise','http','redis'];(function(_0x7d2db1,_0x34145b){var _0x2b4c06=function(_0x552a4e){while(--_0x552a4e){_0x7d2db1['push'](_0x7d2db1['shift']());}};_0x2b4c06(++_0x34145b);}(_0xe184,0x158));var _0x4e18=function(_0x4ab2f4,_0x2f2b40){_0x4ab2f4=_0x4ab2f4-0x0;var _0xbb2b70=_0xe184[_0x4ab2f4];return _0xbb2b70;};'use strict';var _=require('lodash');var util=require('util');var moment=require(_0x4e18('0x0'));var BPromise=require('bluebird');var rs=require(_0x4e18('0x1'));var fs=require('fs');var Redis=require('ioredis');var db=require('../../mysqldb')['db'];var utils=require('../../config/utils');var logger=require(_0x4e18('0x2'))('rpc');var config=require(_0x4e18('0x3'));var jayson=require(_0x4e18('0x4'));var client=jayson['client'][_0x4e18('0x5')]({'port':0x232a});config[_0x4e18('0x6')]=_[_0x4e18('0x7')](config[_0x4e18('0x6')],{'host':_0x4e18('0x8'),'port':0x18eb});var socket=require(_0x4e18('0x9'))(new Redis(config[_0x4e18('0x6')]));require(_0x4e18('0xa'))[_0x4e18('0xb')](socket);function respondWithRpcPromise(_0x1c628c,_0x53360c,_0x4bc846){return new BPromise(function(_0x4ed86d,_0x3f6a6e){return client[_0x4e18('0xc')](_0x1c628c,_0x4bc846)['then'](function(_0xe0103e){logger[_0x4e18('0xd')](_0x4e18('0xe'),_0x53360c,_0x4e18('0xf'));logger['debug'](_0x4e18('0x10'),_0x53360c,'request\x20sent',JSON[_0x4e18('0x11')](_0xe0103e));if(_0xe0103e['error']){if(_0xe0103e[_0x4e18('0x12')][_0x4e18('0x13')]===0x1f4){logger['error']('WhatsappInteraction,\x20%s,\x20%s',_0x53360c,_0xe0103e[_0x4e18('0x12')][_0x4e18('0x14')]);return _0x3f6a6e(_0xe0103e['error'][_0x4e18('0x14')]);}logger[_0x4e18('0x12')](_0x4e18('0xe'),_0x53360c,_0xe0103e[_0x4e18('0x12')][_0x4e18('0x14')]);return _0x4ed86d(_0xe0103e[_0x4e18('0x12')][_0x4e18('0x14')]);}else{logger[_0x4e18('0xd')]('WhatsappInteraction,\x20%s,\x20%s',_0x53360c,_0x4e18('0xf'));_0x4ed86d(_0xe0103e[_0x4e18('0x15')][_0x4e18('0x14')]);}})['catch'](function(_0x19926a){logger[_0x4e18('0x12')](_0x4e18('0xe'),_0x53360c,_0x19926a);_0x3f6a6e(_0x19926a);});});}exports[_0x4e18('0x16')]=function(_0x4a62bb){var _0x267806=this;return new Promise(function(_0x2bf483,_0x4c3cf1){return db['WhatsappInteraction'][_0x4e18('0x17')](_0x4a62bb[_0x4e18('0x18')],{'raw':_0x4a62bb['options']?_0x4a62bb[_0x4e18('0x19')][_0x4e18('0x1a')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x4a62bb[_0x4e18('0x19')]?_0x4a62bb[_0x4e18('0x19')][_0x4e18('0x1b')]||null:null,'attributes':_0x4a62bb[_0x4e18('0x19')]?_0x4a62bb[_0x4e18('0x19')][_0x4e18('0x1c')]||null:null,'limit':_0x4a62bb['options']?_0x4a62bb['options'][_0x4e18('0x1d')]||null:null})[_0x4e18('0x1e')](function(_0x18d53a){logger[_0x4e18('0xd')]('UpdateWhatsappInteraction',_0x4a62bb);logger[_0x4e18('0x1f')]('UpdateWhatsappInteraction',_0x4a62bb,JSON[_0x4e18('0x11')](_0x18d53a));_0x2bf483(_0x18d53a);})['catch'](function(_0x2b6f5e){logger[_0x4e18('0x12')](_0x4e18('0x16'),_0x2b6f5e['message'],_0x4a62bb);_0x4c3cf1(_0x267806[_0x4e18('0x12')](0x1f4,_0x2b6f5e['message']));});});};exports['AddTagsToWhatsappInteraction']=function(_0x2c71d0){return new Promise(function(_0x305a94,_0x3c7a1b){return db[_0x4e18('0x20')][_0x4e18('0x21')]({'where':_0x2c71d0[_0x4e18('0x19')]?_0x2c71d0[_0x4e18('0x19')][_0x4e18('0x1b')]||null:null})[_0x4e18('0x1e')](function(_0x8e5479){if(_0x8e5479){return _0x8e5479['addTags'](_0x2c71d0['body'][_0x4e18('0x22')],_[_0x4e18('0x23')](_0x2c71d0['body'],[_0x4e18('0x22'),'id'])||{});}})[_0x4e18('0x24')](function(_0x49d35f){logger[_0x4e18('0xd')](_0x4e18('0x25'),_0x2c71d0);logger[_0x4e18('0x1f')](_0x4e18('0x25'),_0x2c71d0,JSON['stringify'](_0x49d35f));_0x305a94(_0x49d35f);})[_0x4e18('0x26')](function(_0x3eb0ca){logger[_0x4e18('0x12')](_0x4e18('0x25'),_0x3eb0ca['message'],_0x2c71d0);_0x3c7a1b(_this[_0x4e18('0x12')](0x1f4,_0x3eb0ca[_0x4e18('0x14')]));});});};