Adrian_Santamaria | 2023-11-20 13:42:40 UTC | #1
Hello
The Available Topics documentation includes the JSON schema for the events that each topic returns. I was wondering if the SDKs have the Model definitions to parse those events, or if I have to code the parsing logic for each of them myself.
The SDK includes a lot of "EventTopic" objects, but I couldn't find the documentation for them :frowning:
I am using the Python SDK, FWIW.
Adrian_Santamaria | 2023-12-01 11:08:23 UTC | #2
Could you check this, please?
tim.smith | 2023-12-01 15:04:20 UTC | #3
You can find the topic to model mappings here: https://github.com/MyPureCloud/platform-client-sdk-python/blob/master/notificationMappings.json
There's not a built-in wrapper for notification handling in python, I believe because python's websocket tools are pretty straightforward and a generic wrapper doesn't add a lot of value. You can refer to one of the other SDKs for a general design pattern if you want to implement the same: https://github.com/MyPureCloud/platform-client-sdk-dotnet/blob/master/build/src/PureCloudPlatform.Client.V2/Extensions/Notifications/NotificationHandler.cs.
Adrian_Santamaria | 2023-12-07 13:11:54 UTC | #4
Thank you, Tim!
I understand not having the Notification Handling included in the SDK, as you said it is pretty straightforward. But it would be nice to have a method to unmarshal the JSON to the SDK models easily.
Also, it would be wonderful if that topic-to-model info were included in the Available Topics documentation :smiley:
tim.smith | 2023-12-07 15:20:58 UTC | #5
Adrian_Santamaria, post:4, topic:23223
But it would be nice to have a method to unmarshal the JSON to the SDK models easily.
You can use the function for that in the sdk: https://github.com/MyPureCloud/platform-client-sdk-python/blob/master/build/PureCloudPlatformClientV2/api_client.py#L429
Adrian_Santamaria | 2023-12-12 14:12:07 UTC | #6
Thank you Tim. But that method receives a RESTResponse object, so it cannot be used for this.
There is the __deserialize method that works, but it is a hidden method and therefore it should not be used...
And BTW, are there any plans to include the Model Mappings in the documentation?
tim.smith | 2023-12-12 15:11:16 UTC | #7
Adrian_Santamaria, post:6, topic:23223
But that method receives a RESTResponse object, so it cannot be used for this.
Just package your data into that object. If you look at the code, the only thing it does is pass the data property into the private function. Or you can call the private function directly. Sure, you shouldn't generally use private methods but python lacks an actual concept of public/private, so go for it. Especially because it's an open source project and you can do whatever you want with the code anyway.
Adrian_Santamaria, post:6, topic:23223
And BTW, are there any plans to include the Model Mappings in the documentation?
I'm not aware of any plans. You can request this at https://genesyscloud.ideas.aha.io/ though.
Adrian_Santamaria | 2023-12-12 15:12:39 UTC | #8
Yeah, it's a little bit hacky but I think it will work anyways...
tim.smith | 2023-12-12 15:15:54 UTC | #9
Isn't that python's motto? ;)
Adrian_Santamaria | 2023-12-12 15:24:57 UTC | #10
Well, if the method were declared as _deserialize, it would mean more like "you should not need to use this". But instead, it is __deserialize, which usually means that "the creator doesn't want you to use this".
The main problem with the hacky solutions is that there is no proof that they will continue working in the future. :sweat_smile: Changes in the guts of the library that are not part of the public interface are not usually announced either. :joy:
tim.smith | 2023-12-12 15:37:18 UTC | #11
I can promise you that naming wasn't intentional; that's from the off-the-shelf template used when starting the project. We generally support, as a concept, you (de)serializing your own objects using the SDKs functions.
Changes to that method signature may not be announced, but it's extremely unlikely to change after so many years being untouched. It may be updated when the SDK is refreshed (slated for 2024), but that will be a major change that's announced and you'll need to willfully introduce into your project.
system | 2024-01-11 15:38:01 UTC | #12
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 23223