简体   繁体   English

Google 助理发出 GET 请求并使用服务器响应进行回复

[英]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.

相关问题 Google助理请求权限 - Google Assistant request permission 哪个更好用于Google智能助理? Actions SDK或JSON请求响应 - Which is better to use for Google Assistant? Actions SDK or JSON request response 如何处理对外部REST服务的请求并将响应返回给Google智能助理? - How to process a request to an external REST service and return the response to Google Assistant? 从 GOOGLE ASSISTANT 到 PRIVATE SERVER 的 HTTP POST 并转换语音响应 - HTTP POST from GOOGLE ASSISTANT to PRIVATE SERVER and convert response in voice Google 助理回复“抱歉,我没有收到任何回复” - Google Assistant responding with “Sorry, I didn't get any response” 由于自己的应用程序参数,使用Google Assistant进行GET / POST调用 - Make GET/POST calls with google assistant due to own app parameters Google Assistant SDK - 操作从 SQL 服务器获取信息 - Google Assistant SDK - Actions get information from SQL Server 谷歌DialogFlow V2实现中的神秘错误(谷歌助手模拟器空响应,请求,错误选项卡) - Google DialogFlow V2 mysterious error in fulfillment (Google Assistant simulator empty response, request, error tab) Google Actions(Google Assistant)响应中的电话号码 - Phone Number in Google Actions (Google Assistant) Response 让 Google 助理听 1 分钟 - Make Google Assistant listen for 1 minute
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM