Overview

dialogflow-fulfillment is a package for Python that helps developers to create webhook services for Dialogflow.

The package provides an API for creating and manipulating response messages, output contexts and follow-up events in conversations.

See also

For more information about fulfillment and how it works, see Fulfillment overview.

A simple example

Working with dialogflow-fulfillment is as simple as passing a webhook request object from Dialogflow (a.k.a. WebhookRequest) to an instance of a WebhookClient and using a handler function (or a mapping of functions for each intent) via the handle_request() method:

simple_example.py
from dialogflow_fulfillment import QuickReplies, WebhookClient


# Define a custom handler function
def handler(agent: WebhookClient) -> None:
    """
    Handle the webhook request.

    This handler sends a text message along with a quick replies
    message back to Dialogflow, which uses the messages to build
    the final response to the user.
    """
    agent.add('How are you feeling today?')
    agent.add(QuickReplies(quick_replies=['Happy :)', 'Sad :(']))


# Create an instance of the WebhookClient
agent = WebhookClient(request)  # noqa: F821

# Handle the request using the handler function
agent.handle_request(handler)

The above code produces the resulting response object (a.k.a. WebhookResponse), which can be accessed via the response attribute:

{
   'fulfillmentMessages': [
      {
         'text': {
            'text': [
               'How are you feeling today?'
            ]
         }
      },
      {
         'quickReplies': {
            'quickReplies': [
               'Happy :)',
               'Sad :('
            ]
         }
      }
   ]
}

Installation

The preferred way to install dialogflow-fulfillment is from PyPI with pip:

$ pip install dialogflow-fulfillment

See also

For further details about the installation, see Installation.

Features

dialogflow-fulfillment’s key features are:

  • Webhook Client: handle webhook requests using a custom handler function or a map of handlers for each intent

  • Contexts: process input contexts and add, set or delete output contexts in conversations

  • Events: trigger follow-up events with optional parameters

  • Rich Responses: create and send the following types of rich response messages:

    • Text

    • Image

    • Card

    • Quick Replies

    • Payload

Limitations

Currently, dialogflow-fulfillment has some drawbacks, which will be addressed in the future:

  • No support for platform-specific responses