Built motion from commit 3c2ce842.|2.6.31
[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 _0x744f=['update','then','info','error','stringify','MESSAGE:ACCEPT]\x20id=','\x20role=','\x20interaction=','\x20body=','exports','../../mysqldb','../../config/logger','openchannel-interactions','mail-interactions','fax-interactions','whatsapp-interactions','capitalize','chat','InteractionId','upperFirst','unknown','websites','accounts','_interaction_has_tags','_messages','user_has_','_interactions','isArray','toLowerCase','[%s]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','toUpperCase','name','role','null','Interaction'];(function(_0x449c88,_0x3e7aab){var _0x148220=function(_0x18a5f5){while(--_0x18a5f5){_0x449c88['push'](_0x449c88['shift']());}};_0x148220(++_0x3e7aab);}(_0x744f,0x96));var _0xf744=function(_0x4f9b88,_0x39065a){_0x4f9b88=_0x4f9b88-0x0;var _0x2521aa=_0x744f[_0x4f9b88];return _0x2521aa;};'use strict';var _=require('lodash');var db=require(_0xf744('0x0'))['db'];var loggers={'openchannel':require(_0xf744('0x1'))(_0xf744('0x2')),'mail':require(_0xf744('0x1'))(_0xf744('0x3')),'fax':require('../../config/logger')(_0xf744('0x4')),'sms':require(_0xf744('0x1'))('sms-interactions'),'chat':require(_0xf744('0x1'))('chat-interactions'),'whatsapp':require(_0xf744('0x1'))(_0xf744('0x5'))};function getAccountFK(_0x4fe4e2){return _[_0xf744('0x6')](_0x4fe4e2)+(_0x4fe4e2===_0xf744('0x7')?'Website':'Account')+'Id';}function getInteractionFK(_0x171a25){return _[_0xf744('0x6')](_0x171a25)+_0xf744('0x8');}function getInteractionId(_0x4fb5a5,_0x4575c7,_0xe6b503){if(_0x4fb5a5&&_0x4fb5a5[_[_0xf744('0x9')](_0xe6b503)+'InteractionId']){return _0x4fb5a5[_[_0xf744('0x9')](_0xe6b503)+_0xf744('0x8')];}else if(_0x4fb5a5&&_0x4fb5a5['id']){return _0x4fb5a5['id'];}else if(_0x4575c7&&_0x4575c7['id']){return _0x4575c7['id'];}else{return _0xf744('0xa');}}function getInteractionsTables(_0x93c4b8){return{'accounts':_0x93c4b8+'_'+(_0x93c4b8==='chat'?_0xf744('0xb'):_0xf744('0xc')),'interactions':_0x93c4b8+'_interactions','interactionsTags':_0x93c4b8+_0xf744('0xd'),'messages':_0x93c4b8+_0xf744('0xe'),'userInteractions':_0xf744('0xf')+_0x93c4b8+_0xf744('0x10')};}function getSelectedTags(_0x544b57){var _0x26a326=[];if(_0x544b57){_0x26a326=Array[_0xf744('0x11')](_0x544b57)?_0x544b57:[_0x544b57];}return _0x26a326;}function log(_0x42a5af,_0x53dea9,_0x248c14,_0x1ab9f8,_0x54f6a1,_0x33a633){loggers[_0x54f6a1[_0xf744('0x12')]()][_0x42a5af](_0xf744('0x13'),_0x33a633[_0xf744('0x14')](),_0x53dea9?_0x53dea9['id']:null,_0x53dea9?_0x53dea9[_0xf744('0x15')]:null,_0x53dea9?_0x53dea9[_0xf744('0x16')]:null,getInteractionId(_0x248c14,_0x1ab9f8,_0x54f6a1),_0x248c14?JSON['stringify'](_0x248c14):_0xf744('0x17'));}function updateUser(_0x6480dc,_0x45359d,_0x2e375a,_0x1d7971,_0x1c647c){db[_[_0xf744('0x9')](_0x1d7971)+_0xf744('0x18')]['findOne']({'where':{'id':getInteractionId(_0x45359d,_0x2e375a,_0x1d7971)}})['then'](function(_0x7add25){if(_0x7add25){return _0x7add25[_0xf744('0x19')]({'UserId':_0x6480dc?_0x6480dc['id']:null});}})[_0xf744('0x1a')](function(_0x4d2096){if(_0x4d2096){log(_0xf744('0x1b'),_0x6480dc,_0x45359d,_0x2e375a,_0x1d7971,_0x1c647c);}})['catch'](function(){log(_0xf744('0x1c'),_0x6480dc,_0x45359d,_0x2e375a,_0x1d7971,_0x1c647c);});}function logAcceptMessage(_0x4d2ae4,_0x513ff9,_0x53a89b,_0x2b4295){var _0x31fefe=loggers[_0x4d2ae4[_0xf744('0x12')]()];var _0x57cb3d=_0x513ff9['id'];var _0x4e0b53=_0x513ff9[_0xf744('0x15')];var _0x48c6f5=_0x513ff9['role'];var _0x32c51b=JSON[_0xf744('0x1d')](_0x2b4295||null);_0x31fefe[_0xf744('0x1b')]('['+_0x4d2ae4[_0xf744('0x14')]()+_0xf744('0x1e')+_0x57cb3d+'\x20name='+_0x4e0b53+_0xf744('0x1f')+_0x48c6f5+_0xf744('0x20')+_0x53a89b+_0xf744('0x21')+_0x32c51b);}module[_0xf744('0x22')]={'getAccountFK':getAccountFK,'getInteractionFK':getInteractionFK,'getInteractionsTables':getInteractionsTables,'getSelectedTags':getSelectedTags,'logAcceptMessage':logAcceptMessage,'updateUser':updateUser};