如何从 android 中的 DialogFlow 代理获取文本响应?

How to get Text response from DialogFlow agent in android?

How do I get this Default response in Android?

我希望得到与我在 android 中执行此 CURL 请求时相同的响应。有没有办法使用 API.AI SDK 或其他方式做到这一点?

您可以使用 Dialogflow Android SDK。查看有关集成和访问 Dialogflow 代理的文档。

采取行动

final Result result = response.getResult();
Log.i(TAG, "Action: " + result.getAction());

获得演讲

final Result result = response.getResult();
final String speech = result.getFulfillment().getSpeech();
Log.i(TAG, "Speech: " + speech);

获取元数据

final Result result = response.getResult();
final Metadata metadata = result.getMetadata();
if (metadata != null) {
  Log.i(TAG, "Intent id: " + metadata.getIntentId());
  Log.i(TAG, "Intent name: " + metadata.getIntentName());
}

获取参数

final Result result = response.getResult();
final HashMap<String, JsonElement> params = result.getParameters();
if (params != null && !params.isEmpty()) {
  Log.i(TAG, "Parameters: ");
  for (final Map.Entry<String, JsonElement> entry : params.entrySet()) {
      Log.i(TAG, String.format("%s: %s", entry.getKey(), entry.getValue().toString()));
  }
}