bd08c91410e7022b09192c8b4135f26abe5148a3
[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 _0x2255=['jayson/promise','client','http','redis','defaults','socket.io-emitter','./chatInteraction.socket','register','request','then','info','ChatInteraction,\x20%s,\x20%s','debug','request\x20sent','stringify','error','code','message','result','catch','update','body','options','raw','attributes','limit','UpdateChatInteraction','AddTagsToChatInteraction','ChatInteraction','where','ids','omit','AddTags','util','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment'];(function(_0x3db278,_0x1b0b22){var _0x38ed71=function(_0x273bc1){while(--_0x273bc1){_0x3db278['push'](_0x3db278['shift']());}};_0x38ed71(++_0x1b0b22);}(_0x2255,0xa2));var _0x5225=function(_0x24744e,_0x3d070a){_0x24744e=_0x24744e-0x0;var _0x1c836c=_0x2255[_0x24744e];return _0x1c836c;};'use strict';var _=require('lodash');var util=require(_0x5225('0x0'));var moment=require(_0x5225('0x1'));var BPromise=require(_0x5225('0x2'));var rs=require(_0x5225('0x3'));var fs=require('fs');var Redis=require(_0x5225('0x4'));var db=require(_0x5225('0x5'))['db'];var utils=require(_0x5225('0x6'));var logger=require(_0x5225('0x7'))(_0x5225('0x8'));var config=require(_0x5225('0x9'));var jayson=require(_0x5225('0xa'));var client=jayson[_0x5225('0xb')][_0x5225('0xc')]({'port':0x232a});config[_0x5225('0xd')]=_[_0x5225('0xe')](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0x5225('0xf'))(new Redis(config[_0x5225('0xd')]));require(_0x5225('0x10'))[_0x5225('0x11')](socket);function respondWithRpcPromise(_0x1702ae,_0x5a70fd,_0x5c9ea4){return new BPromise(function(_0x5644d4,_0x1ef54c){return client[_0x5225('0x12')](_0x1702ae,_0x5c9ea4)[_0x5225('0x13')](function(_0x4f035e){logger[_0x5225('0x14')](_0x5225('0x15'),_0x5a70fd,'request\x20sent');logger[_0x5225('0x16')]('ChatInteraction,\x20%s,\x20%s,\x20%s',_0x5a70fd,_0x5225('0x17'),JSON[_0x5225('0x18')](_0x4f035e));if(_0x4f035e['error']){if(_0x4f035e[_0x5225('0x19')][_0x5225('0x1a')]===0x1f4){logger[_0x5225('0x19')](_0x5225('0x15'),_0x5a70fd,_0x4f035e[_0x5225('0x19')][_0x5225('0x1b')]);return _0x1ef54c(_0x4f035e['error'][_0x5225('0x1b')]);}logger[_0x5225('0x19')]('ChatInteraction,\x20%s,\x20%s',_0x5a70fd,_0x4f035e[_0x5225('0x19')][_0x5225('0x1b')]);return _0x5644d4(_0x4f035e['error']['message']);}else{logger[_0x5225('0x14')](_0x5225('0x15'),_0x5a70fd,_0x5225('0x17'));_0x5644d4(_0x4f035e[_0x5225('0x1c')][_0x5225('0x1b')]);}})[_0x5225('0x1d')](function(_0x3d66c7){logger['error'](_0x5225('0x15'),_0x5a70fd,_0x3d66c7);_0x1ef54c(_0x3d66c7);});});}exports['UpdateChatInteraction']=function(_0x4658ee){var _0x9dfbe9=this;return new Promise(function(_0x527b26,_0x2b2e5b){return db['ChatInteraction'][_0x5225('0x1e')](_0x4658ee[_0x5225('0x1f')],{'raw':_0x4658ee['options']?_0x4658ee[_0x5225('0x20')][_0x5225('0x21')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x4658ee[_0x5225('0x20')]?_0x4658ee[_0x5225('0x20')]['where']||null:null,'attributes':_0x4658ee[_0x5225('0x20')]?_0x4658ee[_0x5225('0x20')][_0x5225('0x22')]||null:null,'limit':_0x4658ee[_0x5225('0x20')]?_0x4658ee[_0x5225('0x20')][_0x5225('0x23')]||null:null})['then'](function(_0x2c989f){logger[_0x5225('0x14')](_0x5225('0x24'),_0x4658ee);logger['debug'](_0x5225('0x24'),_0x4658ee,JSON[_0x5225('0x18')](_0x2c989f));_0x527b26(_0x2c989f);})[_0x5225('0x1d')](function(_0x541c4f){logger['error'](_0x5225('0x24'),_0x541c4f[_0x5225('0x1b')],_0x4658ee);_0x2b2e5b(_0x9dfbe9[_0x5225('0x19')](0x1f4,_0x541c4f['message']));});});};exports[_0x5225('0x25')]=function(_0x3092d7){return new Promise(function(_0x3497f2,_0x3ecb81){return db[_0x5225('0x26')]['find']({'where':_0x3092d7[_0x5225('0x20')]?_0x3092d7[_0x5225('0x20')][_0x5225('0x27')]||null:null})['then'](function(_0x4641e7){if(_0x4641e7){return _0x4641e7['addTags'](_0x3092d7[_0x5225('0x1f')][_0x5225('0x28')],_[_0x5225('0x29')](_0x3092d7[_0x5225('0x1f')],['ids','id'])||{});}})['spread'](function(_0x30408c){logger[_0x5225('0x14')](_0x5225('0x2a'),_0x3092d7);logger['debug']('AddTags',_0x3092d7,JSON['stringify'](_0x30408c));_0x3497f2(_0x30408c);})[_0x5225('0x1d')](function(_0x44765b){logger[_0x5225('0x19')]('AddTags',_0x44765b[_0x5225('0x1b')],_0x3092d7);_0x3ecb81(_this[_0x5225('0x19')](0x1f4,_0x44765b['message']));});});};