如何将Dialogflow V2集成到我的应用程序中?

时间:2019-01-12 12:28:24

标签: java android dialogflow

在我的android应用程序中,我正在集成Dialogflow V2代理。尚无适用于Android的特定SDK。所以我正在使用Dialogflow的Java客户端库。遵循了教程https://github.com/dialogflow/dialogflow-java-client-v2/issues/25

我已经添加了依赖项(dialogflow和oauth2),并在google-cloud控制台中创建了一个服务帐户。将凭证文件添加到原始文件夹中。在https://github.com/dialogflow/dialogflow-java-client-v2/issues/25处遵循了本教程。将错误显示为

  

java.lang.NoSuchMethodError:没有静态方法   encodeBase64(Ljava / lang / String;)[B类   Lorg / apache / commons / codec / binary / Base64;或其超一流   (“ org.apache.commons.codec.binary.Base64”的声明出现在   /system/framework/org.apache.http.legacy.boot.jar)

  private void createDialogflow() {
        try {
            InputStream stream = getResources().openRawResource(R.raw.dialogflow_service_credentials);
            GoogleCredentials credentials = GoogleCredentials.fromStream(stream);
            String projectId = ((ServiceAccountCredentials) credentials).getProjectId();

            SessionsSettings.Builder settingsBuilder = SessionsSettings.newBuilder();
            SessionsSettings sessionsSettings = settingsBuilder.setCredentialsProvider(FixedCredentialsProvider.create(credentials)).build();
            sessionsClient = SessionsClient.create(sessionsSettings);
            String uuid = UUID.randomUUID().toString();

            session = SessionName.of(projectId, uuid);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private void sendMessage(String msg) {
        // Java V2
        setTypingMessage();
        QueryInput queryInput = QueryInput.newBuilder().setText(TextInput.newBuilder().setText(msg).setLanguageCode("en-US")).build();
        new RequestJavaV2Task(mContext, session, sessionsClient, queryInput).execute();

    }

    public void callbackV2(DetectIntentResponse response) {
        removeTyingMessage();
        if (response != null) {
            // process aiResponse here
            String botReply = response.getQueryResult().getFulfillmentText();
            Log.d("botReply", "V2 Bot Reply: " + botReply);
            setBotMessage(botReply);
        } else {
            Log.d("botReply", "Bot Reply: Null");
            setBotMessage("There was some communication issue. Please Try again!");
        }
    }

关于如何将Dialogflow v2集成到我的android应用程序中,是否有任何清晰的文档。

1 个答案:

答案 0 :(得分:0)

您关注的tutorial已更新。根据{{​​3}},如果有人遇到此问题:

  

在gradle.properties中保存您的CLIENT_ACCESS_TOKEN