0

Basically I want to achieve this:

1.user: I want apple.
bot: You want apple right? 
2.user: I also want banana.
bot: You want apple and banana right? 

Here apple and banana are all parameters of the same fruit entity. In my webook backend I want to receive [apple, banana] when the user entered 2nd sentence, so the bot needs to remember all the fruit (parameters) users gave during the conversation.

I was playing around with dialogflow context. I know it could pass parameters between different intents. But at here I'm using the same intent buyFruit, so the output context only has the new fruit parameters user entered in a new sentence:

1.user: I want apple. -> outputContext.parameters = [apple]
2.user: I also want banana. -> outputContext.parameters = [banana]

I couldn't find a way to get the fruit parameters user said in previous sentences. In another word, I want outputContext.parameters = [apple, banana] in the second webhook request. Does anyone know how to achieve this?

Harry
  • 7
  • 2

2 Answers2

0

You edited the question and did not respond to my answer. I feel you may not really know what question you are asking.

Use context, create your own, store the data in your python application. Its pretty simple.

Please, respectfully take the time to either comment on the direct result, further ask a more concise question or mark as answered.

-1

I found the solution to this. I will assume you understand how to use fulfillment, and adding webhooks. If not, feel free to visit here or shoot a question.

For this, there are 3 necessary parts. Dialogflow, your fulfillment code ( I used flask and python), and communication between the two. Enable Webhook, fill in the appropriate local machine url (for this I used NGROK).

I created a cart and a function for creating and maintaining said cart. Below is the code:

from flask import Flask, request

app = Flask(__name__)



##Create the cart
cart = []


#create a route for the webhook
@app.route('/webhook', methods=['GET', 'POST'])
def webhook():
    req = request.get_json(silent=True, force=True)
    fulfillmentText = ''
    query_result = req.get('queryResult')

    if query_result.get('action') == 'order.wings':
        food_data = query_result['parameters']

        ##create temp dictionary so we always extract correct order data
        temp_dictionary = []
        for item in food_data:
            temp_dictionary.append(item)

        ##add items to cart
        new_item = []
        for item in temp_dictionary:
            new_item.append(food_data[item])

        cart.append(new_item)
        print(cart)


        fulfillmentText = "Added Wings to Cart"
    return {
            "fulfillmentText": fulfillmentText,
            "source": "webhookdata"
    }


#run the app
if __name__ == '__main__':
    app.run()