Skip to content

Commit

Permalink
Update to use Python3, App Engine Flex and Dialogflow API V2
Browse files Browse the repository at this point in the history
Change-Id: I7f930e5b9618f4f1b094ff484c7dee9deed11765
  • Loading branch information
Matt Carroll committed Apr 16, 2018
1 parent 9669590 commit 8026d50
Show file tree
Hide file tree
Showing 15 changed files with 1,245 additions and 227 deletions.
63 changes: 2 additions & 61 deletions .gitignore
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
10 changes: 7 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ Please fill out either the individual or corporate Contributor License Agreement
(CLA).

* If you are an individual writing original source code and you're sure you
own the intellectual property, then you'll need to sign an [individual CLA](https://developers.google.com/open-source/cla/individual).
own the intellectual property, then you'll need to sign an [individual CLA]
(https://developers.google.com/open-source/cla/individual).
* If you work for a company that wants to allow you to contribute your work,
then you'll need to sign a [corporate CLA](https://developers.google.com/open-source/cla/corporate).
then you'll need to sign a [corporate CLA]
(https://developers.google.com/open-source/cla/corporate).

Follow either of the two links above to access the appropriate CLA and
instructions for how to sign and return it. Once we receive it, we'll be able to
Expand All @@ -26,7 +28,9 @@ accept your pull requests.
1. Fork the desired repo, develop and test your code changes.
1. Ensure that your code adheres to the existing style in the sample to which
you are contributing. Refer to the
[Google Cloud Platform Samples Style Guide](https://github.com/GoogleCloudPlatform/Template/wiki/style.html) for the
[Google Cloud Platform Samples Style Guide]
(https://github.com/GoogleCloudPlatform/Template/wiki/style.html) for the
recommended coding standards for this organization.
1. Ensure that your code has an appropriate set of unit tests which all pass.
1. Submit a pull request.

12 changes: 0 additions & 12 deletions Dockerfile

This file was deleted.

1 change: 0 additions & 1 deletion Procfile

This file was deleted.

52 changes: 32 additions & 20 deletions README.md
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/).
7 changes: 0 additions & 7 deletions app.json

This file was deleted.

121 changes: 0 additions & 121 deletions app.py

This file was deleted.

17 changes: 17 additions & 0 deletions app.yaml
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
37 changes: 37 additions & 0 deletions config.py
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 added dialogflow-agent.zip
Binary file not shown.
Loading

0 comments on commit 8026d50

Please sign in to comment.