1
votes

Below is the flow diagram from https://cloud.google.com/dialogflow/docs/fulfillment-overview

enter image description here

How to pass request headers from custom chatbot client (integration [2]) to my webhook service[5] through dialogflow API service [4].

I use the RPC call to send the user query (text entered by user in chatbot) to DF API service:

      const dfResponses = await sessionsClient.detectIntent(queryRequest);
      responseBody = dfResponses[0].queryResult;

queryRequest has below structure:

  const queryRequest = {
    session: sessionPath,
    queryInput: {
      text: {
        text: queryText,
        languageCode,
      },
    },
  };

I don't see a way through which I can pass headers to my webhook service from by chatbot widget.

Thanks in advance! :)

UPDATE: Based on the below comment by @Prissoner, I am now trying to pass my auth token to my webhook through queryParams.payload So now my queryRequest is like below:

    session: sessionPath,
    queryInput: {
      text: {
        text: queryText,
        languageCode,
      },
    },
    queryParams: {
      payload: {
        authToken
      }
    },
  };

On calling sessionsClient.detectIntent(queryRequest), I expect request.originalDetectIntentRequest.payload to have the authToken in the webhook request. But then request.originalDetectIntentRequest.payload is an empty object.

2
Why, specifically, do you need the headers? Or are you just trying to send additional information to the webhook? - Prisoner
I am trying to send across jwt token through Authorization header. I want to control the information that the webHook sends back as response based on whether the user is logged in or not. - Praveen Dass

2 Answers

1
votes

You can't include this as part of the header from Dialogflow to your webhook.

You can, however, include this data in the queryParameters that you include as part of the detect intent call. You have a couple of options where to put them:

  1. The payload field contains an arbitrary object structure, so you can put whatever you want here in pretty much any format.
  2. As one of the contexts (specifically as a context parameter). This is a little more rigid, but might be easier to manage and fetch the values in some cases.
0
votes

You can set webhook headers using webhookHeaders() of the queryParams object.

"queryParams": {   
        "webhookHeaders":{
            "Authorization": "Bearer {{access_token}}"
        }
    }

You can pass custom payload using originalDetectIntentRequest