0

Hi all,

I have question about control flow in Dialogflow. Is it possible to control Dialogflow in fullfillment?

Below are my Dialogflow Process.

  1. I created 'Intent1' -> wait for user input about 'Document Type' such as 'Document No.1' or 'Document No.2', etc ...
  2. I created 'Intent2' -> It is follow-up intent of 'Intent1'. It get user input (Training Phrases) such as 'Document No.1' or 'Document No.2' or etc. This 'Intent2' has created parameters for get 'Document Type' such as 'No.1' or 'No.2' from user input.
  3. I created fulfillment 'Inline' for 'Intent2' too. After user input 'No.1' or 'No.2' or etc. I check the parameter value with my Firebase Realtime Database. And then return result message to user for waiting next user input by using ...

agent.add("...some phrase...");

I want to know, is it possible to control Dialogflow in fullfillment?

Such as, if I check 'No.3' does not in by Database, may I send message "It is not in database" and force process back to 'Intent1'.

But if 'No.1' is in my Database, may I send message "Please input time to get it?" to user and wait user input at 'Intent3' (follow-up intent of 'Intent2').

I try to search guide for solving but not found.

Thank in advance

Jatu Tung
  • 79
  • 6

1 Answers1

0

Using Firebase to retrieve data

When using firebase to retrieve data for your dialogflow agent, try not to have any ' business logic' in your databases. Instead, query the database, get the results in your application code (for this example Inline fulfillment), and have your logic there (i.e. did the results come back null or non-null, depending on if it exists in the database). Now, let's get back to your problem at stake.

Implementing a solution

First, you should have code that looks like this to set up the connection between Dialogflow and Firebase.

const admin = require('firebase-admin');
admin.initializeApp({
    credential: admin.credential.applicationDefault(),
    databaseURL: 'ws://project_name.firebaseio.com/'
});

If you have issues with respect to using firebase-admin, you will need greater permission and check out this out.

Next, when your user says a Document Type to the agent, you query the database based on what you extracted from the user. This extraction is stored in a variable you named when you created parameters in the console. You can name this variable anything; I am going to call this extracted parameter userType. The inline fulfillment code is as follows:

function getDoc(agent){
    // userType is what the user responded to you
    const response = agent.parameters.userType;
    return admin.database().ref('data').once('value').then((snapshot) => {
        const type = snapshot.child(response).val();// response is variable so no quotes
        if(type!== null){
            agent.add(`You chose Document type ${type}`);
        }
        else{
            // type == null indicating the type doesn't exist in the database
            agent.add('You gave an invalid type');
        }
    });
}

If the Document Type the user said to agent exists in your database, then the variable above I called type will be some value (not null). If it is null, then what the user asked for is not in the database, and you can prompt a message to user as a follow up such as, "Your input is invalid."

In your example, if the user asked for No. 3 then response would refer to No. 3 and the type would be null. indicative of the fact No. 3 is not is your database.

Resources:

  • Video by Axle Web Technologies about the workflow and syntax of connecting Dialogflow to Firebase (highly recommended)
  • Accessing parameters from inside a fulfillment, by GCP Quickstart
  • Get data using Firebase, from the Firebase Documentation
Ari
  • 156
  • 5