watson-developer-cloud / node-red-node-watson

A collection of nodes for the IBM Watson services
Apache License 2.0
82 stars 86 forks source link

User ID metrics is not easy to implement #479

Open epetecof opened 3 years ago

epetecof commented 3 years ago

Now that Watson Assistant Plus and Premium are charged based on unique users per month it would be nice to have a msg.params.user_id property for the AssistantV2 node, in order to specify your unique identifier.

I was trying to do it using the msg.additional_context property for including context.global.system.user_id in my messages (as recommended in this link of the documentation), but after a few tries I saw that the analytics tab showed no data for unique users.

Looking at the code, I discovered that the msg.additional_context property is only suitable for adding variables in the user defined context (context.skills.main skill.user_defined). As a work around (for you that, like me, spent some time banging your head against the wall) I discovered that you can change the root context using msg.params.context, but you need to maintain the same pattern used in the original code (or it will break the msg.additional_context logic), like this:

msg.params = {
        context: {
            global: {
                system: {
                    user_id: msg.twilio.From
                }
            },
            skills: {
                'main skill': {
                    user_defined: {}
                }
            }
        }
    }

Please let me know if there is already a better way to do this, I didn't find it. Thanks!

OBS: If you are using Twilio, like me, it is a good idea to use the Body.From property as your identifier

chughts commented 3 years ago

I think the best way would be for the node to allow global system level context setting. Keeping this issue open allowing for pull requests with suggested resolutions.