393a463601a8395f3627e66f6f4848a348f5c347
[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 _0xcf65=['_interactions','_interaction_has_tags','_messages','isArray','toLowerCase','[%s]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','name','role','null','Interaction','then','catch','exports','lodash','../../mysqldb','../../config/logger','openchannel-interactions','mail-interactions','fax-interactions','sms-interactions','chat-interactions','whatsapp-interactions','capitalize','chat','Website','InteractionId','unknown','websites','accounts'];(function(_0x5e0e81,_0x31614a){var _0x12cd9c=function(_0x51ec94){while(--_0x51ec94){_0x5e0e81['push'](_0x5e0e81['shift']());}};_0x12cd9c(++_0x31614a);}(_0xcf65,0x169));var _0x5cf6=function(_0x2641f9,_0x26715f){_0x2641f9=_0x2641f9-0x0;var _0x585741=_0xcf65[_0x2641f9];return _0x585741;};'use strict';var _=require(_0x5cf6('0x0'));var db=require(_0x5cf6('0x1'))['db'];var loggers={'openchannel':require(_0x5cf6('0x2'))(_0x5cf6('0x3')),'mail':require('../../config/logger')(_0x5cf6('0x4')),'fax':require(_0x5cf6('0x2'))(_0x5cf6('0x5')),'sms':require(_0x5cf6('0x2'))(_0x5cf6('0x6')),'chat':require('../../config/logger')(_0x5cf6('0x7')),'whatsapp':require(_0x5cf6('0x2'))(_0x5cf6('0x8'))};function getAccountFK(_0x398350){return _[_0x5cf6('0x9')](_0x398350)+(_0x398350===_0x5cf6('0xa')?_0x5cf6('0xb'):'Account')+'Id';}function getInteractionFK(_0xcef7d6){return _[_0x5cf6('0x9')](_0xcef7d6)+_0x5cf6('0xc');}function getInteractionId(_0x4f344e,_0x560383,_0x2da7ff){if(_0x4f344e&&_0x4f344e[_['upperFirst'](_0x2da7ff)+_0x5cf6('0xc')]){return _0x4f344e[_['upperFirst'](_0x2da7ff)+_0x5cf6('0xc')];}else if(_0x4f344e&&_0x4f344e['id']){return _0x4f344e['id'];}else if(_0x560383&&_0x560383['id']){return _0x560383['id'];}else{return _0x5cf6('0xd');}}function getInteractionsTables(_0x3f6046){return{'accounts':_0x3f6046+'_'+(_0x3f6046===_0x5cf6('0xa')?_0x5cf6('0xe'):_0x5cf6('0xf')),'interactions':_0x3f6046+_0x5cf6('0x10'),'interactionsTags':_0x3f6046+_0x5cf6('0x11'),'messages':_0x3f6046+_0x5cf6('0x12'),'userInteractions':'user_has_'+_0x3f6046+_0x5cf6('0x10')};}function getSelectedTags(_0x1e8791){var _0x428bab=[];if(_0x1e8791){_0x428bab=Array[_0x5cf6('0x13')](_0x1e8791)?_0x1e8791:[_0x1e8791];}return _0x428bab;}function log(_0x48f61f,_0x4974bd,_0x2cbbf6,_0x50626b,_0x534952,_0x1ed203){loggers[_0x534952[_0x5cf6('0x14')]()][_0x48f61f](_0x5cf6('0x15'),_0x1ed203['toUpperCase'](),_0x4974bd?_0x4974bd['id']:null,_0x4974bd?_0x4974bd[_0x5cf6('0x16')]:null,_0x4974bd?_0x4974bd[_0x5cf6('0x17')]:null,getInteractionId(_0x2cbbf6,_0x50626b,_0x534952),_0x2cbbf6?JSON['stringify'](_0x2cbbf6):_0x5cf6('0x18'));}function updateUser(_0x2708f8,_0x548eb8,_0x20d185,_0xc49066,_0x55412e){db[_['upperFirst'](_0xc49066)+_0x5cf6('0x19')]['findOne']({'where':{'id':getInteractionId(_0x548eb8,_0x20d185,_0xc49066)}})[_0x5cf6('0x1a')](function(_0x379454){if(_0x379454){return _0x379454['update']({'UserId':_0x2708f8?_0x2708f8['id']:null});}})[_0x5cf6('0x1a')](function(_0x243c28){if(_0x243c28){log('info',_0x2708f8,_0x548eb8,_0x20d185,_0xc49066,_0x55412e);}})[_0x5cf6('0x1b')](function(){log('error',_0x2708f8,_0x548eb8,_0x20d185,_0xc49066,_0x55412e);});}module[_0x5cf6('0x1c')]={'getAccountFK':getAccountFK,'getInteractionFK':getInteractionFK,'getInteractionsTables':getInteractionsTables,'getSelectedTags':getSelectedTags,'updateUser':updateUser};