java如何向dialogflow发送响应
我正在尝试使用dialogflow v2制作facebook聊天机器人messenger。 我在Dialogflow中配置了webhook url。我收到dialogflow的请求。 但问题是我不清楚如何将响应发送到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格式来发送dialogflow
任何帮助都将不胜感激
# 1 楼答案
问题是您在Google上使用的是回复格式,它包含比其他集成使用的更多信息。您可能更喜欢JSON