Contexts#

class Context(input_contexts, session)[source]#

Bases: object

A client class for accessing and manipulating input and output contexts.

This class provides an API that allows to create, edit or delete contexts during conversations.

Parameters
  • input_contexts (list(dict)) – The contexts that were active in the conversation when the intent was triggered by Dialogflow.

  • session (str) – The session of the conversation.

Return type

None

input_contexts#

The contexts that were active in the conversation when the intent was triggered by Dialogflow.

Type

list(dict)

session#

The session of the conversation.

Type

str

contexts#

A mapping of context names to context objects (dictionaries).

Type

dict(str, dict)

delete(name)[source]#

Deactivate an output context by setting its lifespan to 0.

Parameters

name (str) – The name of the context.

Return type

None

get(name)[source]#

Get the context object (if exists).

Parameters

name (str) – The name of the context.

Returns

The context object (dictionary) if exists.

Return type

dict, optional

get_output_contexts_array()[source]#

Get the output contexts as an array.

Returns

The output contexts (dictionaries).

Return type

list(dict)

set(name, lifespan_count=None, parameters=None)[source]#

Set a new context or update an existing context.

Sets the lifepan and parameters of a context (if the context exists) or creates a new output context (if the context doesn’t exist).

Parameters
  • name (str) – The name of the context.

  • lifespan_count (int, optional) – The lifespan duration of the context (in minutes).

  • parameters (dict, optional) – The parameters of the context.

Raises

TypeError – If the name is not a string.

Return type

None