How do I configure Alexa to access a REST API?

16

3

I have several lights connected to relays which are connected to a wiolink

I can turn the lights on and off through the REST API, like so:

curl https://us.wio.seeed.io/v1/node/GroveRelayD0/onoff/[onoff]?access_token=xxxxx

How can I access this REST API through Alexa with an Echo Dot?

spuder

Posted 2016-12-13T05:24:14.113

Reputation: 391

Answers

13

See these instructions.

Create an AWS developer account & AWS account.

In the AWS console

  • Create a lambda function. Include in the lambda function some code that will access the API. This can either be python or java or node.js.

Here is a python script. Change modify_state to be either 1 or 0

import urllib2

def modify_state( port, state, token):
    url = 'https://us.wio.seeed.io/v1/node/%s/onoff/%s?access_token=%s' % (port, state, token)
    req = urllib2.Request(url,'')
    response = urllib2.urlopen(req)

def lambda_handler(event, context):
    modify_state('GroveRelayD0', <STATE:0:1>, '<APIKEY')
    # TODO implement
    return {
        'version': '1.0',
        'sessionAttributes': {},
        'response': {
            'outputSpeech': {
                'type': 'PlainText',
                'text': '<whatever whitty remark alexa should say>'
            },
            'card': {
                'type': 'Simple',
                'title': "SessionSpeechlet - foo",
                'content': "SessionSpeechlet - bar" 
            },
            'reprompt': {
                'outputSpeech': {
                    'type': 'PlainText',
                    'text': 'I know right'
                }
            },
            'shouldEndSession': True
        }
    }
  • Make sure to publish new version (copy the ARN in the top right, you'll need it later)

aws lambda code

  • Set the 'trigger' to alexa skills

aws trigger configuration


In the developer console

  • Create a skill create a skill dialog

  • Create an Interaction Model with an intent, and a sample utterance intent schema dialog

  • Link the endpoint

endpoint configuration dialog

You can skip the last 2 steps. The skill will run in development mode and only you will be able to access it. Complete the last 2 steps only if you want to share your skill with anyone in the world.

spuder

Posted 2016-12-13T05:24:14.113

Reputation: 391

1If one doesn't publish I have to connect my Echo to a developer account, right?Helmar 2016-12-14T10:59:10.107