[英]How to run Alexa skill with the alexa-sdk on own server with Node.js without Lambda drop-in?
The Alexa skill docs will eventually allow you to send webhooks to https
endpoints. Alexa技能文档最终将允许您将webhooks发送到https
端点。 However the SDK only documents lambda style alexa-sdk
usage. 然而,SDK仅记录lambda样式alexa-sdk
用法。 How would one go about running Alexa applications on one's own server without anything abstracting Lambda? 如何在没有任何抽象Lambda的情况下在自己的服务器上运行Alexa应用程序? Is it possible to wrap the event
and context
objects? 是否可以包装event
和context
对象?
You can already use your own endpoint. 您已经可以使用自己的端点了。 When you create a new skill, in the configuration tab, just choose HTTPS and provide your https endpoint. 创建新技能时,在配置选项卡中,只需选择HTTPS并提供https端点。 ASK will call your endpoint where you can run anything you want (tip, check ngrok.com to tunnel to your own dev machine). ASK将调用您的端点,您可以在其中运行任何您想要的东西(提示,检查ngrok.com以隧道到您自己的开发机器)。 Regarding the event
and context
objects; 关于event
和context
对象; your endpoint will receive the event
object information. 您的端点将收到event
对象信息。 You don't need the context
object for anything, that just lets you interact with Lambda-specific stuff ( http://docs.aws.amazon.com/lambda/latest/dg/python-context-object.html ). 您不需要任何context
对象,只允许您与Lambda特定的东西进行交互( http://docs.aws.amazon.com/lambda/latest/dg/python-context-object.html )。 Just make sure that you comply with the (undocumented) timeouts by ASK and you are good to go. 只要确保你遵守ASK的(未记录的)超时,你就可以了。
Here's a way to do this that requires only a small change to your Skill code: 这是一种方法,只需要对您的技能代码进行少量更改:
In your main index.js entry point, instead of: 在主index.js入口点,而不是:
exports.handler = function (event, context) {
use something like: 使用类似的东西:
exports.myAppName = function (funcEvent, res) {
Below that, add the following workaround: 在此之下,添加以下解决方法:
var event = funcEvent.body // since not using Lambda, create dummy context with fail and succeed functions const context = { fail: () => { res.sendStatus(500); }, succeed: data => { res.send(data); } };
Install and use Google Cloud Functions Local Emulator on your laptop. 在笔记本电脑上安装并使用Google Cloud Functions Local Emulator 。 When you start and deploy your function to the emulator, you will get back a Resource URL something like http://localhost:8010/my-project-id/us-central1/myAppName . 当您启动函数并将其部署到模拟器时,您将获得类似http:// localhost:8010 / my-project-id / us-central1 / myAppName的资源URL。
Create a tunnel with ngrok . 用ngrok创建一个隧道。 Then take the ngrok endpoint and put it in place of localhost:8010 in the Resource URL above. 然后取ngrok端点并将其放在上面资源URL中的localhost:8010的位置。 Your resulting fulfillment URL will be something like: https://b0xyz04e.ngrok.io/my-project-id/us-central1/myAppName 您生成的履行URL将类似于: https : //b0xyz04e.ngrok.io/my-project-id/us-central1/myAppName
Use the fulfillment URL (like above) under Configuration in the Alexa dev console, selecting https as the Service Endpoint Type. 使用Alexa dev控制台中Configuration下的履行URL(如上所述),选择https作为服务端点类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.