Livechat CRM secret token optional (#14022)

pull/14518/head
Renato Becker 7 years ago committed by Rodrigo Nascimento
parent 58981450f9
commit 788f4e9e39
  1. 2
      app/livechat/server/config.js
  2. 3
      app/livechat/server/hooks/sendToCRM.js
  3. 11
      app/livechat/server/lib/Livechat.js
  4. 1
      server/startup/migrations/index.js
  5. 17
      server/startup/migrations/v145.js

@ -157,7 +157,7 @@ Meteor.startup(function() {
i18nLabel: 'Webhook_URL',
});
settings.add('Livechat_secret_token', false, {
settings.add('Livechat_secret_token', '', {
type: 'string',
group: 'Livechat',
section: 'CRM_Integration',

@ -6,9 +6,8 @@ import { Livechat } from '../lib/Livechat';
const msgNavType = 'livechat_navigation_history';
const crmEnabled = () => {
const secretToken = settings.get('Livechat_secret_token');
const webhookUrl = settings.get('Livechat_webhookUrl');
return secretToken !== '' && secretToken !== undefined && webhookUrl !== '' && webhookUrl !== undefined;
return webhookUrl !== '' && webhookUrl !== undefined;
};
const sendMessageType = (msgType) => {

@ -583,12 +583,11 @@ export const Livechat = {
sendRequest(postData, callback, trying = 1) {
try {
const options = {
headers: {
'X-RocketChat-Livechat-Token': settings.get('Livechat_secret_token'),
},
data: postData,
};
const options = { data: postData };
const secretToken = settings.get('Livechat_secret_token');
if (secretToken !== '' && secretToken !== undefined) {
Object.assign(options, { headers: { 'X-RocketChat-Livechat-Token': secretToken } });
}
return HTTP.post(settings.get('Livechat_webhookUrl'), options);
} catch (e) {
Livechat.logger.webhook.error(`Response error on ${ trying } try ->`, e);

@ -142,4 +142,5 @@ import './v141';
import './v142';
import './v143';
import './v144';
import './v145';
import './xrun';

@ -0,0 +1,17 @@
import { Migrations } from '../../../app/migrations';
import { Settings } from '../../../app/models';
Migrations.add({
version: 145,
up() {
const setting = Settings.findOne({ _id: 'Livechat_secret_token' });
if (setting && setting.value === false) {
Settings.update({ _id: 'Livechat_secret_token' }, {
$set: {
value: '',
},
});
}
},
});
Loading…
Cancel
Save