简体   繁体   English

对Google Assistant使用Actions SDK

[英]Use Actions SDK for Google Assistant

I am trying to use Actions SDK in my own Server, the actions that I made are showed in Google Assistant, but it's not working, the assistant just closes without showing any errors. 我正在尝试在自己的服务器中使用Actions SDK,我执行的操作会显示在Google助手中,但无法正常工作,该助手只会关闭而不会显示任何错误。 This is my code: 这是我的代码:

 'use strict'; const express = require('express'); const bodyParser = require('body-parser'); var exps = express(); exps.use(bodyParser.json()); const {actionssdk} = require('actions-on-google'); const app = actionssdk({debug: true}); const asyncTask = () => new Promise( resolve => setTimeout(resolve, 1000) ); exps.post('/', function(request, response) { app.intent('actions.intent.MAIN', (conv) => { return asyncTask() .then(() => conv.ask('Hi, this is a test!')); }); }); express().use(bodyParser.json(), app).listen(3000); 

Request and Debug tabs Both Errors and Response are empty. 请求和调试选项卡错误和响应均为空。

Looking at the documentation ( https://developers.google.com/actions/assistant/responses ) suggests that you are attempting to call conv.ask() incorrectly. 查看文档( https://developers.google.com/actions/assistant/responses )可能表明您尝试错误地调用conv.ask()。 I would imagine you'd need something like this: 我想您会需要这样的东西:

conv.ask(new SimpleResponse({speech: 'Hi, this is a test!', text: 'Hi, this is a test!'}));

I think the issue is that you are creating two different express objects. 我认为问题在于您正在创建两个不同的表达对象。 One gets mounted on the '/' path, but isn't setup to listen on any port. 一个安装在“ /”路径上,但未设置为在任何端口上侦听。 The other listens on a port, but doesn't have any paths setup for it to handle. 另一个侦听一个端口,但没有设置要处理的任何路径。

Changing your listener line to 将您的听众线路更改为

exps.use(bodyParser.json(), app).listen(3000);

will make it so the express object where you've setup the '/' path will also be the one listening on the port. 它将使您在其中设置了“ /”路径的Express对象也将成为侦听端口的对象。

It also appears that your webhook is listening at the '/' path, but you've specified the webhook in your actions.json file as using the '/node/' path. 似乎您的Webhook正在侦听“ /”路径,但您已在action.json文件中将Webhook指定为使用“ / node /”路径。 (It is a little difficult to read the screen shot - which is why we request you post the text and not a screen shot.) If you either change your webhook to listen to '/node/' or change the actions.json file to use '/', it should work. (阅读屏幕截图有点困难-这就是我们要求您发布文本而不是屏幕截图的原因。)如果您将webhook更改为侦听'/ node /'或将actions.json文件更改为使用“ /”,它应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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