Commit ed1f4c83 authored by Yorrd's avatar Yorrd
Browse files

fix: besserer catch-all für unspezifische Anfragen

parent bcb767a1
......@@ -131,7 +131,18 @@ expressApp.post('/api/dialogflow-webhook', (request, response, next) => {
// .filter({ score: { $gte: 0.7 } })
.sort({ score: { $meta: 'textScore' } })
.toArray();
console.log(foundContents.map(x => x.score));
console.log(
'scores',
foundContents.map(x => x.score),
);
if (agent.query.split(' ').length <= 3 && !!foundContents[0]) {
agent.add(
'Je konkreter die Frage, desto besser meine Antwort. Damit ich helfen kann, ist eine Eingrenzung der Frage notwendig.',
);
return;
}
content = foundContents[0];
}
......@@ -144,7 +155,8 @@ expressApp.post('/api/dialogflow-webhook', (request, response, next) => {
}
console.log('delivering content', content);
const antwortText = content.Antwort?.replace(/<[^>]*>/gi, '')
const antwortText = (content.Antwort || '')
.replace(/<[^>]*>/gi, '')
.replace(/[\s]+$|^[\s]+/g, '')
.replace(/&nbsp;/gi, '');
const slicedAntwort = antwortText.slice(0, 400);
......@@ -154,7 +166,10 @@ expressApp.post('/api/dialogflow-webhook', (request, response, next) => {
// // imageUrl: 'https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png',
text: slicedAntwort,
buttonText: 'Weiterführende Informationen',
buttonUrl: antwortText.length > 400 ? Meteor.absoluteUrl() + 'content/' + content._id : content.Quelle,
buttonUrl:
antwortText.length > 400
? Meteor.absoluteUrl() + 'content/' + content._id
: content.Quelle || Meteor.absoluteUrl() + 'content/' + content._id,
}),
);
const creator = (await AdornisUser.findOne({ _id: content.createdBy }).result) as CCBUser;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment