Twister013
Twister013

Reputation: 183

API.ai bot using same wordings as user

I'm new to api.ai and trying to make the bot adapt to the user's vocabulary. For example if at first the bot asks if the user wants to talk, user will say yes/yep/okay/ok etc and I want to use that answer to user later again. Can I do this? thanks!

Upvotes: 0

Views: 59

Answers (1)

mattcarrollcode
mattcarrollcode

Reputation: 3479

  1. create a yes or affirmative API.AI entity. In the entity include all the synonym values (like the ones you described yes/yep/okay/ok).
  2. create an intent with examples of all your user queries where the user might say this first (you may need to include the yes entity in multiple intents).
  3. Create a webhook (fulfillment getting started guide here). In the webhook check for the yes parameter in the webhook request and if it is present record the value, in a database along with a user identifier (provided by the platform you choose, like Google Assistant or Slack) for later retrieval in a response to the user.

Below is some non-working code using Cloud Functions for Firebase for fulfillment of an API.AI agent and the Firebase Realtime Database to store the user data that would be a good starting point for your fulfillment:

const functions = require('firebase-functions');
const admin = require("firebase-admin");
const db = admin.database();
const ref = db.ref("your/firebase/database/here");

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
  const parameters = request.body.result.parameters;
  if (parameters['yes']){
    var usersRef = ref.child("users");
    usersRef.set({
      userId: {
        yes: parameters['yes']
      }
    });
  }
});

Upvotes: 2

Related Questions