Reference documentation and code samples for the Google Cloud Dialogflow V2 Client class Context.
Dialogflow contexts are similar to natural language context. If a person says
to you "they are orange", you need context in order to understand what "they"
is referring to. Similarly, for Dialogflow to handle an end-user expression
like that, it needs to be provided with context in order to correctly match
an intent.
Using contexts, you can control the flow of a conversation. You can configure
contexts for an intent by setting input and output contexts, which are
identified by string names. When an intent is matched, any configured output
contexts for that intent become active. While any contexts are active,
Dialogflow is more likely to match intents that are configured with input
contexts that correspond to the currently active contexts.
For more information about context, see the
Contexts guide.
Generated from protobuf message google.cloud.dialogflow.v2.Context
Namespace
Google \ Cloud \ Dialogflow \ V2
Methods
__construct
Constructor.
Parameters
Name
Description
data
array
Optional. Data for populating the Message object.
↳ name
string
Required. The unique identifier of the context. Format: projects/<Project ID>/agent/sessions/<Session ID>/contexts/<Context ID>, or projects/<Project ID>/agent/environments/<Environment ID>/users/<User ID>/sessions/<Session ID>/contexts/<Context ID>. The Context ID is always converted to lowercase, may only contain characters in a-zA-Z0-9_-% and may be at most 250 bytes long. If Environment ID is not specified, we assume default 'draft' environment. If User ID is not specified, we assume default '-' user. The following context names are reserved for internal use by Dialogflow. You should not use these contexts or create contexts with these names: * * __system_counters__ * * *_id_dialog_context * * *_dialog_params_size
↳ lifespan_count
int
Optional. The number of conversational query requests after which the context expires. The default is 0. If set to 0, the context expires immediately. Contexts expire automatically after 20 minutes if there are no matching queries.
Optional. The collection of parameters associated with this context. Depending on your protocol or client library language, this is a map, associative array, symbol table, dictionary, or JSON object composed of a collection of (MapKey, MapValue) pairs: * * MapKey type: string * * MapKey value: parameter name * * MapValue type: If parameter's entity type is a composite entity then use map, otherwise, depending on the parameter value type, it could be one of string, number, boolean, null, list or map. * * MapValue value: If parameter's entity type is a composite entity then use map from composite entity property names to property values, otherwise, use parameter value.
getName
Required. The unique identifier of the context. Format:
projects/<Project ID>/agent/sessions/<Session ID>/contexts/<Context ID>,
or projects/<Project ID>/agent/environments/<Environment ID>/users/<User
ID>/sessions/<Session ID>/contexts/<Context ID>.
The Context ID is always converted to lowercase, may only contain
characters in a-zA-Z0-9_-% and may be at most 250 bytes long.
If Environment ID is not specified, we assume default 'draft'
environment. If User ID is not specified, we assume default '-' user.
The following context names are reserved for internal use by Dialogflow.
You should not use these contexts or create contexts with these names:
__system_counters__
*_id_dialog_context
*_dialog_params_size
Returns
Type
Description
string
setName
Required. The unique identifier of the context. Format:
projects/<Project ID>/agent/sessions/<Session ID>/contexts/<Context ID>,
or projects/<Project ID>/agent/environments/<Environment ID>/users/<User
ID>/sessions/<Session ID>/contexts/<Context ID>.
The Context ID is always converted to lowercase, may only contain
characters in a-zA-Z0-9_-% and may be at most 250 bytes long.
If Environment ID is not specified, we assume default 'draft'
environment. If User ID is not specified, we assume default '-' user.
The following context names are reserved for internal use by Dialogflow.
You should not use these contexts or create contexts with these names:
__system_counters__
*_id_dialog_context
*_dialog_params_size
Parameter
Name
Description
var
string
Returns
Type
Description
$this
getLifespanCount
Optional. The number of conversational query requests after which the
context expires. The default is 0. If set to 0, the context expires
immediately. Contexts expire automatically after 20 minutes if there
are no matching queries.
Returns
Type
Description
int
setLifespanCount
Optional. The number of conversational query requests after which the
context expires. The default is 0. If set to 0, the context expires
immediately. Contexts expire automatically after 20 minutes if there
are no matching queries.
Parameter
Name
Description
var
int
Returns
Type
Description
$this
getParameters
Optional. The collection of parameters associated with this context.
Depending on your protocol or client library language, this is a
map, associative array, symbol table, dictionary, or JSON object
composed of a collection of (MapKey, MapValue) pairs:
MapKey type: string
MapKey value: parameter name
MapValue type: If parameter's entity type is a composite entity then use
map, otherwise, depending on the parameter value type, it could be one of
string, number, boolean, null, list or map.
MapValue value: If parameter's entity type is a composite entity then use
map from composite entity property names to property values, otherwise,
use parameter value.
Optional. The collection of parameters associated with this context.
Depending on your protocol or client library language, this is a
map, associative array, symbol table, dictionary, or JSON object
composed of a collection of (MapKey, MapValue) pairs:
MapKey type: string
MapKey value: parameter name
MapValue type: If parameter's entity type is a composite entity then use
map, otherwise, depending on the parameter value type, it could be one of
string, number, boolean, null, list or map.
MapValue value: If parameter's entity type is a composite entity then use
map from composite entity property names to property values, otherwise,
use parameter value.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Google Cloud Dialogflow V2 Client - Class Context (2.1.2)\n\nVersion latestkeyboard_arrow_down\n\n- [2.1.2 (latest)](/php/docs/reference/cloud-dialogflow/latest/V2.Context)\n- [2.1.1](/php/docs/reference/cloud-dialogflow/2.1.1/V2.Context)\n- [2.0.1](/php/docs/reference/cloud-dialogflow/2.0.1/V2.Context)\n- [1.17.2](/php/docs/reference/cloud-dialogflow/1.17.2/V2.Context)\n- [1.16.0](/php/docs/reference/cloud-dialogflow/1.16.0/V2.Context)\n- [1.15.1](/php/docs/reference/cloud-dialogflow/1.15.1/V2.Context)\n- [1.14.0](/php/docs/reference/cloud-dialogflow/1.14.0/V2.Context)\n- [1.13.0](/php/docs/reference/cloud-dialogflow/1.13.0/V2.Context)\n- [1.12.3](/php/docs/reference/cloud-dialogflow/1.12.3/V2.Context)\n- [1.11.0](/php/docs/reference/cloud-dialogflow/1.11.0/V2.Context)\n- [1.10.2](/php/docs/reference/cloud-dialogflow/1.10.2/V2.Context)\n- [1.9.0](/php/docs/reference/cloud-dialogflow/1.9.0/V2.Context)\n- [1.8.0](/php/docs/reference/cloud-dialogflow/1.8.0/V2.Context)\n- [1.7.2](/php/docs/reference/cloud-dialogflow/1.7.2/V2.Context)\n- [1.6.0](/php/docs/reference/cloud-dialogflow/1.6.0/V2.Context)\n- [1.5.0](/php/docs/reference/cloud-dialogflow/1.5.0/V2.Context)\n- [1.4.0](/php/docs/reference/cloud-dialogflow/1.4.0/V2.Context)\n- [1.3.2](/php/docs/reference/cloud-dialogflow/1.3.2/V2.Context)\n- [1.2.0](/php/docs/reference/cloud-dialogflow/1.2.0/V2.Context)\n- [1.1.1](/php/docs/reference/cloud-dialogflow/1.1.1/V2.Context)\n- [1.0.1](/php/docs/reference/cloud-dialogflow/1.0.1/V2.Context) \nReference documentation and code samples for the Google Cloud Dialogflow V2 Client class Context.\n\nDialogflow contexts are similar to natural language context. If a person says\nto you \"they are orange\", you need context in order to understand what \"they\"\nis referring to. Similarly, for Dialogflow to handle an end-user expression\nlike that, it needs to be provided with context in order to correctly match\nan intent.\n\nUsing contexts, you can control the flow of a conversation. You can configure\ncontexts for an intent by setting input and output contexts, which are\nidentified by string names. When an intent is matched, any configured output\ncontexts for that intent become active. While any contexts are active,\nDialogflow is more likely to match intents that are configured with input\ncontexts that correspond to the currently active contexts.\nFor more information about context, see the\n[Contexts guide](https://cloud.google.com/dialogflow/docs/contexts-overview).\n\nGenerated from protobuf message `google.cloud.dialogflow.v2.Context`\n\nNamespace\n---------\n\nGoogle \\\\ Cloud \\\\ Dialogflow \\\\ V2\n\nMethods\n-------\n\n### __construct\n\nConstructor.\n\n### getName\n\nRequired. The unique identifier of the context. Format:\n`projects/\u003cProject ID\u003e/agent/sessions/\u003cSession ID\u003e/contexts/\u003cContext ID\u003e`,\nor `projects/\u003cProject ID\u003e/agent/environments/\u003cEnvironment ID\u003e/users/\u003cUser\nID\u003e/sessions/\u003cSession ID\u003e/contexts/\u003cContext ID\u003e`.\n\nThe `Context ID` is always converted to lowercase, may only contain\ncharacters in `a-zA-Z0-9_-%` and may be at most 250 bytes long.\nIf `Environment ID` is not specified, we assume default 'draft'\nenvironment. If `User ID` is not specified, we assume default '-' user.\nThe following context names are reserved for internal use by Dialogflow.\nYou should not use these contexts or create contexts with these names:\n\n- `__system_counters__`\n- `*_id_dialog_context`\n- `*_dialog_params_size`\n\n### setName\n\nRequired. The unique identifier of the context. Format:\n`projects/\u003cProject ID\u003e/agent/sessions/\u003cSession ID\u003e/contexts/\u003cContext ID\u003e`,\nor `projects/\u003cProject ID\u003e/agent/environments/\u003cEnvironment ID\u003e/users/\u003cUser\nID\u003e/sessions/\u003cSession ID\u003e/contexts/\u003cContext ID\u003e`.\n\nThe `Context ID` is always converted to lowercase, may only contain\ncharacters in `a-zA-Z0-9_-%` and may be at most 250 bytes long.\nIf `Environment ID` is not specified, we assume default 'draft'\nenvironment. If `User ID` is not specified, we assume default '-' user.\nThe following context names are reserved for internal use by Dialogflow.\nYou should not use these contexts or create contexts with these names:\n\n- `__system_counters__`\n- `*_id_dialog_context`\n- `*_dialog_params_size`\n\n### getLifespanCount\n\nOptional. The number of conversational query requests after which the\ncontext expires. The default is `0`. If set to `0`, the context expires\nimmediately. Contexts expire automatically after 20 minutes if there\nare no matching queries.\n\n### setLifespanCount\n\nOptional. The number of conversational query requests after which the\ncontext expires. The default is `0`. If set to `0`, the context expires\nimmediately. Contexts expire automatically after 20 minutes if there\nare no matching queries.\n\n### getParameters\n\nOptional. The collection of parameters associated with this context.\n\nDepending on your protocol or client library language, this is a\nmap, associative array, symbol table, dictionary, or JSON object\ncomposed of a collection of (MapKey, MapValue) pairs:\n\n- MapKey type: string\n- MapKey value: parameter name\n- MapValue type: If parameter's entity type is a composite entity then use map, otherwise, depending on the parameter value type, it could be one of string, number, boolean, null, list or map.\n- MapValue value: If parameter's entity type is a composite entity then use map from composite entity property names to property values, otherwise, use parameter value.\n\n### hasParameters\n\n### clearParameters\n\n### setParameters\n\nOptional. The collection of parameters associated with this context.\n\nDepending on your protocol or client library language, this is a\nmap, associative array, symbol table, dictionary, or JSON object\ncomposed of a collection of (MapKey, MapValue) pairs:\n\n- MapKey type: string\n- MapKey value: parameter name\n- MapValue type: If parameter's entity type is a composite entity then use map, otherwise, depending on the parameter value type, it could be one of string, number, boolean, null, list or map.\n- MapValue value: If parameter's entity type is a composite entity then use map from composite entity property names to property values, otherwise, use parameter value."]]