Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python alternative of agent.setContext()

In node.js we can set context using agent.setContext(), what will be python alternative of using this way?

Currently I am using below code to set new context:

res = {
    "fulfillmentText = "This is a test",
    "outputContexts": [
        {
            "name": "projects/project_id/agent/sessions/session_id/contexts/your_context",
            "lifespanCount": 5,
            "parameters": {
                "foo": "bar",
                "foo1": "bar1"
            }
        }
    ],
}
return res

Is there any simpler way?
Thanks in advance.

Note : It seems like node.js have dialogflow-fulfillment library to ease up the things. Is there any similar fulfillment library for python as well?

like image 846
sid8491 Avatar asked Apr 30 '26 04:04

sid8491


2 Answers

The Node.js dialogflow-fulfillment library is owned and maintained by Dialogflow/Google. There is no "official" Dialogflow Python fulfillment library but there are a couple community efforts you can fork:

  • Flask extension: https://github.com/treethought/flask-assistant
  • Response generation helper: https://github.com/pragnakalp/dialogflow-webhook-response-libary-in-python
like image 89
matthewayne Avatar answered May 04 '26 05:05

matthewayne


There is no standard python fulfillment library at this time. Sounds like an opportunity for you!

The format for setting output contexts looks correct, and isn't really much more difficult than the equivalent in JavaScript. How much simpler do you want it?

like image 33
Prisoner Avatar answered May 04 '26 06:05

Prisoner