Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to modify conversationData, userStorage values in Kotlin #26

Closed
pawelcala opened this issue Jul 26, 2019 · 7 comments
Closed

Unable to modify conversationData, userStorage values in Kotlin #26

pawelcala opened this issue Jul 26, 2019 · 7 comments

Comments

@pawelcala
Copy link

pawelcala commented Jul 26, 2019

conversationData and userStorage are immutable values and cannot be changed using kotlin.
For now there is no option to modify this! One of possible solution is to override getResponseBuilder in DialogflowApp and construct own ResponseBuilder with custom data BUT ResponseBuilder is internal class.
Someone already noticed that in other task few months ago and you didn't fixed it yet.
Please fix this!

@Fleker
Copy link
Member

Fleker commented Jul 26, 2019

This is the same as #17, where you can clone the object to a mutable implementation.

@cbeaujoin
Copy link

cbeaujoin commented Aug 1, 2019

As said in #17 userStorage works fine when cloned.

But conversationData doesn't works.

The conversationData is overrided in ResponseSerializer.kt

contexts?.forEach { setContext(it, webhookResponse) }

You should put it before line 86

As workaround you can try to access and modify conversationData trough context

ActionContext context = request.getContext(request.getSessionId() + "/contexts/" + "_actions_on_google");
String serializedData = (String) context.getParameters().get("data");
Type empMapType = new TypeToken<Map<String, Object>>() {}.getType();
Map<String, Object> conversationData = new Gson().fromJson(serializedData, empMapType);
...
conversationData.put("test", test);
responseContext.getParameters().put("data", conversationData);

Edit:
The workaround was a bad idea, once the conversationData has been set it can't be parse in the next request due to a class cast exception (String <=> LinkedTreeMap).

val serializedData = parameters?.get("data") as String

@Fleker
Copy link
Member

Fleker commented Aug 15, 2019

The same thing seems to work for conversation data in Kotlin

val sessionData = mutableMapOf<String, Any>()
sessionData.putAll(aogRequest.conversationData)

val headquarters = sessionData["headquarters"] as MutableList<String>
assertEquals("google1", headquarters[0])
headquarters[0] = "google2"

sessionData["headquarters"] = headquarters
val responseBuilder =
        ResponseBuilder(usesDialogflow = false, conversationData = sessionData)

val aogResponse = responseBuilder.build()
val jsonOutput = aogResponse.toJson()

@cbeaujoin
Copy link

Have you noticed that conversationData is overided by the context: [sessionId]/contexts/_actions_on_google

@Fleker
Copy link
Member

Fleker commented Aug 28, 2019

When using Dialogflow?

@cbeaujoin
Copy link

When using Dialogflow?

Yes

@taycaldwell
Copy link
Contributor

Closing as a duplicate of #17

For separate/unrelated bugs, please open a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants