82b5aa84d13150a43f03340981c9244c328668ea
[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 _0x8eb0=['options','raw','where','attributes','limit','UpdateChatInteraction','find','addTags','body','ids','omit','AddTags','catch','lodash','util','moment','bluebird','randomstring','ioredis','../../config/utils','../../config/logger','rpc','../../config/environment','client','http','redis','defaults','localhost','socket.io-emitter','./chatInteraction.socket','register','request','then','info','ChatInteraction,\x20%s,\x20%s','request\x20sent','debug','ChatInteraction,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','ChatInteraction','update'];(function(_0x5719ff,_0x3a3a66){var _0x3d6f84=function(_0x619847){while(--_0x619847){_0x5719ff['push'](_0x5719ff['shift']());}};_0x3d6f84(++_0x3a3a66);}(_0x8eb0,0x175));var _0x08eb=function(_0x421019,_0x5e2b74){_0x421019=_0x421019-0x0;var _0x1219f9=_0x8eb0[_0x421019];return _0x1219f9;};'use strict';var _=require(_0x08eb('0x0'));var util=require(_0x08eb('0x1'));var moment=require(_0x08eb('0x2'));var BPromise=require(_0x08eb('0x3'));var rs=require(_0x08eb('0x4'));var fs=require('fs');var Redis=require(_0x08eb('0x5'));var db=require('../../mysqldb')['db'];var utils=require(_0x08eb('0x6'));var logger=require(_0x08eb('0x7'))(_0x08eb('0x8'));var config=require(_0x08eb('0x9'));var jayson=require('jayson/promise');var client=jayson[_0x08eb('0xa')][_0x08eb('0xb')]({'port':0x232a});config[_0x08eb('0xc')]=_[_0x08eb('0xd')](config[_0x08eb('0xc')],{'host':_0x08eb('0xe'),'port':0x18eb});var socket=require(_0x08eb('0xf'))(new Redis(config[_0x08eb('0xc')]));require(_0x08eb('0x10'))[_0x08eb('0x11')](socket);function respondWithRpcPromise(_0x4e7f54,_0x221db6,_0x5bc803){return new BPromise(function(_0x3854d3,_0x21065e){return client[_0x08eb('0x12')](_0x4e7f54,_0x5bc803)[_0x08eb('0x13')](function(_0x2e29f1){logger[_0x08eb('0x14')](_0x08eb('0x15'),_0x221db6,_0x08eb('0x16'));logger[_0x08eb('0x17')](_0x08eb('0x18'),_0x221db6,'request\x20sent',JSON[_0x08eb('0x19')](_0x2e29f1));if(_0x2e29f1[_0x08eb('0x1a')]){if(_0x2e29f1[_0x08eb('0x1a')][_0x08eb('0x1b')]===0x1f4){logger[_0x08eb('0x1a')](_0x08eb('0x15'),_0x221db6,_0x2e29f1[_0x08eb('0x1a')][_0x08eb('0x1c')]);return _0x21065e(_0x2e29f1[_0x08eb('0x1a')]['message']);}logger[_0x08eb('0x1a')](_0x08eb('0x15'),_0x221db6,_0x2e29f1['error'][_0x08eb('0x1c')]);return _0x3854d3(_0x2e29f1['error']['message']);}else{logger['info'](_0x08eb('0x15'),_0x221db6,_0x08eb('0x16'));_0x3854d3(_0x2e29f1[_0x08eb('0x1d')][_0x08eb('0x1c')]);}})['catch'](function(_0x18f05a){logger['error']('ChatInteraction,\x20%s,\x20%s',_0x221db6,_0x18f05a);_0x21065e(_0x18f05a);});});}exports['UpdateChatInteraction']=function(_0xd0a341){var _0xe6ba66=this;return new Promise(function(_0x4eac5f,_0x255fe8){return db[_0x08eb('0x1e')][_0x08eb('0x1f')](_0xd0a341['body'],{'raw':_0xd0a341['options']?_0xd0a341[_0x08eb('0x20')][_0x08eb('0x21')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0xd0a341['options']?_0xd0a341[_0x08eb('0x20')][_0x08eb('0x22')]||null:null,'attributes':_0xd0a341[_0x08eb('0x20')]?_0xd0a341[_0x08eb('0x20')][_0x08eb('0x23')]||null:null,'limit':_0xd0a341['options']?_0xd0a341['options'][_0x08eb('0x24')]||null:null})['then'](function(_0x44d480){logger[_0x08eb('0x14')](_0x08eb('0x25'),_0xd0a341);logger[_0x08eb('0x17')]('UpdateChatInteraction',_0xd0a341,JSON['stringify'](_0x44d480));_0x4eac5f(_0x44d480);})['catch'](function(_0x4204cb){logger['error'](_0x08eb('0x25'),_0x4204cb[_0x08eb('0x1c')],_0xd0a341);_0x255fe8(_0xe6ba66[_0x08eb('0x1a')](0x1f4,_0x4204cb[_0x08eb('0x1c')]));});});};exports['AddTagsToChatInteraction']=function(_0x435ddc){return new Promise(function(_0x4342aa,_0x21cdc3){return db[_0x08eb('0x1e')][_0x08eb('0x26')]({'where':_0x435ddc['options']?_0x435ddc[_0x08eb('0x20')][_0x08eb('0x22')]||null:null})[_0x08eb('0x13')](function(_0x5776ea){if(_0x5776ea){return _0x5776ea[_0x08eb('0x27')](_0x435ddc[_0x08eb('0x28')][_0x08eb('0x29')],_[_0x08eb('0x2a')](_0x435ddc['body'],[_0x08eb('0x29'),'id'])||{});}})['spread'](function(_0x4075dc){logger['info'](_0x08eb('0x2b'),_0x435ddc);logger['debug']('AddTags',_0x435ddc,JSON['stringify'](_0x4075dc));_0x4342aa(_0x4075dc);})[_0x08eb('0x2c')](function(_0x49ef6c){logger['error'](_0x08eb('0x2b'),_0x49ef6c[_0x08eb('0x1c')],_0x435ddc);_0x21cdc3(_this[_0x08eb('0x1a')](0x1f4,_0x49ef6c['message']));});});};