0

how to add middleware/intercepter for every request in on dialogflow webhook server while using Action-on-google library and working with dialogflow application, the purpose is i want to authenticate on every request that key is still valid or not, and also i want to check if that user is already managing a group then get all members of group and put in /userEntity,

now i'm doing this in wellcome intent, so when user say talk to xyz app in wellcome intent i check in database if user is managing a group then get all members of that specific group and put in user entity,

but this logic become trash when user directly say a command such as if user don't say talk to my xyz app and instead he says ask my xyz app john wink is present or not then app is unable to recognize this name, note that i cannot user system name entity because in my case these are not english names

for now i have restricted direct commands with context combination but it is not good e.g: user cannot say direct command unless WELCOME_DONE context which is context out of wellcome intent

Prisoner
  • 49,922
  • 7
  • 53
  • 105
Inzamam Malik
  • 3,238
  • 3
  • 29
  • 61
  • What application server are you using? Can you update your question to include code where you illustrate how you're handling this now for one intent and why you're having problems with other intents? – Prisoner Nov 03 '17 at 10:16
  • firebase functions, a single function named `webhook` – Inzamam Malik Nov 04 '17 at 13:07

1 Answers1

1

The "direct command" you mention (ask my xyz app john wink is present or not) is what we call an "action invocation phrase". Since you're depending on a user entity in order to extract a name from the action phrase, you'll only be able to do this successfully if another intent has recently been matched, since the user entities you add are only available for 30 minutes.

One way around this might be the following. We are going to do something clever to run the user query through Dialogflow a second time, after adding the user entity.

  1. In the intent that handles your "action invocation", use @sys.any (which is essentially a wildcard entity) to capture the name. Enable the webhook for this intent.

  2. Create another intent with User says examples that match the expected "action phrase", similar to the first intent, but don't add it to your "Additional triggering intents". Enable the webhook for this intent.

  3. Create a function in your webhook that handles the intent from Step 1.

  4. In this function, look up the user and their group and add the members via /userEntity.

  5. Now that the user entity has been created, call the Dialogflow /query API with whatever the user said.

  6. Since the user entity has now been created, the intent created in Step 2 will be matched, so the /query API response will contain the name from the entity you created in Step 4.

  7. Use the name to generate whatever response you wanted to generate.

Daniel Situnayake
  • 2,874
  • 2
  • 30
  • 38