Built motion from commit (unavailable).|2.5.14
[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 _0xf111=['info','ChatInteraction,\x20%s,\x20%s','request\x20sent','ChatInteraction,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','UpdateChatInteraction','ChatInteraction','body','options','raw','debug','AddTagsToChatInteraction','where','AddTags','util','moment','bluebird','ioredis','../../mysqldb','../../config/logger','rpc','../../config/environment','jayson/promise','client','http','redis','localhost','./chatInteraction.socket','register','then'];(function(_0x119b3e,_0x588d50){var _0x1169ae=function(_0x377422){while(--_0x377422){_0x119b3e['push'](_0x119b3e['shift']());}};_0x1169ae(++_0x588d50);}(_0xf111,0x9f));var _0x1f11=function(_0x2eb3db,_0x4a32c0){_0x2eb3db=_0x2eb3db-0x0;var _0x358f33=_0xf111[_0x2eb3db];return _0x358f33;};'use strict';var _=require('lodash');var util=require(_0x1f11('0x0'));var moment=require(_0x1f11('0x1'));var BPromise=require(_0x1f11('0x2'));var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x1f11('0x3'));var db=require(_0x1f11('0x4'))['db'];var utils=require('../../config/utils');var logger=require(_0x1f11('0x5'))(_0x1f11('0x6'));var config=require(_0x1f11('0x7'));var jayson=require(_0x1f11('0x8'));var client=jayson[_0x1f11('0x9')][_0x1f11('0xa')]({'port':0x232a});config[_0x1f11('0xb')]=_['defaults'](config['redis'],{'host':_0x1f11('0xc'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x1f11('0xb')]));require(_0x1f11('0xd'))[_0x1f11('0xe')](socket);function respondWithRpcPromise(_0x2dea96,_0x5a626c,_0x143463){return new BPromise(function(_0x1fc3cd,_0x297659){return client['request'](_0x2dea96,_0x143463)[_0x1f11('0xf')](function(_0x1fd91b){logger[_0x1f11('0x10')](_0x1f11('0x11'),_0x5a626c,_0x1f11('0x12'));logger['debug'](_0x1f11('0x13'),_0x5a626c,_0x1f11('0x12'),JSON[_0x1f11('0x14')](_0x1fd91b));if(_0x1fd91b[_0x1f11('0x15')]){if(_0x1fd91b['error'][_0x1f11('0x16')]===0x1f4){logger[_0x1f11('0x15')](_0x1f11('0x11'),_0x5a626c,_0x1fd91b['error'][_0x1f11('0x17')]);return _0x297659(_0x1fd91b['error'][_0x1f11('0x17')]);}logger[_0x1f11('0x15')](_0x1f11('0x11'),_0x5a626c,_0x1fd91b[_0x1f11('0x15')]['message']);return _0x1fc3cd(_0x1fd91b[_0x1f11('0x15')][_0x1f11('0x17')]);}else{logger[_0x1f11('0x10')](_0x1f11('0x11'),_0x5a626c,_0x1f11('0x12'));_0x1fc3cd(_0x1fd91b[_0x1f11('0x18')][_0x1f11('0x17')]);}})[_0x1f11('0x19')](function(_0x4388ed){logger['error'](_0x1f11('0x11'),_0x5a626c,_0x4388ed);_0x297659(_0x4388ed);});});}exports[_0x1f11('0x1a')]=function(_0x2088b7){var _0x46b606=this;return new Promise(function(_0x5d607e,_0x3b74ad){return db[_0x1f11('0x1b')]['update'](_0x2088b7[_0x1f11('0x1c')],{'raw':_0x2088b7['options']?_0x2088b7[_0x1f11('0x1d')][_0x1f11('0x1e')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x2088b7[_0x1f11('0x1d')]?_0x2088b7[_0x1f11('0x1d')]['where']||null:null,'attributes':_0x2088b7['options']?_0x2088b7[_0x1f11('0x1d')]['attributes']||null:null,'limit':_0x2088b7['options']?_0x2088b7['options']['limit']||null:null})[_0x1f11('0xf')](function(_0x344657){logger[_0x1f11('0x10')]('UpdateChatInteraction',_0x2088b7);logger[_0x1f11('0x1f')]('UpdateChatInteraction',_0x2088b7,JSON[_0x1f11('0x14')](_0x344657));_0x5d607e(_0x344657);})['catch'](function(_0x171a44){logger['error'](_0x1f11('0x1a'),_0x171a44[_0x1f11('0x17')],_0x2088b7);_0x3b74ad(_0x46b606['error'](0x1f4,_0x171a44[_0x1f11('0x17')]));});});};exports[_0x1f11('0x20')]=function(_0x57fd7d){return new Promise(function(_0x1c975c,_0x2621fa){return db[_0x1f11('0x1b')]['find']({'where':_0x57fd7d['options']?_0x57fd7d[_0x1f11('0x1d')][_0x1f11('0x21')]||null:null})['then'](function(_0x16e595){if(_0x16e595){return _0x16e595['addTags'](_0x57fd7d[_0x1f11('0x1c')]['ids'],_['omit'](_0x57fd7d[_0x1f11('0x1c')],['ids','id'])||{});}})['spread'](function(_0x30d212){logger['info']('AddTags',_0x57fd7d);logger[_0x1f11('0x1f')](_0x1f11('0x22'),_0x57fd7d,JSON[_0x1f11('0x14')](_0x30d212));_0x1c975c(_0x30d212);})['catch'](function(_0x424db2){logger[_0x1f11('0x15')](_0x1f11('0x22'),_0x424db2[_0x1f11('0x17')],_0x57fd7d);_0x2621fa(_this[_0x1f11('0x15')](0x1f4,_0x424db2['message']));});});};