Built motion from commit d5e4af8c.|2.6.23
[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 _0xb0f7=['_messages','user_has_','isArray','[%s]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','toUpperCase','role','stringify','Interaction','findOne','then','update','catch','error','exports','lodash','../../mysqldb','../../config/logger','openchannel-interactions','mail-interactions','fax-interactions','chat-interactions','capitalize','Website','Account','InteractionId','upperFirst','unknown','websites','accounts','_interactions','_interaction_has_tags'];(function(_0x39a378,_0x24e80){var _0x578a3b=function(_0x8f8e2){while(--_0x8f8e2){_0x39a378['push'](_0x39a378['shift']());}};_0x578a3b(++_0x24e80);}(_0xb0f7,0x1df));var _0x7b0f=function(_0x35f1f0,_0x5a69a3){_0x35f1f0=_0x35f1f0-0x0;var _0x41cd13=_0xb0f7[_0x35f1f0];return _0x41cd13;};'use strict';var _=require(_0x7b0f('0x0'));var db=require(_0x7b0f('0x1'))['db'];var loggers={'openchannel':require(_0x7b0f('0x2'))(_0x7b0f('0x3')),'mail':require(_0x7b0f('0x2'))(_0x7b0f('0x4')),'fax':require(_0x7b0f('0x2'))(_0x7b0f('0x5')),'sms':require(_0x7b0f('0x2'))('sms-interactions'),'chat':require('../../config/logger')(_0x7b0f('0x6')),'whatsapp':require('../../config/logger')('whatsapp-interactions')};function getAccountFK(_0x464ff2){return _[_0x7b0f('0x7')](_0x464ff2)+(_0x464ff2==='chat'?_0x7b0f('0x8'):_0x7b0f('0x9'))+'Id';}function getInteractionFK(_0x44286c){return _['capitalize'](_0x44286c)+_0x7b0f('0xa');}function getInteractionId(_0x2eb29e,_0x456c99,_0xe6c1c0){if(_0x2eb29e&&_0x2eb29e[_[_0x7b0f('0xb')](_0xe6c1c0)+_0x7b0f('0xa')]){return _0x2eb29e[_[_0x7b0f('0xb')](_0xe6c1c0)+_0x7b0f('0xa')];}else if(_0x2eb29e&&_0x2eb29e['id']){return _0x2eb29e['id'];}else if(_0x456c99&&_0x456c99['id']){return _0x456c99['id'];}else{return _0x7b0f('0xc');}}function getInteractionsTables(_0x5be9e3){return{'accounts':_0x5be9e3+'_'+(_0x5be9e3==='chat'?_0x7b0f('0xd'):_0x7b0f('0xe')),'interactions':_0x5be9e3+_0x7b0f('0xf'),'interactionsTags':_0x5be9e3+_0x7b0f('0x10'),'messages':_0x5be9e3+_0x7b0f('0x11'),'userInteractions':_0x7b0f('0x12')+_0x5be9e3+'_interactions'};}function getSelectedTags(_0x56db2d){var _0x1222d7=[];if(_0x56db2d){_0x1222d7=Array[_0x7b0f('0x13')](_0x56db2d)?_0x56db2d:[_0x56db2d];}return _0x1222d7;}function log(_0x5dcbb1,_0x21f4c4,_0x38def6,_0x12b99d,_0x303cbb,_0x2d8642){loggers[_0x303cbb['toLowerCase']()][_0x5dcbb1](_0x7b0f('0x14'),_0x2d8642[_0x7b0f('0x15')](),_0x21f4c4?_0x21f4c4['id']:null,_0x21f4c4?_0x21f4c4['name']:null,_0x21f4c4?_0x21f4c4[_0x7b0f('0x16')]:null,getInteractionId(_0x38def6,_0x12b99d,_0x303cbb),_0x38def6?JSON[_0x7b0f('0x17')](_0x38def6):'null');}function updateUser(_0x2c4209,_0xf26736,_0x305ab2,_0x58f5e1,_0x5df71e){db[_[_0x7b0f('0xb')](_0x58f5e1)+_0x7b0f('0x18')][_0x7b0f('0x19')]({'where':{'id':getInteractionId(_0xf26736,_0x305ab2,_0x58f5e1)}})[_0x7b0f('0x1a')](function(_0x3087f0){if(_0x3087f0){return _0x3087f0[_0x7b0f('0x1b')]({'UserId':_0x2c4209?_0x2c4209['id']:null});}})['then'](function(_0x475ad7){if(_0x475ad7){log('info',_0x2c4209,_0xf26736,_0x305ab2,_0x58f5e1,_0x5df71e);}})[_0x7b0f('0x1c')](function(){log(_0x7b0f('0x1d'),_0x2c4209,_0xf26736,_0x305ab2,_0x58f5e1,_0x5df71e);});}module[_0x7b0f('0x1e')]={'getAccountFK':getAccountFK,'getInteractionFK':getInteractionFK,'getInteractionsTables':getInteractionsTables,'getSelectedTags':getSelectedTags,'updateUser':updateUser};