903f51db509c79e8db23da8f2bf8bc23fa9c61e3
[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 _0x4b99=['attributes','limit','then','debug','AddTagsToWhatsappInteraction','find','addTags','ids','omit','spread','AddTags','lodash','moment','bluebird','randomstring','ioredis','../../mysqldb','rpc','../../config/environment','jayson/promise','client','http','redis','localhost','socket.io-emitter','./whatsappInteraction.socket','request','info','request\x20sent','WhatsappInteraction,\x20%s,\x20%s,\x20%s','stringify','error','WhatsappInteraction,\x20%s,\x20%s','message','catch','UpdateWhatsappInteraction','WhatsappInteraction','update','body','options','raw','where'];(function(_0x1aabe6,_0xd72f2a){var _0x5bf82b=function(_0x513fce){while(--_0x513fce){_0x1aabe6['push'](_0x1aabe6['shift']());}};_0x5bf82b(++_0xd72f2a);}(_0x4b99,0xb3));var _0x94b9=function(_0xb14a9d,_0x2cfc96){_0xb14a9d=_0xb14a9d-0x0;var _0x1c5d1e=_0x4b99[_0xb14a9d];return _0x1c5d1e;};'use strict';var _=require(_0x94b9('0x0'));var util=require('util');var moment=require(_0x94b9('0x1'));var BPromise=require(_0x94b9('0x2'));var rs=require(_0x94b9('0x3'));var fs=require('fs');var Redis=require(_0x94b9('0x4'));var db=require(_0x94b9('0x5'))['db'];var utils=require('../../config/utils');var logger=require('../../config/logger')(_0x94b9('0x6'));var config=require(_0x94b9('0x7'));var jayson=require(_0x94b9('0x8'));var client=jayson[_0x94b9('0x9')][_0x94b9('0xa')]({'port':0x232a});config[_0x94b9('0xb')]=_['defaults'](config[_0x94b9('0xb')],{'host':_0x94b9('0xc'),'port':0x18eb});var socket=require(_0x94b9('0xd'))(new Redis(config[_0x94b9('0xb')]));require(_0x94b9('0xe'))['register'](socket);function respondWithRpcPromise(_0x16e37a,_0x5aef61,_0x3753e7){return new BPromise(function(_0x1bcbac,_0x1a4735){return client[_0x94b9('0xf')](_0x16e37a,_0x3753e7)['then'](function(_0xaf263){logger[_0x94b9('0x10')]('WhatsappInteraction,\x20%s,\x20%s',_0x5aef61,_0x94b9('0x11'));logger['debug'](_0x94b9('0x12'),_0x5aef61,_0x94b9('0x11'),JSON[_0x94b9('0x13')](_0xaf263));if(_0xaf263[_0x94b9('0x14')]){if(_0xaf263[_0x94b9('0x14')]['code']===0x1f4){logger[_0x94b9('0x14')](_0x94b9('0x15'),_0x5aef61,_0xaf263[_0x94b9('0x14')][_0x94b9('0x16')]);return _0x1a4735(_0xaf263[_0x94b9('0x14')][_0x94b9('0x16')]);}logger['error'](_0x94b9('0x15'),_0x5aef61,_0xaf263['error'][_0x94b9('0x16')]);return _0x1bcbac(_0xaf263[_0x94b9('0x14')]['message']);}else{logger['info'](_0x94b9('0x15'),_0x5aef61,_0x94b9('0x11'));_0x1bcbac(_0xaf263['result'][_0x94b9('0x16')]);}})[_0x94b9('0x17')](function(_0x2bfdd5){logger['error'](_0x94b9('0x15'),_0x5aef61,_0x2bfdd5);_0x1a4735(_0x2bfdd5);});});}exports[_0x94b9('0x18')]=function(_0x34bf4b){var _0x5ae0cf=this;return new Promise(function(_0x4da917,_0x977aa7){return db[_0x94b9('0x19')][_0x94b9('0x1a')](_0x34bf4b[_0x94b9('0x1b')],{'raw':_0x34bf4b[_0x94b9('0x1c')]?_0x34bf4b[_0x94b9('0x1c')][_0x94b9('0x1d')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x34bf4b['options']?_0x34bf4b[_0x94b9('0x1c')][_0x94b9('0x1e')]||null:null,'attributes':_0x34bf4b[_0x94b9('0x1c')]?_0x34bf4b[_0x94b9('0x1c')][_0x94b9('0x1f')]||null:null,'limit':_0x34bf4b[_0x94b9('0x1c')]?_0x34bf4b[_0x94b9('0x1c')][_0x94b9('0x20')]||null:null})[_0x94b9('0x21')](function(_0x530b4f){logger[_0x94b9('0x10')](_0x94b9('0x18'),_0x34bf4b);logger[_0x94b9('0x22')](_0x94b9('0x18'),_0x34bf4b,JSON[_0x94b9('0x13')](_0x530b4f));_0x4da917(_0x530b4f);})[_0x94b9('0x17')](function(_0x56f8d9){logger[_0x94b9('0x14')]('UpdateWhatsappInteraction',_0x56f8d9[_0x94b9('0x16')],_0x34bf4b);_0x977aa7(_0x5ae0cf[_0x94b9('0x14')](0x1f4,_0x56f8d9[_0x94b9('0x16')]));});});};exports[_0x94b9('0x23')]=function(_0x20a0c5){return new Promise(function(_0x5b5c9e,_0x490afb){return db[_0x94b9('0x19')][_0x94b9('0x24')]({'where':_0x20a0c5[_0x94b9('0x1c')]?_0x20a0c5[_0x94b9('0x1c')][_0x94b9('0x1e')]||null:null})[_0x94b9('0x21')](function(_0x540a57){if(_0x540a57){return _0x540a57[_0x94b9('0x25')](_0x20a0c5['body'][_0x94b9('0x26')],_[_0x94b9('0x27')](_0x20a0c5[_0x94b9('0x1b')],[_0x94b9('0x26'),'id'])||{});}})[_0x94b9('0x28')](function(_0x3ea151){logger[_0x94b9('0x10')]('AddTags',_0x20a0c5);logger[_0x94b9('0x22')](_0x94b9('0x29'),_0x20a0c5,JSON['stringify'](_0x3ea151));_0x5b5c9e(_0x3ea151);})[_0x94b9('0x17')](function(_0x11ebcb){logger['error'](_0x94b9('0x29'),_0x11ebcb[_0x94b9('0x16')],_0x20a0c5);_0x490afb(_this['error'](0x1f4,_0x11ebcb[_0x94b9('0x16')]));});});};