What if your bot could do ANYTHING? Wouldn’t your friends be impressed?

What if a user said, “can you dance” and your bot could dance?

Or write code?

Or even cry…

Wouldn’t that be sweeeeeeet?

Well, let me show you how you can train your bot to do, literally, anything under the sun.

What this tutorial will cover

This tutorial will show you how to use the sys.any entity in Dialogflow to extract keywords from an utterance and send it back to Chatfuel via Janis. In this example, we will also send the keyword to Giphy via Giphy’s API and return the response from Giphy to the user.

The instructions are for users of Chatfuel, Janis and Dialogflow, but can easily be modified for any Dialogflow agent.

(Chatfuel users who are not familiar with Giphy’s API should read The Non-Coder’s Guide to using Giphy’s API in Chatfuel)

What you need

  1. Chatfuel Account (free)
  2. Dialogflow Account (free)
  3. Janis Account (free)
  4. Giphy API (free. Go to Giphy’s Developer site. Create a new app. Get your API keys)

So let’s jump straight in!

  1. Connect your Chatfuel bot to Janis (instructions can be found here). Put Janis’ JSON API url in your Default Answer block. This saves anything the user says to the attribute “user input” and sends it to Dialogflow.

2. In your Dialogflow agent, create a “Can You” intent and add utterances like “can you {{add random verb}}”. You may also want to add utterances like “will you…” or “do you….”.

Note: Some people will omit the word you, so you may want to add “can dance?” as a training phrase too.

3. Highlight each verb and set it to sys.any

4. Under Actions and Parameters, set the parameter name “any” to the sys.any entity. This stores the verb to parameter $any.

Note: The sys.any entity will also capture a string of words. For example, “can you play the guitar” will be stored as $any = play the guitar.

5. Add a Custom Payload for the response. Set an attribute called “query” that holds the random verb (stored as $any).

Redirect to a Chatfuel block named Gif.

6. In Chatfuel, create a block named Gif that sends a get request to https://gif-loader.herokuapp.com/YOUR-API-KEY/translate_endpoint. (This is a connector that Rahul Bhattacharjee and I wrote to connect Giphy’s API to a format readable by Chatfuel.)

(Remember to insert your API key in the above URL. For more details on how this works, please read The Non-Coder’s Guide to Using Giphy’s API in Chatfuel)

How this works: What we’ve done is as follows:

  • Extract the verb from the utterance “can you …”
  • Store the verb as a parameter $any
  • Save the value of $any to an attribute called “query”
  • Send “query” to Chatfuel, which then sends it to Giphy’s Translate API via our connector
  • Wait for Giphy to sends back the relevant gif!

Quite easily done! 😉

Source link


Please enter your comment!
Please enter your name here