94fecdb160c7ea59f97a2ef678290d8bcdcb738b
[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 _0x9a3e=['socket.io-emitter','./chatInteraction.socket','register','then','info','debug','ChatInteraction,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','ChatInteraction,\x20%s,\x20%s','message','result','catch','ChatInteraction','update','options','raw','limit','UpdateChatInteraction','find','where','body','ids','omit','spread','AddTags','lodash','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','rpc','../../config/environment','jayson/promise','client','http','redis','localhost'];(function(_0x1deb03,_0xd05ad8){var _0x189fe7=function(_0x321225){while(--_0x321225){_0x1deb03['push'](_0x1deb03['shift']());}};_0x189fe7(++_0xd05ad8);}(_0x9a3e,0x133));var _0xe9a3=function(_0x37ca2d,_0x3075a3){_0x37ca2d=_0x37ca2d-0x0;var _0x598608=_0x9a3e[_0x37ca2d];return _0x598608;};'use strict';var _=require(_0xe9a3('0x0'));var util=require('util');var moment=require('moment');var BPromise=require(_0xe9a3('0x1'));var rs=require(_0xe9a3('0x2'));var fs=require('fs');var Redis=require(_0xe9a3('0x3'));var db=require(_0xe9a3('0x4'))['db'];var utils=require(_0xe9a3('0x5'));var logger=require('../../config/logger')(_0xe9a3('0x6'));var config=require(_0xe9a3('0x7'));var jayson=require(_0xe9a3('0x8'));var client=jayson[_0xe9a3('0x9')][_0xe9a3('0xa')]({'port':0x232a});config[_0xe9a3('0xb')]=_['defaults'](config[_0xe9a3('0xb')],{'host':_0xe9a3('0xc'),'port':0x18eb});var socket=require(_0xe9a3('0xd'))(new Redis(config[_0xe9a3('0xb')]));require(_0xe9a3('0xe'))[_0xe9a3('0xf')](socket);function respondWithRpcPromise(_0x1611fa,_0x41df4f,_0x44b38e){return new BPromise(function(_0x4ffaf4,_0x4fcf3c){return client['request'](_0x1611fa,_0x44b38e)[_0xe9a3('0x10')](function(_0x380038){logger[_0xe9a3('0x11')]('ChatInteraction,\x20%s,\x20%s',_0x41df4f,'request\x20sent');logger[_0xe9a3('0x12')](_0xe9a3('0x13'),_0x41df4f,_0xe9a3('0x14'),JSON[_0xe9a3('0x15')](_0x380038));if(_0x380038['error']){if(_0x380038[_0xe9a3('0x16')]['code']===0x1f4){logger[_0xe9a3('0x16')](_0xe9a3('0x17'),_0x41df4f,_0x380038[_0xe9a3('0x16')][_0xe9a3('0x18')]);return _0x4fcf3c(_0x380038['error'][_0xe9a3('0x18')]);}logger[_0xe9a3('0x16')](_0xe9a3('0x17'),_0x41df4f,_0x380038['error'][_0xe9a3('0x18')]);return _0x4ffaf4(_0x380038[_0xe9a3('0x16')][_0xe9a3('0x18')]);}else{logger[_0xe9a3('0x11')](_0xe9a3('0x17'),_0x41df4f,_0xe9a3('0x14'));_0x4ffaf4(_0x380038[_0xe9a3('0x19')][_0xe9a3('0x18')]);}})[_0xe9a3('0x1a')](function(_0x5df7e4){logger[_0xe9a3('0x16')]('ChatInteraction,\x20%s,\x20%s',_0x41df4f,_0x5df7e4);_0x4fcf3c(_0x5df7e4);});});}exports['UpdateChatInteraction']=function(_0x25db66){var _0x1049da=this;return new Promise(function(_0x5d4fbd,_0x5c1ec4){return db[_0xe9a3('0x1b')][_0xe9a3('0x1c')](_0x25db66['body'],{'raw':_0x25db66['options']?_0x25db66[_0xe9a3('0x1d')][_0xe9a3('0x1e')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x25db66[_0xe9a3('0x1d')]?_0x25db66[_0xe9a3('0x1d')]['where']||null:null,'attributes':_0x25db66[_0xe9a3('0x1d')]?_0x25db66[_0xe9a3('0x1d')]['attributes']||null:null,'limit':_0x25db66[_0xe9a3('0x1d')]?_0x25db66['options'][_0xe9a3('0x1f')]||null:null})[_0xe9a3('0x10')](function(_0x44ecaf){logger[_0xe9a3('0x11')](_0xe9a3('0x20'),_0x25db66);logger['debug']('UpdateChatInteraction',_0x25db66,JSON[_0xe9a3('0x15')](_0x44ecaf));_0x5d4fbd(_0x44ecaf);})[_0xe9a3('0x1a')](function(_0x451f5a){logger[_0xe9a3('0x16')](_0xe9a3('0x20'),_0x451f5a['message'],_0x25db66);_0x5c1ec4(_0x1049da['error'](0x1f4,_0x451f5a[_0xe9a3('0x18')]));});});};exports['AddTagsToChatInteraction']=function(_0x8d28a8){return new Promise(function(_0x1ce1b5,_0x4d34b9){return db['ChatInteraction'][_0xe9a3('0x21')]({'where':_0x8d28a8['options']?_0x8d28a8['options'][_0xe9a3('0x22')]||null:null})[_0xe9a3('0x10')](function(_0x33f978){if(_0x33f978){return _0x33f978['addTags'](_0x8d28a8[_0xe9a3('0x23')][_0xe9a3('0x24')],_[_0xe9a3('0x25')](_0x8d28a8[_0xe9a3('0x23')],['ids','id'])||{});}})[_0xe9a3('0x26')](function(_0x31d285){logger[_0xe9a3('0x11')](_0xe9a3('0x27'),_0x8d28a8);logger[_0xe9a3('0x12')](_0xe9a3('0x27'),_0x8d28a8,JSON[_0xe9a3('0x15')](_0x31d285));_0x1ce1b5(_0x31d285);})[_0xe9a3('0x1a')](function(_0x2b17e4){logger[_0xe9a3('0x16')](_0xe9a3('0x27'),_0x2b17e4['message'],_0x8d28a8);_0x4d34b9(_this[_0xe9a3('0x16')](0x1f4,_0x2b17e4['message']));});});};