java - 如何向对话流发送响应
问题描述
我正在尝试使用 dialogflow v2 做一个 facebook 聊天机器人信使。我在 Dialogflow 中配置了 webhook url。我正在从 dialogflow 获取请求。但问题是我不清楚如何将响应发送到对话流。
下面是我的代码
post("/", (request, response) -> {
String body = request.body();
System.err.println(body);
String reply = "Hi";
JSONObject responseJSON = new JSONObject();
JSONObject payload = new JSONObject();
JSONObject google = new JSONObject();
google.put("expectUserResponse", true);
JSONObject richResponse = new JSONObject();
JSONArray itemsArray = new JSONArray();
JSONObject simpleResponseRoot = new JSONObject();
JSONObject simpleResponse = new JSONObject();
simpleResponse.put("textToSpeech", reply);
simpleResponseRoot.put("simpleResponse", simpleResponse);
itemsArray.put(simpleResponseRoot);
richResponse.put("items", itemsArray);
google.put("richResponse", richResponse);
payload.put("google", google);
responseJSON.put("payload", payload);
System.err.println(responseJSON);
return responseJSON;
});
下面是我的json回复
{"payload":{"google":{"richResponse":{"items":[{"simpleResponse":{"textToSpeech":"Hi"}}]},"expectUserResponse":true}}}
但我没有收到对我的 Facebook 页面的回复。
任何人都可以共享代码或 json 格式来发送对话流。
任何帮助将不胜感激!!!
解决方案
问题在于您使用的是 Actions on Google 的回复格式,其中包含的信息比其他集成使用的更多。您可能希望 JSON 更像
{
"fulfillmentText": "Hi"
}
推荐阅读
- php - 在 Ubuntu 上进行 VsCode 调试
- javascript - 是否可以将标记的模板文字与保存为常量的模板文字一起使用?
- javascript - 如何将 C# 中的 bool 映射到 JScript 中的布尔变量?自动转换将布尔值 true 转换为字符串“True”
- azure-ad-graph-api - 在 Azure Graph API 中获取更新注释
- python - 在 Keras 中显示“y”的预测值和对应的实际“x”值
- javascript - 所有 axios 请求都在一台机器上停止,但不是隐身
- javascript - 如何将垫对话框注入服务?
- vue.js - 从父级 Vuejs 打开折叠
- c# - 当我执行 SetParent() 时,我的孩子远离父母
- java - OpenHTMLToPDF 构建非漏洞文档