Built motion from commit (unavailable).|2.5.30
[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 _0xcf40=['ChatInteraction','body','options','raw','where','attributes','limit','find','addTags','ids','spread','AddTags','lodash','moment','randomstring','ioredis','../../mysqldb','../../config/logger','../../config/environment','client','http','redis','defaults','./chatInteraction.socket','register','then','info','ChatInteraction,\x20%s,\x20%s','debug','ChatInteraction,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','catch','UpdateChatInteraction'];(function(_0x4c8bc2,_0x21cdc6){var _0x30c586=function(_0x4a0425){while(--_0x4a0425){_0x4c8bc2['push'](_0x4c8bc2['shift']());}};_0x30c586(++_0x21cdc6);}(_0xcf40,0x159));var _0x0cf4=function(_0x41acc3,_0x102803){_0x41acc3=_0x41acc3-0x0;var _0xe2344c=_0xcf40[_0x41acc3];return _0xe2344c;};'use strict';var _=require(_0x0cf4('0x0'));var util=require('util');var moment=require(_0x0cf4('0x1'));var BPromise=require('bluebird');var rs=require(_0x0cf4('0x2'));var fs=require('fs');var Redis=require(_0x0cf4('0x3'));var db=require(_0x0cf4('0x4'))['db'];var utils=require('../../config/utils');var logger=require(_0x0cf4('0x5'))('rpc');var config=require(_0x0cf4('0x6'));var jayson=require('jayson/promise');var client=jayson[_0x0cf4('0x7')][_0x0cf4('0x8')]({'port':0x232a});config[_0x0cf4('0x9')]=_[_0x0cf4('0xa')](config[_0x0cf4('0x9')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x0cf4('0x9')]));require(_0x0cf4('0xb'))[_0x0cf4('0xc')](socket);function respondWithRpcPromise(_0x37b4ba,_0x146c3e,_0x26a686){return new BPromise(function(_0x1a4ba3,_0x7078c4){return client['request'](_0x37b4ba,_0x26a686)[_0x0cf4('0xd')](function(_0x1310e8){logger[_0x0cf4('0xe')](_0x0cf4('0xf'),_0x146c3e,'request\x20sent');logger[_0x0cf4('0x10')](_0x0cf4('0x11'),_0x146c3e,_0x0cf4('0x12'),JSON[_0x0cf4('0x13')](_0x1310e8));if(_0x1310e8[_0x0cf4('0x14')]){if(_0x1310e8[_0x0cf4('0x14')][_0x0cf4('0x15')]===0x1f4){logger[_0x0cf4('0x14')](_0x0cf4('0xf'),_0x146c3e,_0x1310e8[_0x0cf4('0x14')][_0x0cf4('0x16')]);return _0x7078c4(_0x1310e8[_0x0cf4('0x14')][_0x0cf4('0x16')]);}logger[_0x0cf4('0x14')]('ChatInteraction,\x20%s,\x20%s',_0x146c3e,_0x1310e8[_0x0cf4('0x14')][_0x0cf4('0x16')]);return _0x1a4ba3(_0x1310e8['error'][_0x0cf4('0x16')]);}else{logger[_0x0cf4('0xe')](_0x0cf4('0xf'),_0x146c3e,'request\x20sent');_0x1a4ba3(_0x1310e8['result']['message']);}})[_0x0cf4('0x17')](function(_0x4e8a02){logger[_0x0cf4('0x14')](_0x0cf4('0xf'),_0x146c3e,_0x4e8a02);_0x7078c4(_0x4e8a02);});});}exports[_0x0cf4('0x18')]=function(_0x32a2b7){var _0x2bc59f=this;return new Promise(function(_0x185bf4,_0xef654a){return db[_0x0cf4('0x19')]['update'](_0x32a2b7[_0x0cf4('0x1a')],{'raw':_0x32a2b7[_0x0cf4('0x1b')]?_0x32a2b7[_0x0cf4('0x1b')][_0x0cf4('0x1c')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x32a2b7[_0x0cf4('0x1b')]?_0x32a2b7['options'][_0x0cf4('0x1d')]||null:null,'attributes':_0x32a2b7[_0x0cf4('0x1b')]?_0x32a2b7[_0x0cf4('0x1b')][_0x0cf4('0x1e')]||null:null,'limit':_0x32a2b7[_0x0cf4('0x1b')]?_0x32a2b7['options'][_0x0cf4('0x1f')]||null:null})['then'](function(_0x4750e5){logger[_0x0cf4('0xe')](_0x0cf4('0x18'),_0x32a2b7);logger['debug']('UpdateChatInteraction',_0x32a2b7,JSON[_0x0cf4('0x13')](_0x4750e5));_0x185bf4(_0x4750e5);})['catch'](function(_0x51100e){logger['error'](_0x0cf4('0x18'),_0x51100e['message'],_0x32a2b7);_0xef654a(_0x2bc59f[_0x0cf4('0x14')](0x1f4,_0x51100e['message']));});});};exports['AddTagsToChatInteraction']=function(_0x8d6785){return new Promise(function(_0x3e2d42,_0x337b5f){return db[_0x0cf4('0x19')][_0x0cf4('0x20')]({'where':_0x8d6785['options']?_0x8d6785['options'][_0x0cf4('0x1d')]||null:null})[_0x0cf4('0xd')](function(_0x310672){if(_0x310672){return _0x310672[_0x0cf4('0x21')](_0x8d6785[_0x0cf4('0x1a')][_0x0cf4('0x22')],_['omit'](_0x8d6785['body'],['ids','id'])||{});}})[_0x0cf4('0x23')](function(_0x119e2a){logger[_0x0cf4('0xe')](_0x0cf4('0x24'),_0x8d6785);logger[_0x0cf4('0x10')](_0x0cf4('0x24'),_0x8d6785,JSON['stringify'](_0x119e2a));_0x3e2d42(_0x119e2a);})[_0x0cf4('0x17')](function(_0x13e253){logger[_0x0cf4('0x14')](_0x0cf4('0x24'),_0x13e253['message'],_0x8d6785);_0x337b5f(_this[_0x0cf4('0x14')](0x1f4,_0x13e253[_0x0cf4('0x16')]));});});};