Skip to content

Commit

Permalink
chore: update dialogflow_cx_v3_webhook_configure_session_parameters s…
Browse files Browse the repository at this point in the history
…nippet (#411)
  • Loading branch information
nicain authored Jun 29, 2022
1 parent bef54e0 commit a824898
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,25 @@

""" DialogFlow CX: webhook to configure new session parameters."""

# [START dialogflow_v3beta1_webhook_configure_session_parameters]
# [START dialogflow_cx_v3_webhook_configure_session_parameters]

# TODO (developer): change entry point to configure_session_params in Cloud Function


def configure_session_params(request):
"""Webhook to validate or configure new session parameters."""

request_dict = request.get_json()
tag = request_dict["fulfillmentInfo"]["tag"]

new_session_parameter = "Hi, I am new!"
text = f"{new_session_parameter}. I'm a session parameter configured by the webhook. The webhook's tag is {tag}."
order_number = 123

json_response = {
"fulfillment_response": {
"messages": [
{
"text": {
"text": [
# fulfillment text response to be sent to the agent
text
],
},
},
],
},
"sessionInfo": {
"parameters": {
"newSessionParameter": new_session_parameter,
"orderNumber": order_number,
},
},
}

return json_response


# [END dialogflow_v3beta1_webhook_configure_session_parameters]
# [END dialogflow_cx_v3_webhook_configure_session_parameters]
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,8 @@ def fixture_app():
def test_validate_parameter(app):
"""Test for configure new session parameters."""

request = {"fulfillmentInfo": {"tag": "MOCK_TAG"}}
request = {"fulfillmentInfo": {"tag": "configure-session-parameter"}}

with app.test_request_context(json=request):
res = configure_session_params(flask.request)
assert (
res["fulfillment_response"]["messages"][0]["text"]["text"][0]
== (
"Hi, I am new!. I'm a session parameter configured by the webhook. "
"The webhook's tag is MOCK_TAG."
)
)
assert "orderNumber" in res["sessionInfo"]["parameters"]

0 comments on commit a824898

Please sign in to comment.