https://github.com/stanwood/alexa-skill
A flexible and easy-to-use package for building Alexa skill applications.
https://github.com/stanwood/alexa-skill
alexa alexa-skills-kit python
Last synced: 6 months ago
JSON representation
A flexible and easy-to-use package for building Alexa skill applications.
- Host: GitHub
- URL: https://github.com/stanwood/alexa-skill
- Owner: stanwood
- License: mit
- Created: 2018-09-27T09:02:18.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-05-01T20:22:16.000Z (over 2 years ago)
- Last Synced: 2025-04-14T09:16:54.364Z (6 months ago)
- Topics: alexa, alexa-skills-kit, python
- Language: Python
- Homepage: https://pypi.org/project/alexa-skill/
- Size: 39.1 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://alexa-skill.readthedocs.io/en/latest/)
[](https://travis-ci.org/stanwood/alexa-skill)# alexa-skill
[alexa-skill](https://github.com/stanwood/alexa-skill) is flexible, easy to use and extend package for creating Alexa skill applications.
This package is based on [alexa documentation](https://developer.amazon.com/docs/custom-skills/request-and-response-json-reference.html).
## Installing
Install and update using pip:
```bash
pip install -U alexa-skill
```## Examples
Define intent class
```python
from alexa_skill.intents import BaseIntentsclass ExampleIntents(BaseIntents):
@property
def mapper(self):
return {
'EXAMPLE.hello': self.hello,
}def hello(self):
return self.response('Hello. Nice to meet you.'), True
```Define intent class with slots
```python
from alexa_skill import dates
from alexa_skill.intents import BaseIntentsclass DateIntents(BaseIntents):
@property
def mapper(self):
return {
'EXAMPLE.date_intent': self.date_intent,
}def date_intent(self, slots):
date, date_type = dates.AmazonDateParser.to_date(slots['dateslot']['value'])
text = "Your date is {} and it is a {}".format(
date.strftime('%Y%m%d'),
date_type
)return self.response(text), True
```
Define buildin intents
```python
from alexa_skill.intents import BuildInIntentsbuildin_intents = BuildInIntents(
help_message='Say "HI" to us',
not_handled_message="Sorry, I don't understand you. Could you repeat?",
stop_message='stop',
cancel_message='cancel'
)
```### [Falcon](examples/falcon_app/main.py)
Initiate intents in fulfiller webhook for Alexa
```python
import loggingimport alexa_skill
import falconclass Fulfiller(object):
def on_post(self, req, resp):
get_response = alexa_skill.Processor(
req.media,
buildin_intents,
'Welcome to Alexa skill bot',
'Good bye',
ExampleIntents(), # Insert created Intents as arguments
DateIntents(),
)
json_response, handled = get_response()logging.info('Response was handled by system: {}'.format(handled))
resp.media = json_response
app = falcon.API(media_type=falcon.MEDIA_JSON)
app.add_route('/v1/alexa/fulfiller', Fulfiller())
```### [Flask](examples/flask_app/main.py)
```python
import loggingimport alexa_skill
from flask import Flask, request, jsonifyapp = Flask(__name__)
@app.route("/v1/alexa/fulfiller", methods=['POST'])
def fulfiller():
get_response = alexa_skill.Processor(
request.json,
buildin_intents,
'Welcome to Alexa skill bot',
'Good bye',
ExampleIntents(),
DateIntents(),
)
json_response, handled = get_response()logging.info('Response was handled by system: {}'.format(handled))
return jsonify(json_response)
```## Documentation
Auto generate documentation
```bash
cd docs/
sphinx-apidoc -o ./source/_modules/ ../alexa_skill/
make html
```