0

I am creating a chatbot to manage customers support. I have a flow called "Products Problem". It should detect what type of product is concerned and redirect to another flow specific to that type. The idea here is to make smaller flows that are easier to manage.

For each request I need three elements: the product type, the brand and a description of the problem. In the initial request, a lot of customers will use the brand name. In most cases, the brand will also determine the type of product.

For exemple let's say I created three entities: cars ("Volvo" and "Bentley"), television ("Sony", "Panasonic") and product-type ("car", "television"). If the initial request is "I have an issue with my Volvo", I know the brand but I also know the product-type. The brand is detected but not the product-type.

I created a webhook to manage that. I have no error but the product-type parameter is not set.

webhook

exports.mapBrandToProductType = (req,res) => {
  const brand = req.body.sessionInfo.parameters.brand;
  const fullUrl = req.body.sessionInfo.session + "/contexts/product-type-context";

  let productType;

  if (brand === "Volvo" || brand === "Bentley") {
    productType = "car";
  } else if (brand === "Sony" || brand === "Panasonic") {
    productType = "television"
  }

  const response = {
    fulfillment_response: {
      messages: [
        {
          text: {
            text: ["product is a " + productType],
          }
        }
      ],
      outputContexts: [
        {
          name: fullUrl,
          lifespan_count: 60,
          parameters: {
            "product-type": productType
          }
        }
      ]
    }
  };

  res.status(200).send(response)
}

I have a page "Problem Info" where the product-type is required to make the redirection to another flow. I added the webhook to the fulfillment.

When I test the chatbot, I see a text showing that product-type was set correctly is my js code. But the parameter is still missing.

Thbwun
  • 323
  • 1
  • 3
  • 14

1 Answers1

0

The possible reason why product-type parameter is missing is there is an error in the code of your webhook. Setting the parameters using outputContexts is part of Dialogflow ES webhook. In order to make it work, change the webhook response object with SessionInfo parameters.

Here is an example code from webhook documentation:

// Build and return the response.
    response := webhookResponse{
        FulfillmentResponse: fulfillmentResponse{
            Messages: []responseMessage{
                {
                    Text: text{
                        Text: []string{t},
                    },
                },
            },
        },
        SessionInfo: sessionInfo{
            Parameters: p,
        },
    }
    return response, nil
}
Poala Astrid
  • 1,028
  • 2
  • 10