How to integrate Dialogflow V2 into my Application?

Viewed 1669

In my android application, I'm integrating the Dialogflow V2 Agent. There's no specific SDK for Android yet. So I'm using the java client library from Dialogflow. followed the tutorial https://github.com/dialogflow/dialogflow-java-client-v2/issues/25.

I've added the dependencies(dialogflow & oauth2) and created a service account in the google-cloud console. Added the credential file into raw folder. followed the tutorial here https://github.com/dialogflow/dialogflow-java-client-v2/issues/25. Getting the error as

java.lang.NoSuchMethodError: No static method decodeBase64(Ljava/lang/String;)[B in class Lorg/apache/commons/codec/binary/Base64; or its super classes (declaration of 'org.apache.commons.codec.binary.Base64' appears in /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!");
        }
    }

Is there any clear documentations on how to integrate Dialogflow v2 into my android application.

1 Answers

The tutorial you were following was updated. In case anyone is facing this issue, according to the repo:

Save your CLIENT_ACCESS_TOKEN in gradle.properties

Related