Built motion from commit 511216ff.|2.6.34
[motion2.git] / server / components / interaction / utils.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 _0x7f9c=['Interaction','findOne','then','update','info','error','name','stringify','MESSAGE:ACCEPT]\x20id=','\x20name=','\x20role=','\x20body=','lodash','../../mysqldb','../../config/logger','fax-interactions','sms-interactions','chat-interactions','whatsapp-interactions','capitalize','chat','Website','Account','upperFirst','InteractionId','unknown','websites','accounts','_interactions','_interaction_has_tags','_messages','isArray','toLowerCase','toUpperCase','role','null'];(function(_0x51b973,_0x26c0f6){var _0x37ac06=function(_0x221ab6){while(--_0x221ab6){_0x51b973['push'](_0x51b973['shift']());}};_0x37ac06(++_0x26c0f6);}(_0x7f9c,0x174));var _0xc7f9=function(_0x1f1c27,_0x3d5a0b){_0x1f1c27=_0x1f1c27-0x0;var _0x334749=_0x7f9c[_0x1f1c27];return _0x334749;};'use strict';var _=require(_0xc7f9('0x0'));var db=require(_0xc7f9('0x1'))['db'];var loggers={'openchannel':require(_0xc7f9('0x2'))('openchannel-interactions'),'mail':require(_0xc7f9('0x2'))('mail-interactions'),'fax':require(_0xc7f9('0x2'))(_0xc7f9('0x3')),'sms':require(_0xc7f9('0x2'))(_0xc7f9('0x4')),'chat':require(_0xc7f9('0x2'))(_0xc7f9('0x5')),'whatsapp':require(_0xc7f9('0x2'))(_0xc7f9('0x6'))};function getAccountFK(_0x59ba28){return _[_0xc7f9('0x7')](_0x59ba28)+(_0x59ba28===_0xc7f9('0x8')?_0xc7f9('0x9'):_0xc7f9('0xa'))+'Id';}function getInteractionFK(_0x427253){return _[_0xc7f9('0x7')](_0x427253)+'InteractionId';}function getInteractionId(_0x51ca8f,_0x501fe8,_0x53c227){if(_0x51ca8f&&_0x51ca8f[_[_0xc7f9('0xb')](_0x53c227)+_0xc7f9('0xc')]){return _0x51ca8f[_[_0xc7f9('0xb')](_0x53c227)+'InteractionId'];}else if(_0x51ca8f&&_0x51ca8f['id']){return _0x51ca8f['id'];}else if(_0x501fe8&&_0x501fe8['id']){return _0x501fe8['id'];}else{return _0xc7f9('0xd');}}function getInteractionsTables(_0xf86771){return{'accounts':_0xf86771+'_'+(_0xf86771===_0xc7f9('0x8')?_0xc7f9('0xe'):_0xc7f9('0xf')),'interactions':_0xf86771+_0xc7f9('0x10'),'interactionsTags':_0xf86771+_0xc7f9('0x11'),'messages':_0xf86771+_0xc7f9('0x12'),'userInteractions':'user_has_'+_0xf86771+_0xc7f9('0x10')};}function getSelectedTags(_0x1b0d79){var _0x11a7ed=[];if(_0x1b0d79){_0x11a7ed=Array[_0xc7f9('0x13')](_0x1b0d79)?_0x1b0d79:[_0x1b0d79];}return _0x11a7ed;}function log(_0x50022a,_0x45ec8c,_0x603246,_0x5a3006,_0x3372dd,_0x4650cc){loggers[_0x3372dd[_0xc7f9('0x14')]()][_0x50022a]('[%s]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x4650cc[_0xc7f9('0x15')](),_0x45ec8c?_0x45ec8c['id']:null,_0x45ec8c?_0x45ec8c['name']:null,_0x45ec8c?_0x45ec8c[_0xc7f9('0x16')]:null,getInteractionId(_0x603246,_0x5a3006,_0x3372dd),_0x603246?JSON['stringify'](_0x603246):_0xc7f9('0x17'));}function updateUser(_0x2e32ec,_0x58ca53,_0x343e42,_0x5de9e8,_0x1db7d7){db[_[_0xc7f9('0xb')](_0x5de9e8)+_0xc7f9('0x18')][_0xc7f9('0x19')]({'where':{'id':getInteractionId(_0x58ca53,_0x343e42,_0x5de9e8)}})[_0xc7f9('0x1a')](function(_0x5348e6){if(_0x5348e6){return _0x5348e6[_0xc7f9('0x1b')]({'UserId':_0x2e32ec?_0x2e32ec['id']:null});}})[_0xc7f9('0x1a')](function(_0x4d37cb){if(_0x4d37cb){log(_0xc7f9('0x1c'),_0x2e32ec,_0x58ca53,_0x343e42,_0x5de9e8,_0x1db7d7);}})['catch'](function(){log(_0xc7f9('0x1d'),_0x2e32ec,_0x58ca53,_0x343e42,_0x5de9e8,_0x1db7d7);});}function logAcceptMessage(_0x2de59a,_0x46c8e4,_0x5b7643,_0x4253bc){var _0x5d3083=loggers[_0x2de59a[_0xc7f9('0x14')]()];var _0x57cccb=_0x46c8e4['id'];var _0x1f6244=_0x46c8e4[_0xc7f9('0x1e')];var _0x10e6dd=_0x46c8e4['role'];var _0x2a20fb=JSON[_0xc7f9('0x1f')](_0x4253bc||null);_0x5d3083['info']('['+_0x2de59a[_0xc7f9('0x15')]()+_0xc7f9('0x20')+_0x57cccb+_0xc7f9('0x21')+_0x1f6244+_0xc7f9('0x22')+_0x10e6dd+'\x20interaction='+_0x5b7643+_0xc7f9('0x23')+_0x2a20fb);}module['exports']={'getAccountFK':getAccountFK,'getInteractionFK':getInteractionFK,'getInteractionsTables':getInteractionsTables,'getSelectedTags':getSelectedTags,'logAcceptMessage':logAcceptMessage,'updateUser':updateUser};