I got this question via YouTube recently:
Here is a summary of this question:
Here is the original question on StackOverflow.
There is no "native" way to do this
First, there is no native way to do this in Dialogflow. Since the information is coming from an external service, you cannot "attach" such metadata into the intent and have it be sent to the webhook automatically.
In my view, there are two ways to achieve this goal.
Move the webhook logic outside Dialogflow
I have mentioned this in a previous article, but it is possible to move the entire webhook logic outside of Dialogflow.
1 Use the REST API to trigger the intent
2 Get the response from the REST API call
3 Call the external service to get the metadata (in this case the userID)
4 Perform your business logic in code which resides outside Dialogflow
In other words, in this case, you will not enable the "Enable webhook call for this intent" inside the Dialogflow console.
The big downside of this approach is that if for some reason you need to update the context from within your webhook, things become quite complex.
Associate the sessionID to the metadata (UserID) in your backend
The other option is to figure out the sessionID of the current conversation, and associate it with the metadata of interest in your backend database.
Say, the current sessionID is 1001 and the UserID is UserA. You will create a row in your database which will have a mapping from 1001 --> UserA.
When the webhook code executes, it will look at the SessionID, do a lookup on the table to find the userid and then perform the appropriate business logic.
How to actually implement it?
This depends on what you are trying to do. If you need specific advice, you can take a look at my strategy service.
And it is much easier if you are not using the 1-click integration and you are using a custom integration instead. (My gut instinct is that it is not even possible if you are using a 1-click integration, but I am not 100% sure).
I have already mentioned this, but this is just one more example of how a custom integration can be much more useful than using Dialogflow's 1-click integration.