Built motion from commit 4c281f94.|2.6.31
[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 _0x6464=['./chatInteraction.socket','register','then','info','ChatInteraction,\x20%s,\x20%s','request\x20sent','ChatInteraction,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','UpdateChatInteraction','body','options','raw','where','attributes','limit','ChatInteraction','find','ids','spread','AddTags','debug','util','moment','bluebird','randomstring','../../mysqldb','../../config/logger','rpc','../../config/environment','jayson/promise','http','redis','defaults','localhost','socket.io-emitter'];(function(_0x32b423,_0x252697){var _0x414faf=function(_0x1df1ca){while(--_0x1df1ca){_0x32b423['push'](_0x32b423['shift']());}};_0x414faf(++_0x252697);}(_0x6464,0x1aa));var _0x4646=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x6464[_0x3dd15e];return _0x231fd0;};'use strict';var _=require('lodash');var util=require(_0x4646('0x0'));var moment=require(_0x4646('0x1'));var BPromise=require(_0x4646('0x2'));var rs=require(_0x4646('0x3'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0x4646('0x4'))['db'];var utils=require('../../config/utils');var logger=require(_0x4646('0x5'))(_0x4646('0x6'));var config=require(_0x4646('0x7'));var jayson=require(_0x4646('0x8'));var client=jayson['client'][_0x4646('0x9')]({'port':0x232a});config[_0x4646('0xa')]=_[_0x4646('0xb')](config['redis'],{'host':_0x4646('0xc'),'port':0x18eb});var socket=require(_0x4646('0xd'))(new Redis(config[_0x4646('0xa')]));require(_0x4646('0xe'))[_0x4646('0xf')](socket);function respondWithRpcPromise(_0x37630b,_0x3e836a,_0x2dc02e){return new BPromise(function(_0x2c4339,_0x57ebc9){return client['request'](_0x37630b,_0x2dc02e)[_0x4646('0x10')](function(_0x25c2c9){logger[_0x4646('0x11')](_0x4646('0x12'),_0x3e836a,_0x4646('0x13'));logger['debug'](_0x4646('0x14'),_0x3e836a,_0x4646('0x13'),JSON[_0x4646('0x15')](_0x25c2c9));if(_0x25c2c9[_0x4646('0x16')]){if(_0x25c2c9[_0x4646('0x16')][_0x4646('0x17')]===0x1f4){logger[_0x4646('0x16')](_0x4646('0x12'),_0x3e836a,_0x25c2c9['error'][_0x4646('0x18')]);return _0x57ebc9(_0x25c2c9[_0x4646('0x16')][_0x4646('0x18')]);}logger['error'](_0x4646('0x12'),_0x3e836a,_0x25c2c9[_0x4646('0x16')][_0x4646('0x18')]);return _0x2c4339(_0x25c2c9[_0x4646('0x16')][_0x4646('0x18')]);}else{logger[_0x4646('0x11')](_0x4646('0x12'),_0x3e836a,_0x4646('0x13'));_0x2c4339(_0x25c2c9[_0x4646('0x19')][_0x4646('0x18')]);}})[_0x4646('0x1a')](function(_0xad2134){logger[_0x4646('0x16')]('ChatInteraction,\x20%s,\x20%s',_0x3e836a,_0xad2134);_0x57ebc9(_0xad2134);});});}exports[_0x4646('0x1b')]=function(_0x543a88){var _0x4d1718=this;return new Promise(function(_0x1337d0,_0x5dfdfb){return db['ChatInteraction']['update'](_0x543a88[_0x4646('0x1c')],{'raw':_0x543a88['options']?_0x543a88[_0x4646('0x1d')][_0x4646('0x1e')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x543a88[_0x4646('0x1d')]?_0x543a88[_0x4646('0x1d')][_0x4646('0x1f')]||null:null,'attributes':_0x543a88[_0x4646('0x1d')]?_0x543a88[_0x4646('0x1d')][_0x4646('0x20')]||null:null,'limit':_0x543a88[_0x4646('0x1d')]?_0x543a88[_0x4646('0x1d')][_0x4646('0x21')]||null:null})[_0x4646('0x10')](function(_0x456829){logger[_0x4646('0x11')]('UpdateChatInteraction',_0x543a88);logger['debug'](_0x4646('0x1b'),_0x543a88,JSON['stringify'](_0x456829));_0x1337d0(_0x456829);})[_0x4646('0x1a')](function(_0x11dfc3){logger['error'](_0x4646('0x1b'),_0x11dfc3[_0x4646('0x18')],_0x543a88);_0x5dfdfb(_0x4d1718[_0x4646('0x16')](0x1f4,_0x11dfc3['message']));});});};exports['AddTagsToChatInteraction']=function(_0x1c7767){return new Promise(function(_0x495534,_0x25eebf){return db[_0x4646('0x22')][_0x4646('0x23')]({'where':_0x1c7767[_0x4646('0x1d')]?_0x1c7767[_0x4646('0x1d')][_0x4646('0x1f')]||null:null})[_0x4646('0x10')](function(_0x2a9ead){if(_0x2a9ead){return _0x2a9ead['addTags'](_0x1c7767[_0x4646('0x1c')][_0x4646('0x24')],_['omit'](_0x1c7767[_0x4646('0x1c')],[_0x4646('0x24'),'id'])||{});}})[_0x4646('0x25')](function(_0x575c33){logger[_0x4646('0x11')](_0x4646('0x26'),_0x1c7767);logger[_0x4646('0x27')](_0x4646('0x26'),_0x1c7767,JSON[_0x4646('0x15')](_0x575c33));_0x495534(_0x575c33);})['catch'](function(_0x771980){logger[_0x4646('0x16')](_0x4646('0x26'),_0x771980[_0x4646('0x18')],_0x1c7767);_0x25eebf(_this['error'](0x1f4,_0x771980['message']));});});};