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.
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);
via Xavier_Ex
No comments:
Post a Comment