How to share webhook code and intents works togeth

2019-08-23 15:34发布

问题:

I' m working with dialogflow to have a chatbot for renting different buildings(in my case called FMRs). I have a "New FMR" intent as shown in the following picture:

As you see this FMR has different rent prices according to its facilities.I have a graphql database to store FMRs and their parameters. I used webhook and wrote a piece of java script code to get the list of FMRs. Whenever user says "Set up a new FMR called TEST with rent two bedroom at $1500" my code checks whether the FMR name(TEST) exists in the database or not.If it exists we should ask the user if she/he wants to edit the parameters of existed FMR, and if it doesn't exist, the new FMR will be created in database. My problem is with the first part that FMR exists in database.As I only can check its existence in my own code, where can I ask the user to edit the existed FMR or no and get his/her response to continue the work? How can I have a sub-intent to connect it to my code and have the above scenario correctly? Or how can I trigger a sub-intent in my code to be executed after user says "Yes" or "no" to my question about "editing existed FMR"? Sorry for long description and thanks in advance for your help

回答1:

I'm still confused about how this conversation flow should look, but it sounds like it would be something like this:

  • User Says: "Create a new FMR named name with..."

    If "name" does not exist, save the data, reply with "The FMR named name has been created" and close the conversation.

    If "name" exists, reply: "The name FMR exists. Do you want to edit it?"

    • User says: "no"

      Reply: "What should it be named?"

      User says the new name and processing repeats as above.

    • User says: "yes"

      Save the data, reply with "The FMR named name has been updated", and close the conversation.

In your fulfillment code, if you need to ask the yes/no question, you'd also reply with a Context, setting the parameters with enough information so you can remember what the user has already said about this FMR the next time your fulfillment gets called.

You can then create followup Intents for the "Yes" and "No" responses. Give each one a different Action setting, so you can differentiate them in your fulfillment. You'll also need another Intent that has this Context as the input context and has sample phrases that match how the user will specify the name (ie - with a parameter named "fmr-name" of type @sys.any) - this can have the same Action setting as your original Intent.

When your fulfillment is called again, you know if they've responded yes or no (by checking the Action). If they've said "yes", you have the previous information they already said and can save and exit.

If they've said "no", you'll prompt for the new name and set the Context again with the information you need to remember when you get a reply. When they do reply, you'll check the parameters for the new name and use the values from the context.



标签: dialogflow