7df657424f2beed25049baf436776d84425c6edd
[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 _0x8b65=['update','body','options','where','limit','catch','AddTagsToChatInteraction','find','addTags','ids','omit','spread','AddTags','lodash','util','moment','bluebird','randomstring','ioredis','../../config/utils','../../config/logger','jayson/promise','http','redis','defaults','socket.io-emitter','register','request','then','info','request\x20sent','debug','ChatInteraction,\x20%s,\x20%s,\x20%s','stringify','error','code','ChatInteraction,\x20%s,\x20%s','message','UpdateChatInteraction','ChatInteraction'];(function(_0x409fb8,_0x5ab3d3){var _0x278270=function(_0x58849c){while(--_0x58849c){_0x409fb8['push'](_0x409fb8['shift']());}};_0x278270(++_0x5ab3d3);}(_0x8b65,0x175));var _0x58b6=function(_0x12cf86,_0x4e840c){_0x12cf86=_0x12cf86-0x0;var _0x40baa=_0x8b65[_0x12cf86];return _0x40baa;};'use strict';var _=require(_0x58b6('0x0'));var util=require(_0x58b6('0x1'));var moment=require(_0x58b6('0x2'));var BPromise=require(_0x58b6('0x3'));var rs=require(_0x58b6('0x4'));var fs=require('fs');var Redis=require(_0x58b6('0x5'));var db=require('../../mysqldb')['db'];var utils=require(_0x58b6('0x6'));var logger=require(_0x58b6('0x7'))('rpc');var config=require('../../config/environment');var jayson=require(_0x58b6('0x8'));var client=jayson['client'][_0x58b6('0x9')]({'port':0x232a});config[_0x58b6('0xa')]=_[_0x58b6('0xb')](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0x58b6('0xc'))(new Redis(config[_0x58b6('0xa')]));require('./chatInteraction.socket')[_0x58b6('0xd')](socket);function respondWithRpcPromise(_0x46011f,_0x33183f,_0x4ed709){return new BPromise(function(_0x14103a,_0x5be54f){return client[_0x58b6('0xe')](_0x46011f,_0x4ed709)[_0x58b6('0xf')](function(_0x59a394){logger[_0x58b6('0x10')]('ChatInteraction,\x20%s,\x20%s',_0x33183f,_0x58b6('0x11'));logger[_0x58b6('0x12')](_0x58b6('0x13'),_0x33183f,_0x58b6('0x11'),JSON[_0x58b6('0x14')](_0x59a394));if(_0x59a394['error']){if(_0x59a394[_0x58b6('0x15')][_0x58b6('0x16')]===0x1f4){logger[_0x58b6('0x15')](_0x58b6('0x17'),_0x33183f,_0x59a394['error'][_0x58b6('0x18')]);return _0x5be54f(_0x59a394[_0x58b6('0x15')][_0x58b6('0x18')]);}logger['error'](_0x58b6('0x17'),_0x33183f,_0x59a394[_0x58b6('0x15')][_0x58b6('0x18')]);return _0x14103a(_0x59a394[_0x58b6('0x15')][_0x58b6('0x18')]);}else{logger['info']('ChatInteraction,\x20%s,\x20%s',_0x33183f,'request\x20sent');_0x14103a(_0x59a394['result'][_0x58b6('0x18')]);}})['catch'](function(_0x3d0777){logger[_0x58b6('0x15')](_0x58b6('0x17'),_0x33183f,_0x3d0777);_0x5be54f(_0x3d0777);});});}exports[_0x58b6('0x19')]=function(_0x1b4076){var _0x44c7ee=this;return new Promise(function(_0x26cb3f,_0x5ec10d){return db[_0x58b6('0x1a')][_0x58b6('0x1b')](_0x1b4076[_0x58b6('0x1c')],{'raw':_0x1b4076['options']?_0x1b4076[_0x58b6('0x1d')]['raw']===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x1b4076['options']?_0x1b4076['options'][_0x58b6('0x1e')]||null:null,'attributes':_0x1b4076[_0x58b6('0x1d')]?_0x1b4076['options']['attributes']||null:null,'limit':_0x1b4076[_0x58b6('0x1d')]?_0x1b4076[_0x58b6('0x1d')][_0x58b6('0x1f')]||null:null})['then'](function(_0x22a878){logger[_0x58b6('0x10')](_0x58b6('0x19'),_0x1b4076);logger[_0x58b6('0x12')](_0x58b6('0x19'),_0x1b4076,JSON[_0x58b6('0x14')](_0x22a878));_0x26cb3f(_0x22a878);})[_0x58b6('0x20')](function(_0x4cba7b){logger[_0x58b6('0x15')](_0x58b6('0x19'),_0x4cba7b['message'],_0x1b4076);_0x5ec10d(_0x44c7ee[_0x58b6('0x15')](0x1f4,_0x4cba7b[_0x58b6('0x18')]));});});};exports[_0x58b6('0x21')]=function(_0x3a09bf){return new Promise(function(_0x58c2eb,_0x17fd27){return db['ChatInteraction'][_0x58b6('0x22')]({'where':_0x3a09bf['options']?_0x3a09bf[_0x58b6('0x1d')][_0x58b6('0x1e')]||null:null})[_0x58b6('0xf')](function(_0x5d5cf7){if(_0x5d5cf7){return _0x5d5cf7[_0x58b6('0x23')](_0x3a09bf[_0x58b6('0x1c')][_0x58b6('0x24')],_[_0x58b6('0x25')](_0x3a09bf[_0x58b6('0x1c')],[_0x58b6('0x24'),'id'])||{});}})[_0x58b6('0x26')](function(_0x5d1f18){logger[_0x58b6('0x10')](_0x58b6('0x27'),_0x3a09bf);logger[_0x58b6('0x12')](_0x58b6('0x27'),_0x3a09bf,JSON[_0x58b6('0x14')](_0x5d1f18));_0x58c2eb(_0x5d1f18);})[_0x58b6('0x20')](function(_0xdfc8aa){logger[_0x58b6('0x15')](_0x58b6('0x27'),_0xdfc8aa[_0x58b6('0x18')],_0x3a09bf);_0x17fd27(_this['error'](0x1f4,_0xdfc8aa[_0x58b6('0x18')]));});});};