96af3780d621e73ddc1d65f633ee06fb5c12550b
[motion2.git] / server / api / chatInteraction / chatInteraction.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 _0xe11f=['jayson/promise','redis','defaults','register','request','then','info','ChatInteraction,\x20%s,\x20%s','debug','ChatInteraction,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','message','result','catch','update','body','options','raw','limit','UpdateChatInteraction','ChatInteraction','find','ids','omit','spread','AddTags','util','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','../../config/environment'];(function(_0x53b63f,_0x37af4d){var _0x24aecb=function(_0x2a3a11){while(--_0x2a3a11){_0x53b63f['push'](_0x53b63f['shift']());}};_0x24aecb(++_0x37af4d);}(_0xe11f,0x1b3));var _0xfe11=function(_0x42eab0,_0x2442e0){_0x42eab0=_0x42eab0-0x0;var _0x4c3f19=_0xe11f[_0x42eab0];return _0x4c3f19;};'use strict';var _=require('lodash');var util=require(_0xfe11('0x0'));var moment=require(_0xfe11('0x1'));var BPromise=require(_0xfe11('0x2'));var rs=require(_0xfe11('0x3'));var fs=require('fs');var Redis=require(_0xfe11('0x4'));var db=require(_0xfe11('0x5'))['db'];var utils=require(_0xfe11('0x6'));var logger=require(_0xfe11('0x7'))('rpc');var config=require(_0xfe11('0x8'));var jayson=require(_0xfe11('0x9'));var client=jayson['client']['http']({'port':0x232a});config[_0xfe11('0xa')]=_[_0xfe11('0xb')](config[_0xfe11('0xa')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require('./chatInteraction.socket')[_0xfe11('0xc')](socket);function respondWithRpcPromise(_0x1c95c1,_0xa00612,_0x5c576e){return new BPromise(function(_0x3ca0ed,_0x1e06a9){return client[_0xfe11('0xd')](_0x1c95c1,_0x5c576e)[_0xfe11('0xe')](function(_0x4da62d){logger[_0xfe11('0xf')](_0xfe11('0x10'),_0xa00612,'request\x20sent');logger[_0xfe11('0x11')](_0xfe11('0x12'),_0xa00612,_0xfe11('0x13'),JSON[_0xfe11('0x14')](_0x4da62d));if(_0x4da62d[_0xfe11('0x15')]){if(_0x4da62d[_0xfe11('0x15')]['code']===0x1f4){logger[_0xfe11('0x15')](_0xfe11('0x10'),_0xa00612,_0x4da62d[_0xfe11('0x15')][_0xfe11('0x16')]);return _0x1e06a9(_0x4da62d[_0xfe11('0x15')][_0xfe11('0x16')]);}logger['error'](_0xfe11('0x10'),_0xa00612,_0x4da62d[_0xfe11('0x15')][_0xfe11('0x16')]);return _0x3ca0ed(_0x4da62d[_0xfe11('0x15')][_0xfe11('0x16')]);}else{logger['info'](_0xfe11('0x10'),_0xa00612,_0xfe11('0x13'));_0x3ca0ed(_0x4da62d[_0xfe11('0x17')][_0xfe11('0x16')]);}})[_0xfe11('0x18')](function(_0x5ba26b){logger[_0xfe11('0x15')](_0xfe11('0x10'),_0xa00612,_0x5ba26b);_0x1e06a9(_0x5ba26b);});});}exports['UpdateChatInteraction']=function(_0x19aedd){var _0x36e419=this;return new Promise(function(_0x570b8f,_0x4befae){return db['ChatInteraction'][_0xfe11('0x19')](_0x19aedd[_0xfe11('0x1a')],{'raw':_0x19aedd[_0xfe11('0x1b')]?_0x19aedd[_0xfe11('0x1b')][_0xfe11('0x1c')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x19aedd[_0xfe11('0x1b')]?_0x19aedd[_0xfe11('0x1b')]['where']||null:null,'attributes':_0x19aedd[_0xfe11('0x1b')]?_0x19aedd['options']['attributes']||null:null,'limit':_0x19aedd['options']?_0x19aedd[_0xfe11('0x1b')][_0xfe11('0x1d')]||null:null})[_0xfe11('0xe')](function(_0x413386){logger[_0xfe11('0xf')](_0xfe11('0x1e'),_0x19aedd);logger[_0xfe11('0x11')](_0xfe11('0x1e'),_0x19aedd,JSON['stringify'](_0x413386));_0x570b8f(_0x413386);})['catch'](function(_0x6dc8dd){logger[_0xfe11('0x15')]('UpdateChatInteraction',_0x6dc8dd[_0xfe11('0x16')],_0x19aedd);_0x4befae(_0x36e419[_0xfe11('0x15')](0x1f4,_0x6dc8dd[_0xfe11('0x16')]));});});};exports['AddTagsToChatInteraction']=function(_0x55da59){return new Promise(function(_0x485c6c,_0x4e0412){return db[_0xfe11('0x1f')][_0xfe11('0x20')]({'where':_0x55da59[_0xfe11('0x1b')]?_0x55da59[_0xfe11('0x1b')]['where']||null:null})[_0xfe11('0xe')](function(_0x232f67){if(_0x232f67){return _0x232f67['addTags'](_0x55da59[_0xfe11('0x1a')][_0xfe11('0x21')],_[_0xfe11('0x22')](_0x55da59['body'],['ids','id'])||{});}})[_0xfe11('0x23')](function(_0x2026ee){logger[_0xfe11('0xf')](_0xfe11('0x24'),_0x55da59);logger[_0xfe11('0x11')](_0xfe11('0x24'),_0x55da59,JSON[_0xfe11('0x14')](_0x2026ee));_0x485c6c(_0x2026ee);})[_0xfe11('0x18')](function(_0x324912){logger[_0xfe11('0x15')]('AddTags',_0x324912[_0xfe11('0x16')],_0x55da59);_0x4e0412(_this[_0xfe11('0x15')](0x1f4,_0x324912[_0xfe11('0x16')]));});});};