Python package for handling requests from Amazon and API.AI. Supoorts Alexa, Google Home, Google Assistant, Slack and Web Apps.
pip install git+https://github.com/TheLampshady/all_voice.git
The AllVoice Base Skill allows a developer to extend a single class and inherit the functionality of the skill associated with the service making the call. By uses dynamic parenting from different types of base skill (e.g. Alexa, Google Home) the request and response are handling implicitly while providing support for multiple devices.
The developer can extend one class and just focus on developing actions with easy access to slots/parameters or session attributes. With session support, the Amazon attribute is used and a default case is added for API.AI
#TODO Add Alexa context support.
#TODO Add Alexa yes support to handle context of the question being answered
Developers can create there skill by extending the AllVoice and adding their Intents as functions.
from all_voice.models import AllVoice
class TalkToMeSkill(AllVoice):
"""My Skill"""
def AwesomeIntent(self):
"""My Intent/Action"""
return self.build_response("I am awesome.")Developers can also use a single skill class such as just Alexa
from all_voice.models import AlexaSkill
class TalkToMeSkill(AlexaSkill):
"""My Skill"""
def AwesomeIntent(self):
"""My Intent/Action"""
return self.build_response("I am awesome.")User objects are created by extending the BaseUser class. By default an AllVoice user provides
simple logging powered by a python dict. Do not rely on this for webhooks that scale.
from all_voice.models import BaseUser
class UserClass(BaseUser): passOnce created, the class can be passes a a parameter to your skills init.
def webhook(event):
skill = TalkToMeSkill(event, UserClass)Developers can extend the unittest class and utils for generating JSON events fomr various services.
import unittest
from all_voice.tests.utils import AllVoiceTestUtils
class TestBaseIntent(AllVoiceTestUtils, unittest.TestCase):
def setUp(self):
super(TestBaseIntent, self).setUp()Since the parents are dynamic, references to class fields / methods will be correct but IDEs will reference the unimplemented code and not the dynamic classes (Alexa / Google Home)
Fulfillments can be hosted on various platforms with this library.
This exmaple will go through hosting your webhook in Google App Engine with Python an WebApp2 Review this link for a quickstart into google app engine. Google App Engine Quickstart
-
Create your
- config
app.yaml - application
webapp2.WSGIApplication - handler class
class Webhook(BaseHandler)
- config
-
Link your
app.yamlto thewebapp2.WSGIApplication
- url: .*
script: routes._APP
secure: always-
Add a route to your web hook handler
webapp2.Route("/webhook", handler=Webhook, name='webhook'),
-
Add your skill to handler
import json
# ....
def post(self):
event = json.loads(self.request.body)
request = TalkToMeSkill(event)
response = json.dumps(request.response())
self.response.headers['Content-Type'] = 'application/json'
return self.response.out.write(response)- Install this library for upload
pip install -t libs git+https://github.com/TheLampshady/all_voice.git
This example will provide the code for hosting a webhook on lambda functions. A brief tutorial on creating a lmbda function Alexa on Lambda Function
- Create a a function that takes the parameters below in a file called.
lambda_function.py
from my_skill import TalkToMeSkill
def lambda_handler(event, context={}):
return TalkToMeSkill(event=event).response()- Install this library for upload
pip install -t libs git+https://github.com/TheLampshady/all_voice.git