Built motion from commit 25580385.|2.6.2
[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 _0x1725=['then','AddTagsToChatInteraction','ChatInteraction','find','omit','ids','AddTags','util','bluebird','randomstring','ioredis','../../mysqldb','rpc','client','http','defaults','localhost','socket.io-emitter','redis','./chatInteraction.socket','register','request','info','ChatInteraction,\x20%s,\x20%s','request\x20sent','debug','stringify','error','code','message','result','catch','UpdateChatInteraction','body','options','raw','where','limit'];(function(_0x118bb2,_0x57a6db){var _0x4be656=function(_0x585f26){while(--_0x585f26){_0x118bb2['push'](_0x118bb2['shift']());}};_0x4be656(++_0x57a6db);}(_0x1725,0x15d));var _0x5172=function(_0x55150d,_0x5689f2){_0x55150d=_0x55150d-0x0;var _0x25329f=_0x1725[_0x55150d];return _0x25329f;};'use strict';var _=require('lodash');var util=require(_0x5172('0x0'));var moment=require('moment');var BPromise=require(_0x5172('0x1'));var rs=require(_0x5172('0x2'));var fs=require('fs');var Redis=require(_0x5172('0x3'));var db=require(_0x5172('0x4'))['db'];var utils=require('../../config/utils');var logger=require('../../config/logger')(_0x5172('0x5'));var config=require('../../config/environment');var jayson=require('jayson/promise');var client=jayson[_0x5172('0x6')][_0x5172('0x7')]({'port':0x232a});config['redis']=_[_0x5172('0x8')](config['redis'],{'host':_0x5172('0x9'),'port':0x18eb});var socket=require(_0x5172('0xa'))(new Redis(config[_0x5172('0xb')]));require(_0x5172('0xc'))[_0x5172('0xd')](socket);function respondWithRpcPromise(_0xb5adbc,_0x5ab8b9,_0x52eff3){return new BPromise(function(_0x183779,_0x19187f){return client[_0x5172('0xe')](_0xb5adbc,_0x52eff3)['then'](function(_0x13cce4){logger[_0x5172('0xf')](_0x5172('0x10'),_0x5ab8b9,_0x5172('0x11'));logger[_0x5172('0x12')]('ChatInteraction,\x20%s,\x20%s,\x20%s',_0x5ab8b9,'request\x20sent',JSON[_0x5172('0x13')](_0x13cce4));if(_0x13cce4[_0x5172('0x14')]){if(_0x13cce4['error'][_0x5172('0x15')]===0x1f4){logger[_0x5172('0x14')](_0x5172('0x10'),_0x5ab8b9,_0x13cce4[_0x5172('0x14')]['message']);return _0x19187f(_0x13cce4['error'][_0x5172('0x16')]);}logger['error'](_0x5172('0x10'),_0x5ab8b9,_0x13cce4['error']['message']);return _0x183779(_0x13cce4[_0x5172('0x14')]['message']);}else{logger[_0x5172('0xf')](_0x5172('0x10'),_0x5ab8b9,_0x5172('0x11'));_0x183779(_0x13cce4[_0x5172('0x17')]['message']);}})[_0x5172('0x18')](function(_0x16ee65){logger['error']('ChatInteraction,\x20%s,\x20%s',_0x5ab8b9,_0x16ee65);_0x19187f(_0x16ee65);});});}exports[_0x5172('0x19')]=function(_0x6edda4){var _0x2a0927=this;return new Promise(function(_0x4f406f,_0xf211f2){return db['ChatInteraction']['update'](_0x6edda4[_0x5172('0x1a')],{'raw':_0x6edda4[_0x5172('0x1b')]?_0x6edda4['options'][_0x5172('0x1c')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x6edda4['options']?_0x6edda4[_0x5172('0x1b')][_0x5172('0x1d')]||null:null,'attributes':_0x6edda4['options']?_0x6edda4[_0x5172('0x1b')]['attributes']||null:null,'limit':_0x6edda4[_0x5172('0x1b')]?_0x6edda4[_0x5172('0x1b')][_0x5172('0x1e')]||null:null})[_0x5172('0x1f')](function(_0x50540f){logger[_0x5172('0xf')](_0x5172('0x19'),_0x6edda4);logger[_0x5172('0x12')](_0x5172('0x19'),_0x6edda4,JSON['stringify'](_0x50540f));_0x4f406f(_0x50540f);})['catch'](function(_0x48b4d4){logger[_0x5172('0x14')](_0x5172('0x19'),_0x48b4d4[_0x5172('0x16')],_0x6edda4);_0xf211f2(_0x2a0927[_0x5172('0x14')](0x1f4,_0x48b4d4[_0x5172('0x16')]));});});};exports[_0x5172('0x20')]=function(_0x2ef4f8){return new Promise(function(_0xd26fba,_0x3454c7){return db[_0x5172('0x21')][_0x5172('0x22')]({'where':_0x2ef4f8[_0x5172('0x1b')]?_0x2ef4f8[_0x5172('0x1b')][_0x5172('0x1d')]||null:null})['then'](function(_0x133558){if(_0x133558){return _0x133558['addTags'](_0x2ef4f8['body']['ids'],_[_0x5172('0x23')](_0x2ef4f8[_0x5172('0x1a')],[_0x5172('0x24'),'id'])||{});}})['spread'](function(_0x30b11e){logger[_0x5172('0xf')](_0x5172('0x25'),_0x2ef4f8);logger[_0x5172('0x12')]('AddTags',_0x2ef4f8,JSON['stringify'](_0x30b11e));_0xd26fba(_0x30b11e);})[_0x5172('0x18')](function(_0x328c9f){logger[_0x5172('0x14')]('AddTags',_0x328c9f[_0x5172('0x16')],_0x2ef4f8);_0x3454c7(_this['error'](0x1f4,_0x328c9f[_0x5172('0x16')]));});});};