简体   繁体   中英

Alexa test simulator with text vs json

I am developing a custom skill using alexa-sdk , which is tailored towards being used as a Lambda function. However, I was able to set up an express server following this discussion , which involves mocking the lambda context.

When I set up my server and was testing the skill using the Service Simulator in the Alexa dev console. There are two ways to send the request, either via "Text" or "JSON".

If I use the "Text" tab, all I get is just an error saying that "The remote endpoint could not be called, or the response it returned was invalid". However, if I copy the content in the "Server Request" (which is a JSON object) and send it under the "JSON" tab, everything works fine.

Testing using echosim and a real eco device yielded the "cannot reached the skill" error. I suspect the way Alexa sends the "Text" requests to my server is different from "JSON", whatever it is... But I couldn't find any documentation. I inspected my server and it didn't even receive the request while testing via "Text".

Below is my server code using express. It is a simple server listening on port 8080, but I am forwarding that to an https address using ngrok .

'use strict'

const express = require('express')
const bodyParser = require('body-parser')
const context = require('aws-lambda-mock-context')

const alexaLambda = require('./alexaLambda') // where the alexa handler is

const app = express()

app.use(bodyParser.json({ type: 'application/json' }))

app.get('/', (req, res) => {
    console.log('received get')
    resp => res.status(200)
})

app.post('/alexa', (req, res) => {
    var ctx = context()
    console.log('received post: ', req.body)

    alexaLambda.handler(req.body, ctx)

    ctx.Promise
        .then(resp => res.status(200).json(resp))
        .catch(err => console.log(err))
})

app.listen(8080);

Well, I solved the problem by fiddling with the SSL config... I checked the radio button saying " My development endpoint has a certificate from a trusted certificate authority " where I should've checked " My development endpoint is a sub-domain of a domain that has a wildcard certificate from a certificate authority ".

Still, it bothers me as to why testing with JSON works while Text fails.

If you want to work with AWS Lambdas without the extra express code, you can also use our bst proxy tool:
https://bespoken.tools/blog/2016/08/24/introducing-bst-proxy-for-alexa-skill-development

It is similar to ngrok in that it makes your local machine accessible to the Alexa service. It has the added benefit though that you can work directly with Lambdas using it. So you can just say

bst proxy lambda index.js

And it will create an endpoint you can use in your skill for testing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM