From 7ea42fa651c2cd4b68cca300f537e496c63a0557 Mon Sep 17 00:00:00 2001 From: Volkmar Vogel Date: Mon, 25 Feb 2019 14:06:37 +0100 Subject: [PATCH] add function to detect if the request is coming from the Google Crawler --- .../org/rewedigital/dialog/handler/DialogflowHandler.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/src/main/kotlin/org/rewedigital/dialog/handler/DialogflowHandler.kt b/core/src/main/kotlin/org/rewedigital/dialog/handler/DialogflowHandler.kt index 58b0d7e..0b0f7b8 100644 --- a/core/src/main/kotlin/org/rewedigital/dialog/handler/DialogflowHandler.kt +++ b/core/src/main/kotlin/org/rewedigital/dialog/handler/DialogflowHandler.kt @@ -126,6 +126,11 @@ class DialogflowHandler(private val webhookRequest: WebhookRequest) { */ fun getArgument(key: String) = arguments[key] + fun isGoogleCrawler() = webhookRequest.originalDetectIntentRequest?.payload?.user?.profile + .let { + it?.givenName == "Google" && it.familyName == "Crawler" + } + /** * Checks if on the last request a permission was successfully granted. */ @@ -192,7 +197,7 @@ class DialogflowHandler(private val webhookRequest: WebhookRequest) { operator fun set(contextName: String, parameter: String, value: Any) { if (this[contextName] == null) { this[contextName] = - OutputContext(contextName, lifespanCount = 4, parameters = mutableMapOf(parameter to value)) + OutputContext(contextName, lifespanCount = 4, parameters = mutableMapOf(parameter to value)) } else { this[contextName]?.parameters?.set(parameter, value) }