6f5d2318f729307fdeb96b3a47c2032b05f5ef5c
[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 _0x5268=['debug','ChatInteraction,\x20%s,\x20%s,\x20%s','error','message','result','catch','UpdateChatInteraction','ChatInteraction','body','options','raw','where','attributes','stringify','AddTagsToChatInteraction','find','addTags','ids','AddTags','lodash','moment','bluebird','randomstring','../../mysqldb','../../config/logger','rpc','../../config/environment','client','http','defaults','redis','localhost','socket.io-emitter','./chatInteraction.socket','request','then','info','ChatInteraction,\x20%s,\x20%s','request\x20sent'];(function(_0x22f830,_0x35b858){var _0x183390=function(_0x1bf154){while(--_0x1bf154){_0x22f830['push'](_0x22f830['shift']());}};_0x183390(++_0x35b858);}(_0x5268,0x1e7));var _0x8526=function(_0x1a8692,_0x20b1b5){_0x1a8692=_0x1a8692-0x0;var _0x5c1667=_0x5268[_0x1a8692];return _0x5c1667;};'use strict';var _=require(_0x8526('0x0'));var util=require('util');var moment=require(_0x8526('0x1'));var BPromise=require(_0x8526('0x2'));var rs=require(_0x8526('0x3'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0x8526('0x4'))['db'];var utils=require('../../config/utils');var logger=require(_0x8526('0x5'))(_0x8526('0x6'));var config=require(_0x8526('0x7'));var jayson=require('jayson/promise');var client=jayson[_0x8526('0x8')][_0x8526('0x9')]({'port':0x232a});config['redis']=_[_0x8526('0xa')](config[_0x8526('0xb')],{'host':_0x8526('0xc'),'port':0x18eb});var socket=require(_0x8526('0xd'))(new Redis(config[_0x8526('0xb')]));require(_0x8526('0xe'))['register'](socket);function respondWithRpcPromise(_0x3c6f57,_0x1c6c14,_0x315ef8){return new BPromise(function(_0x209aa9,_0x8926fb){return client[_0x8526('0xf')](_0x3c6f57,_0x315ef8)[_0x8526('0x10')](function(_0x5bf549){logger[_0x8526('0x11')](_0x8526('0x12'),_0x1c6c14,_0x8526('0x13'));logger[_0x8526('0x14')](_0x8526('0x15'),_0x1c6c14,'request\x20sent',JSON['stringify'](_0x5bf549));if(_0x5bf549[_0x8526('0x16')]){if(_0x5bf549[_0x8526('0x16')]['code']===0x1f4){logger['error']('ChatInteraction,\x20%s,\x20%s',_0x1c6c14,_0x5bf549[_0x8526('0x16')][_0x8526('0x17')]);return _0x8926fb(_0x5bf549[_0x8526('0x16')][_0x8526('0x17')]);}logger['error'](_0x8526('0x12'),_0x1c6c14,_0x5bf549[_0x8526('0x16')][_0x8526('0x17')]);return _0x209aa9(_0x5bf549[_0x8526('0x16')][_0x8526('0x17')]);}else{logger[_0x8526('0x11')](_0x8526('0x12'),_0x1c6c14,_0x8526('0x13'));_0x209aa9(_0x5bf549[_0x8526('0x18')][_0x8526('0x17')]);}})[_0x8526('0x19')](function(_0x2b01c3){logger[_0x8526('0x16')](_0x8526('0x12'),_0x1c6c14,_0x2b01c3);_0x8926fb(_0x2b01c3);});});}exports[_0x8526('0x1a')]=function(_0x230b5f){var _0x4b9015=this;return new Promise(function(_0x54091c,_0x32236d){return db[_0x8526('0x1b')]['update'](_0x230b5f[_0x8526('0x1c')],{'raw':_0x230b5f[_0x8526('0x1d')]?_0x230b5f[_0x8526('0x1d')][_0x8526('0x1e')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x230b5f['options']?_0x230b5f['options'][_0x8526('0x1f')]||null:null,'attributes':_0x230b5f[_0x8526('0x1d')]?_0x230b5f[_0x8526('0x1d')][_0x8526('0x20')]||null:null,'limit':_0x230b5f[_0x8526('0x1d')]?_0x230b5f['options']['limit']||null:null})[_0x8526('0x10')](function(_0x14fe04){logger[_0x8526('0x11')](_0x8526('0x1a'),_0x230b5f);logger[_0x8526('0x14')](_0x8526('0x1a'),_0x230b5f,JSON[_0x8526('0x21')](_0x14fe04));_0x54091c(_0x14fe04);})[_0x8526('0x19')](function(_0x29bffe){logger[_0x8526('0x16')](_0x8526('0x1a'),_0x29bffe[_0x8526('0x17')],_0x230b5f);_0x32236d(_0x4b9015[_0x8526('0x16')](0x1f4,_0x29bffe['message']));});});};exports[_0x8526('0x22')]=function(_0x2f7b4a){return new Promise(function(_0xf7fac5,_0x3c6dd3){return db[_0x8526('0x1b')][_0x8526('0x23')]({'where':_0x2f7b4a[_0x8526('0x1d')]?_0x2f7b4a[_0x8526('0x1d')][_0x8526('0x1f')]||null:null})['then'](function(_0x90155c){if(_0x90155c){return _0x90155c[_0x8526('0x24')](_0x2f7b4a[_0x8526('0x1c')][_0x8526('0x25')],_['omit'](_0x2f7b4a[_0x8526('0x1c')],[_0x8526('0x25'),'id'])||{});}})['spread'](function(_0x21fce3){logger[_0x8526('0x11')]('AddTags',_0x2f7b4a);logger['debug'](_0x8526('0x26'),_0x2f7b4a,JSON[_0x8526('0x21')](_0x21fce3));_0xf7fac5(_0x21fce3);})[_0x8526('0x19')](function(_0x111052){logger['error']('AddTags',_0x111052[_0x8526('0x17')],_0x2f7b4a);_0x3c6dd3(_this['error'](0x1f4,_0x111052[_0x8526('0x17')]));});});};