Search code examples
nlpdialogflow-esdialogflow-es-fulfillment

Returning a boolean upon finding 'before' or 'after' or any synonyms


I am building a calendar chatbot application and I'm using DialogFlow ES to detect what they are saying. One thing I want to implement is the user being able to say "Book a meeting before Tuesday", "Book a meeting before next week", "Book a meeting after next month", etc.

I already have the functionality of booking a meeting as well as detecting dates and ranges of dates (Tuesday, next month, tomorrow, etc.) however I want DialogFlow to return a boolean value if it detects 'before' or 'after' in the sentence or any synonyms of either words (e.g. before: 'prior to', etc.).

Some examples:

'Book a meeting before Tuesday' would return the typical parameters but also beforeAfterFlag: true ('before' would set it to true)

'Book a meeting after Tuesday' would return the typical parameters but also beforeAfterFlag: false ('after' would set it to false)

'Book a meeting on Tuesday' would return the typical parameters but also beforeAfterFlag: - (nothing returned)

How can I implement this?


Solution

  • You can't make Dialogflow return boolean values to your backend. Dialogflow is designed to understand and detect words of the human language. It has no understanding of booleans or other programming values.

    So if you want to create a similar mechanism with Dialogflow to detect if the user used words such as "before" or "after", you will have to use entities, kind of the same way you did with detecting dates.

    You could create a moment entity and give it the required values and synonyms:

    1. Before, prior to, etc
    2. After

    Then in your intent, add some example phrases that include this intent. Leave the required checkbox unchecked, because you still want your users to be able to book an appointment without using words such as before.

    When your users trigger your intent, you can check for the moment parameter in the request. If it has a before value, you set the before variable to true in your webhook, the same goes for after and if there is no moment parameter, you know that your user didn't use one, so you can leave both parameters to false.