c4339c7de37a30933be5326c339f5355f1c57870
[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 _0x1e9c=['client','http','redis','socket.io-emitter','./whatsappInteraction.socket','register','request','then','info','WhatsappInteraction,\x20%s,\x20%s','request\x20sent','WhatsappInteraction,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','WhatsappInteraction','update','body','options','where','UpdateWhatsappInteraction','debug','AddTagsToWhatsappInteraction','find','addTags','spread','AddTags','lodash','moment','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise'];(function(_0x13e093,_0x5970c3){var _0x5b3634=function(_0x460f16){while(--_0x460f16){_0x13e093['push'](_0x13e093['shift']());}};_0x5b3634(++_0x5970c3);}(_0x1e9c,0x6e));var _0xc1e9=function(_0x26462c,_0xd20a35){_0x26462c=_0x26462c-0x0;var _0x509a42=_0x1e9c[_0x26462c];return _0x509a42;};'use strict';var _=require(_0xc1e9('0x0'));var util=require('util');var moment=require(_0xc1e9('0x1'));var BPromise=require('bluebird');var rs=require(_0xc1e9('0x2'));var fs=require('fs');var Redis=require(_0xc1e9('0x3'));var db=require(_0xc1e9('0x4'))['db'];var utils=require(_0xc1e9('0x5'));var logger=require(_0xc1e9('0x6'))(_0xc1e9('0x7'));var config=require(_0xc1e9('0x8'));var jayson=require(_0xc1e9('0x9'));var client=jayson[_0xc1e9('0xa')][_0xc1e9('0xb')]({'port':0x232a});config[_0xc1e9('0xc')]=_['defaults'](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0xc1e9('0xd'))(new Redis(config[_0xc1e9('0xc')]));require(_0xc1e9('0xe'))[_0xc1e9('0xf')](socket);function respondWithRpcPromise(_0x332d08,_0x4e713f,_0x1cc07b){return new BPromise(function(_0x5107d7,_0x26c484){return client[_0xc1e9('0x10')](_0x332d08,_0x1cc07b)[_0xc1e9('0x11')](function(_0x2906fc){logger[_0xc1e9('0x12')](_0xc1e9('0x13'),_0x4e713f,_0xc1e9('0x14'));logger['debug'](_0xc1e9('0x15'),_0x4e713f,_0xc1e9('0x14'),JSON[_0xc1e9('0x16')](_0x2906fc));if(_0x2906fc[_0xc1e9('0x17')]){if(_0x2906fc[_0xc1e9('0x17')][_0xc1e9('0x18')]===0x1f4){logger[_0xc1e9('0x17')](_0xc1e9('0x13'),_0x4e713f,_0x2906fc[_0xc1e9('0x17')][_0xc1e9('0x19')]);return _0x26c484(_0x2906fc[_0xc1e9('0x17')][_0xc1e9('0x19')]);}logger[_0xc1e9('0x17')]('WhatsappInteraction,\x20%s,\x20%s',_0x4e713f,_0x2906fc[_0xc1e9('0x17')][_0xc1e9('0x19')]);return _0x5107d7(_0x2906fc[_0xc1e9('0x17')][_0xc1e9('0x19')]);}else{logger['info'](_0xc1e9('0x13'),_0x4e713f,_0xc1e9('0x14'));_0x5107d7(_0x2906fc[_0xc1e9('0x1a')][_0xc1e9('0x19')]);}})[_0xc1e9('0x1b')](function(_0x17d10c){logger[_0xc1e9('0x17')](_0xc1e9('0x13'),_0x4e713f,_0x17d10c);_0x26c484(_0x17d10c);});});}exports['UpdateWhatsappInteraction']=function(_0x11458c){var _0x446c18=this;return new Promise(function(_0x401f80,_0x1a84d7){return db[_0xc1e9('0x1c')][_0xc1e9('0x1d')](_0x11458c[_0xc1e9('0x1e')],{'raw':_0x11458c[_0xc1e9('0x1f')]?_0x11458c[_0xc1e9('0x1f')]['raw']===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x11458c['options']?_0x11458c[_0xc1e9('0x1f')][_0xc1e9('0x20')]||null:null,'attributes':_0x11458c[_0xc1e9('0x1f')]?_0x11458c[_0xc1e9('0x1f')]['attributes']||null:null,'limit':_0x11458c['options']?_0x11458c['options']['limit']||null:null})[_0xc1e9('0x11')](function(_0x30c4ec){logger[_0xc1e9('0x12')](_0xc1e9('0x21'),_0x11458c);logger[_0xc1e9('0x22')](_0xc1e9('0x21'),_0x11458c,JSON[_0xc1e9('0x16')](_0x30c4ec));_0x401f80(_0x30c4ec);})[_0xc1e9('0x1b')](function(_0x56333b){logger[_0xc1e9('0x17')](_0xc1e9('0x21'),_0x56333b[_0xc1e9('0x19')],_0x11458c);_0x1a84d7(_0x446c18['error'](0x1f4,_0x56333b[_0xc1e9('0x19')]));});});};exports[_0xc1e9('0x23')]=function(_0x4fa972){return new Promise(function(_0x3d89c8,_0x4067e5){return db['WhatsappInteraction'][_0xc1e9('0x24')]({'where':_0x4fa972[_0xc1e9('0x1f')]?_0x4fa972['options'][_0xc1e9('0x20')]||null:null})['then'](function(_0x52a60a){if(_0x52a60a){return _0x52a60a[_0xc1e9('0x25')](_0x4fa972['body']['ids'],_['omit'](_0x4fa972['body'],['ids','id'])||{});}})[_0xc1e9('0x26')](function(_0x1de23f){logger[_0xc1e9('0x12')](_0xc1e9('0x27'),_0x4fa972);logger['debug']('AddTags',_0x4fa972,JSON[_0xc1e9('0x16')](_0x1de23f));_0x3d89c8(_0x1de23f);})[_0xc1e9('0x1b')](function(_0x2a3a1b){logger[_0xc1e9('0x17')](_0xc1e9('0x27'),_0x2a3a1b[_0xc1e9('0x19')],_0x4fa972);_0x4067e5(_this['error'](0x1f4,_0x2a3a1b[_0xc1e9('0x19')]));});});};