[英]Google Assistant make GET request and reply with server response
I'd like to create an action in Google Assistant such that when a voice command is issued, the Assistant will make a GET request to a URL, like http://example.com/response.txt and just read out the plaintext response.我想在 Google Assistant 中创建一个动作,这样当发出语音命令时,Assistant 将对 URL 发出 GET 请求,例如http://example.com/response.txt并读出纯文本响应. How do I go about doing that?
我该怎么做?
You would need to create an Action using Actions Builder or Dialogflow.您需要使用 Actions Builder 或 Dialogflow 创建一个 Action 。
This Action would start with a 'Default Welcome Intent' that you should connect it to a webhook:此操作将以“默认欢迎意图”开始,您应该将其连接到网络钩子:
This webhook can be written simply using a language like Node.js这个 webhook 可以简单地使用 Node.js 之类的语言编写
import {conversation} from '@assistant/conversation'
const fetch = require('node-fetch')
const app = conversation()
const URL = 'http://example.com/response.txt'
app.handle('Default Welcome Intent', async conv => {
const apiResponse = await fetch(URL)
const text = await apiResponse.text()
conv.add(text)
})
Depending on whether you just want static information or not, you may want to then add a transition to 'end conversation' to close it out.根据您是否只需要静态信息,您可能需要添加一个过渡到“结束对话”以将其关闭。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.