I am using Kotlin to access the response from a DialogFlow agent. The response in android console is as follows,
parameters {
fields {
key: "EmployeeID"
value {
number_value: 12345.0
}
}
}
In kotlin, I am using SessionClient to create a function that returns a custom response of multiple fields,
fun detectIntentTexts(
text: String,
sessionId: String,
languageCode: String
): TextResponse {
val sessionsSettings = SessionsSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credentials))
.build()
SessionsClient.create(sessionsSettings).use {
sessionsClient - >
val session = SessionName.of(credentials.projectId, sessionId)
val textInput = TextInput.newBuilder()
.setText(text).setLanguageCode(languageCode)
val queryInput = QueryInput
.newBuilder().setText(textInput).build()
val response = sessionsClient.detectIntent(session, queryInput)
return TextResponse(response.queryResult.fulfillmentText, response.queryResult.parameters.fieldsMap)
}
}
In an another Kotlin class, I am trying to access response.queryResult.parameters.fieldsMap
using getValue(key:String) as the fieldsMap returns it of type MutableMap<String, Value>.
Whenever I try to access the value of the key,
Log.i("TEST",answer.parametersMap.getValue("EmployeeID").toString())
It keeps throwing the following error on build,
Cannot access class 'com.google.protobuf.Value'.
Check your module classpath for missing or conflicting dependencies
Note: When I access the
response.queryResult.parameters.fieldsMap.values.toString()
it does not throw any error. I have also tried adding protobuf dependencies in build.gradle file using this documentation, it still gives the above error on build.
It would be great if someone could resolve it in kotlin and provide some insight as to why its not accessible.