0
votes
        $update_response = file_get_contents("php://input");
        $update = json_decode($update_response, true);

        $reply = 'Message';
        $context = array();
        $context[0]['lifespanCount'] = 1;
        $context[0]['name'] = $update['session'].'/contexts/newUser';

        echo json_encode((array(
            'fulfillmentText' => $reply,
            'outputContexts' => $context,
            'source' => 'Agent')));

I'm using the code shown above in my php webhook to set the context of my conversation after an initial.

This is what my fullfillment response looks like once parsed in Dialogflow console

{
  "fulfillmentText": "Message",
  "outputContexts": [
    {
      "lifespanCount": 1,
      "name": "projects/agent-duvwmd/agent/sessions/8b044ab6-cc42-f663-18a3-409e2983c3f1/contexts/newUser"
    }
  ],
  "source": "Agent"
}

My agent is succesfully sending a reply and I can see that the name of the context newUser is shown properly on the dialogflow console, however it wont be accepted as context input for my only other intent.

It wont direct the conversation to my other intent even though I have set its input context as newUser and the parameter entity is set to sys.any so it should basically accepting any input. I only have two intents, and no more contexts so my context is not working at all. I set the lifespancount to 1, somethings 5, yet it doesn't seem to be working at all.

This is such a small project that using the Google Dialogflow Library would be more of a hinderance so I will not use it.

What is causing this problem?

EDIT: This is what the Raw API Response looks like in the next intent (after newUser context is set)

{
  "responseId": "e6a89789-bc1d-4f15-94e4-86404060c4b9-83ffff32",
  "queryResult": {
    "queryText": "Something",
    "parameters": {},
    "languageCode": "es"
  }
}

There is no context or anything. Here is what my contexts look like in intent2

enter image description here

I have webhook disabled on the second intent

enter image description here

2

2 Answers

2
votes

I had my second intent set up with two input contexts, yet I was trying to set only one output context. I thought that I could redirect to another intent with just one of the input contexts but apparently that is not so.

1
votes

I'm not sure if I understand your question correctly but by setting the context in the webhook not necessarily assure you it will redirect to another intent unless otherwise instructed in your code. I programmed my webhooks in .net core but maybe the concept will help you. Try this:

Go to your target intent and create and event in the event textbox (example: intent_event). Create the input context, if needed, and output context. Then in your code after setting the context do a FollowupEventInput with the name of your event (intent_event). This will redirect the flow to this new intent based on the eventnae and it will validate contexts to decide if it is the correct intent.

This is how I did it.

Hope this can give you some guidance