Rich responses#

Card#

class Card(title=None, subtitle=None, image_url=None, buttons=None)[source]#

Bases: dialogflow_fulfillment.rich_responses.base.RichResponse

Send a card response to the end-user.

Examples

Constructing a Card response:

>>> card = Card(
...     title='What is your favorite color?',
...     subtitle='Choose a color',
...     buttons=[{'text': 'Red'}, {'text': 'Green'}, {'text': 'Blue'}]
... )
Parameters
  • title (str, optional) – The title of the card response.

  • subtitle (str, optional) – The subtitle of the card response. Defaults

  • image_url (str, optional) – The URL of the card response’s image.

  • buttons (list(dict(str, str)), optional) – The buttons of the card response.

Return type

None

See also

For more information about the Card response, see the Card responses section in Dialogflow’s documentation.

property buttons: Optional[List[Dict[str, str]]]#

The buttons of the card response.

Examples

Accessing the buttons attribute:

>>> card.buttons
[{'text': 'Red'}, {'text': 'Green'}, {'text': 'Blue'}]

Assigning value to the buttons attribute:

>>> card.buttons = [{'text': 'Cyan'}, {'text': 'Magenta'}]
>>> card.buttons
[{'text': 'Cyan'}, {'text': 'Magenta'}]
Raises

TypeError – If the value to be assigned is not a list of buttons.

Type

list(dict(str, str)), optional

property image_url: Optional[str]#

The URL of the card response’s image.

Examples

Accessing the image_url attribute:

>>> card.image_url
None

Assigning value to the image_url attribute:

>>> card.image_url = 'https://picsum.photos/200/300.jpg'
>>> card.image_url
'https://picsum.photos/200/300.jpg'
Raises

TypeError – If the value to be assigned is not a string.

Type

str, optional

property subtitle: Optional[str]#

The subtitle of the card response.

Examples

Accessing the subtitle attribute:

>>> card.subtitle
'Choose a color'

Assigning value to the subtitle attribute:

>>> card.subtitle = 'Select a color below'
>>> card.subtitle
'Select a color below'
Raises

TypeError – If the value to be assigned is not a string.

Type

str, optional

property title: Optional[str]#

The title of the card response.

Examples

Accessing the title attribute:

>>> card.title
'What is your favorite color?'

Assigning value to the title attribute:

>>> card.title = 'Which color do you like?'
>>> card.title
'Which color do you like?'
Raises

TypeError – If the value to be assigned is not a string.

Type

str, optional

Image#

class Image(image_url=None)[source]#

Bases: dialogflow_fulfillment.rich_responses.base.RichResponse

Send an image response to the end-user.

Examples

Constructing an image response:

>>> image = Image('https://picsum.photos/200/300.jpg')
Parameters

image_url (str, optional) – The URL of the image response.

Return type

None

See also

For more information about the Image response, see the Image responses section in Dialogflow’s documentation.

property image_url: Optional[str]#

The URL of the image response.

Examples

Accessing the image_url attribute:

>>> image.image_url
'https://picsum.photos/200/300.jpg'

Assigning a value to the image_url attribute:

>>> image.image_url = 'https://picsum.photos/200/300?blur.jpg'
>>> image.image_url
'https://picsum.photos/200/300?blur.jpg'
Raises

TypeError – If the value to be assigned is not a string.

Type

str, optional

Payload#

class Payload(payload=None)[source]#

Bases: dialogflow_fulfillment.rich_responses.base.RichResponse

Send a custom payload response to the end-user.

This type of rich response allows to create advanced, custom, responses.

Examples

Constructing a custom Payload response for file attachments:

>>> payload_data = {
...     'attachment': 'https://example.com/files/some_file.pdf',
...     'type': 'application/pdf'
... }
>>> payload = Payload(payload_data)
Parameters

payload (dict, optional) – The content of the custom payload response.

Return type

None

See also

For more information about the Payload response, see the Custom payload responses section in Dialogflow’s documentation.

property payload: Optional[Dict[Any, Any]]#

The content of the custom payload response.

Examples

Accessing the payload attribute:

>>> payload.payload
{'attachment': 'https://example.com/files/some_file.pdf', 'type': 'application/pdf'}

Assigning a value to the payload attribute:

>>> payload.payload = {
...     'attachment': 'https://example.com/files/another_file.zip',
...     'type': 'application/zip'
... }
>>> payload.payload
{'attachment': 'https://example.com/files/another_file.zip', 'type': 'application/zip'}
Raises

TypeError – If the value to be assigned is not a dictionary.

Type

dict, optional

Quick Replies#

class QuickReplies(title=None, quick_replies=None)[source]#

Bases: dialogflow_fulfillment.rich_responses.base.RichResponse

Send a collection of quick replies to the end-user.

When a quick reply button is clicked, the corresponding reply text is sent back to Dialogflow as if the user had typed it.

Examples

Constructing a QuickReplies response:

>>> quick_replies = QuickReplies('Choose an answer', ['Yes', 'No'])
Parameters
  • title (str, optional) – The title of the quick reply buttons.

  • quick_replies (list, tuple(str), optional) – The texts for the quick reply buttons.

Return type

None

See also

For more information about the QuickReplies response, see the Quick reply responses section in Dialogflow’s documentation.

property quick_replies: Optional[Union[List[str], Tuple[str]]]#

The texts for the quick reply buttons.

Examples

Accessing the quick_replies attribute:

>>> quick_replies.quick_replies
['Yes', 'No']

Assigning a value to the quick_replies attribute:

>>> quick_replies.quick_replies = ['Yes', 'No', 'Maybe']
>>> quick_replies.quick_replies
['Yes', 'No', 'Maybe']
Raises

TypeError – if the value to be assigned is not a list or tuple of strings.

Type

list, tuple(str), optional

property title: Optional[str]#

The title of the quick reply buttons.

Examples

Accessing the title attribute:

>>> quick_replies.title
'Choose an answer'

Assigning a value to the title attribute:

>>> quick_replies.title = 'Select yes or no'
>>> quick_replies.title
'Select yes or no'
Raises

TypeError – If the value to be assigned is not a string.

Type

str, optional

Rich Response#

class RichResponse[source]#

Bases: object

The base (abstract) class for the different types of rich responses.

See also

For more information about the RichResponse, see the Rich response messages section in Dialogflow’s documentation.

Text#

class Text(text=None)[source]#

Bases: dialogflow_fulfillment.rich_responses.base.RichResponse

Send a basic (static) text response to the end-user.

Examples

Constructing a Text response:

>>> text = Text('this is a text response')
Parameters

text (str, optional) – The content of the text response.

Return type

None

See also

For more information about the Text response, see the Text responses section in Dialogflow’s documentation.

property text: Optional[str]#

The content of the text response.

Examples

Accessing the text attribute:

>>> text.text
'this is a text response'

Assigning a value to the text attribute:

>>> text.text = 'this is a new text response'
>>> text.text
'this is a new text response'
Raises

TypeError – If the value to be assigned is not a string.

Type

str, optional