Skip to content
This repository was archived by the owner on Jan 6, 2024. It is now read-only.

docs(samples): Adding snippet to extract SessionInfo #457

Merged
merged 6 commits into from
Oct 3, 2022
Merged

docs(samples): Adding snippet to extract SessionInfo #457

merged 6 commits into from
Oct 3, 2022

Conversation

hjosiah
Copy link
Contributor

@hjosiah hjosiah commented Sep 13, 2022

Adding a code sample to show how to extract SessionInfo from a WebhookRequest

Fixes #<444> 🦕

BEGIN_COMMIT_OVERRIDE
docs(samples): Adding snippet to extract SessionInfo
END_COMMIT_OVERRIDE

This snippet provides an example of how to extract SessionInfo from
WebhookRequests.
@hjosiah hjosiah requested review from a team as code owners September 13, 2022 19:54
@hjosiah hjosiah requested a review from engelke September 13, 2022 19:54
@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Sep 13, 2022
@snippet-bot
Copy link

snippet-bot bot commented Sep 13, 2022

Here is the summary of changes.

You are about to add 1 region tag.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label bot added the api: dialogflow Issues related to the googleapis/python-dialogflow-cx API. label Sep 13, 2022
@engelke engelke added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 27, 2022
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 27, 2022
Copy link

@engelke engelke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

def log_session_info_for_troubleshooting(request):
"""Webhook will log session id corresponding to request."""

req = request.get_json()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's a concern about unhandled exceptions, you might want to wrap this in a try block in case the request does not contain well-formed JSON.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There shouldn't be a concern of incorrect json here. Since the doc indicates that the request will contain JSON data this behavior should be guaranteed.



@pytest.fixture
def session_prefix(agent_id):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, but I'm not used to seeing so fixtures used only for other fixtures (instead of static constant test strings, for example). Is this to make it easier to add more tests that use these embedded fixtures in other ways?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially tried the constant approach but I liked Nick's suggestion to use fixtures.

I also updated the code in webhook_log_session_info_test.py with the following summary:

  • session_id is what I want to log and check in the tests so this is a good fixture for all tests
  • session_prefix is a rather long string that in this context does not need a variable agent_id. So I made session_prefix a fixture that I can use for the two types of session strings I needed to test. I also made agent_id available only in the session_prefix scope.
  • session and env_session are critical to the two tests. They now have the same signature.

@parthea parthea changed the title feat: Adding snippet to extract SessionInfo docs(samples): Adding snippet to extract SessionInfo Sep 29, 2022
@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Sep 30, 2022
@parthea parthea added kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels Oct 3, 2022
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Oct 3, 2022
@yoshi-kokoro yoshi-kokoro removed kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Oct 3, 2022
@engelke engelke merged commit d6ef048 into googleapis:main Oct 3, 2022
@parthea parthea added the release-please:force-run To run release-please label Oct 4, 2022
@release-please release-please bot removed the release-please:force-run To run release-please label Oct 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api: dialogflow Issues related to the googleapis/python-dialogflow-cx API. samples Issues that are directly related to samples. size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants