Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Dialogflow to work with V2 API #25975

Merged
merged 2 commits into from Aug 18, 2019

Conversation

jshridha
Copy link
Contributor

@jshridha jshridha commented Aug 16, 2019

Description:

On October 23, 2019, the V1 API for Dialogflow will be shut down forcing users to use the V2 API. Additionally, new Dialogflow accounts are being forced to use the new API. Currently, home assistant does not support this API, so all old Dialogflow intents will stop working and new Dialogflow accounts cannot create workable intents.

This is my first PR to home-assistant, but I tried to follow the docs closely. I'm sure I have messed something up, so please let me know what I can do to fix it.

Related issue (if applicable):
Fixes #18411 and fixes #14343

Pull request with documentation for home-assistant.io (if applicable): home-assistant/home-assistant.io#10149

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly. Update and include derived files by running python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

@homeassistant
Copy link
Contributor

Hi @jshridha,

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@jshridha jshridha changed the title [WIP] Upgrade Dialogflow to work with V2 API Upgrade Dialogflow to work with V2 API Aug 16, 2019
@jshridha
Copy link
Contributor Author

This PR is ready for review.

@balloob
Copy link
Member

balloob commented Aug 16, 2019

Is this a breaking change or is this backwards compatible ?

@@ -84,23 +87,45 @@ class DialogFlowError(HomeAssistantError):

def dialogflow_error_response(message, error):
"""Return a response saying the error message."""
dialogflow_response = DialogflowResponse(message["result"]["parameters"])
_api_version = get_api_version(message)
if _api_version is V1:
Copy link
Member

Choose a reason for hiding this comment

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

Use == for comparison, not is. is is for pointer equivalency.

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 intended pointer equivalency here since it's comparing integers, but I'm happy to change it to ==.

parameters = message["result"]["parameters"]
elif _api_version is V2:
parameters = message["queryResult"]["parameters"]
dialogflow_response = DialogflowResponse(parameters, get_api_version(message))
Copy link
Member

Choose a reason for hiding this comment

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

You should be able to use _api_version here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good eye! Should be fixed now.

@@ -84,23 +87,45 @@ class DialogFlowError(HomeAssistantError):

def dialogflow_error_response(message, error):
"""Return a response saying the error message."""
dialogflow_response = DialogflowResponse(message["result"]["parameters"])
_api_version = get_api_version(message)
Copy link
Member

Choose a reason for hiding this comment

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

Please don't prefix parameters with _ if you're using them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed - that was bad styling on my part. It's fixed now.

req = message.get("result")
action_incomplete = req["actionIncomplete"]
_api_version = get_api_version(message)
if _api_version is V1:
Copy link
Member

Choose a reason for hiding this comment

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

idem.

)
req = message.get("result")
action_incomplete = req.get("actionIncomplete", True)
if action_incomplete is True:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if action_incomplete is True:
if action_incomplete:

Copy link
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

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

This looks great ! After reading the code it is backwards compatible 👏

A few minor comments but after that ok to merge 🐬

Dev automation moved this from Needs review to Review in progress Aug 16, 2019
@jshridha jshridha closed this Aug 16, 2019
Dev automation moved this from Review in progress to Cancelled Aug 16, 2019
@jshridha jshridha reopened this Aug 16, 2019
Dev automation moved this from Cancelled to Needs review Aug 16, 2019
@MartinHjelmare MartinHjelmare moved this from Needs review to Review in progress in Dev Aug 16, 2019
@jshridha
Copy link
Contributor Author

@balloob I added the changes you requested. Let me know if you want it rebased into one commit.

Copy link
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

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

Looks great, awesome work ! 🎉

Dev automation moved this from Review in progress to Reviewer approved Aug 18, 2019
@balloob balloob merged commit 6907e8e into home-assistant:dev Aug 18, 2019
Dev automation moved this from Reviewer approved to Done Aug 18, 2019
@lock lock bot locked and limited conversation to collaborators Aug 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Dev
  
Done
Development

Successfully merging this pull request may close these issues.

Dialogflow API v2 not working with webhooks - Needs updating Dialogflow V2 API not supported
3 participants