forked from xVir/apiai-python-webhook
-
Notifications
You must be signed in to change notification settings - Fork 562
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to use Python3, App Engine Flex and Dialogflow API V2
Change-Id: I7f930e5b9618f4f1b094ff484c7dee9deed11765
- Loading branch information
Matt Carroll
committed
Apr 16, 2018
1 parent
9669590
commit 8026d50
Showing
15 changed files
with
1,245 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,2 @@ | ||
### Python template | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
env/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*,cover | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Created by .ignore support plugin (hsz.mobi) | ||
*.pyc | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,38 @@ | ||
# Api.ai - sample webhook implementation in Python | ||
|
||
This is a really simple webhook implementation that gets Api.ai classification JSON (i.e. a JSON output of Api.ai /query endpoint) and returns a fulfillment response. | ||
|
||
More info about Api.ai webhooks could be found here: | ||
[Api.ai Webhook](https://docs.api.ai/docs/webhook) | ||
|
||
# Deploy to: | ||
[![Deploy to Heroku](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy) | ||
|
||
# What does the service do? | ||
It's a weather information fulfillment service that uses [Yahoo! Weather API](https://developer.yahoo.com/weather/). | ||
The services takes the `geo-city` parameter from the action, performs geolocation for the city and requests weather information from Yahoo! Weather public API. | ||
|
||
The service packs the result in the Api.ai webhook-compatible response JSON and returns it to Api.ai. | ||
# Dialogflow Fulfillment Weather Sample Python (Flask) | ||
|
||
## Setup Instructions | ||
|
||
### WWO Weather API Setup | ||
1. Get a WWO API key, by going to https://developer.worldweatheronline.com/api/ and following the instructions to get an API key that includes forecasts 14 days into the future | ||
1. Paste your API key for the value of the `WWO_API_KEY` varible on line 28 of `config.py` | ||
|
||
### Dialogflow Setup | ||
1. Create an account on Dialogflow | ||
1. Create a new Dialogflow agent | ||
1. Restore the `dialogflow-agent.zip` ZIP file in the root of this repo | ||
1. Go to your agent's settings and then the *Export and Import* tab | ||
1. Click the *Restore from ZIP* button | ||
1. Select the `dialogflow-agent.zip` ZIP file in the root of this repo | ||
1. Type *RESTORE* and and click the *Restore* button | ||
|
||
### Fulfillment Setup | ||
1. Deploy fulfillment to App Engine | ||
1. [Download and authenticate the Google Cloud SDK](https://cloud.google.com/sdk/docs/quickstart-macos) | ||
1. Run `gcloud app deploy`, make a note of the service URL, which will be used in the next step | ||
1. Set the fulfillment URL in Dialogflow to your App Engine service URL | ||
1. Go to your [agent's fulfillment page](https://console.dialogflow.com/api-client/#/agent//fulfillment) | ||
1. Click the switch to enable webhook for your agent | ||
1. Enter you App Engine service URL (e.g. `https://weather-10929.appspot.com/`) to the URL field | ||
1. Click *Save* at the bottom of the page | ||
|
||
## How to report bugs | ||
* If you find any issues, please open a bug here on GitHub | ||
|
||
## How to make contributions? | ||
Please read and follow the steps in the [CONTRIBUTING.md](CONTRIBUTING.md). | ||
Please read and follow the steps in the CONTRIBUTING.md | ||
|
||
## License | ||
See [LICENSE](LICENSE). | ||
See LICENSE.md | ||
|
||
## Terms | ||
Your use of this sample is subject to, and by using or downloading the sample files you agree to comply with, the [Google APIs Terms of Service](https://developers.google.com/terms/). | ||
|
||
This is not an official Google product | ||
Your use of this sample is subject to, and by using or downloading the sample files you agree to comply with, the [Google APIs Terms of Service](https://developers.google.com/terms/) and the [Dialogflow's Terms of Use and Privacy Policy](https://dialogflow.com/terms/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
runtime: python | ||
env: flex | ||
entrypoint: gunicorn -b :$PORT main:app | ||
|
||
runtime_config: | ||
python_version: 3 | ||
|
||
# This sample incurs costs to run on the App Engine flexible environment. | ||
# The settings below are to reduce costs during testing and are not appropriate | ||
# for production use. For more information, see: | ||
# https://cloud.google.com/appengine/docs/flexible/python/configuring-your-app-with-app-yaml | ||
manual_scaling: | ||
instances: 1 | ||
resources: | ||
cpu: 1 | ||
memory_gb: 0.5 | ||
disk_size_gb: 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# -*- coding:utf8 -*- | ||
# !/usr/bin/env python | ||
# Copyright 2017 Google Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Module that holds the configuration for app.py including | ||
API keys, temperature and forecast defaults and limits | ||
This is meant to be used with the sample weather agent for Dialogflow, located at | ||
https://console.dialogflow.com/api-client/#/agent//prebuiltAgents/Weather | ||
This requires setting the WWO_API_KEY constant in config.py to a string with | ||
a valid WWO API key for retrieving weather up to 14 days in the future. Get an | ||
WWO API key here: https://developer.worldweatheronline.com/api/ | ||
""" | ||
|
||
WWO_API_KEY = '<INSERT_WWWO_API_KEY_HERE>' | ||
MAX_FORECAST_LEN = 13 | ||
_DEFAULT_TEMP_UNIT = 'F' | ||
|
||
_TEMP_LIMITS = { | ||
'hot': {'C': 25, 'F': 77}, | ||
'warm': {'C': 15, 'F': 59}, | ||
'chilly': {'C': 15, 'F': 41}, | ||
'cold': {'C': -5, 'F': 23} | ||
} |
Binary file not shown.
Oops, something went wrong.