context.message_tone doesnt work

I’m trying to access context.message_tone and dialog_tone in a message node to evaluate sentiment management. which seems to be not populated even the tone of the utterance is generated. Find below screenshots for reference.
one two

@hareen.yalavarti
Please note, message_tone does not have any object with key “angry”. The way you are checking results in a null /undefined which makes the if condition false.
Try with

context.message_tone[0].level

Please consider on the same lines as (both message_tone and dialog_tone are at same level as context) the following:

    if(context.dialog_tone){
    if(context.dialog_tone.length){
        print("Dialog tone array node: \n" + JSON.stringify(context.dialog_tone[(context.dialog_tone.length - 1)]));
    } else {
        print("No length found for dialog tone array. here is the array: \n" + JSON.stringify(context.dialog_tone));
    }

    } else {
    print("No dialog tone found");
    }

Also as defined in
https://developer.kore.ai/docs/bots/advanced-topics/working-with-tone-processing/
message tone is for a particular node. Not every utterance will generate message tone. Dialog tone is average for entire dialog.

1 Like

But technically if you see in the debug window message_tone object has some data as well as dialog_tone, but when i try to find the length of the object message_tone it gives me Zero and JSON.stringify(context.message_tone[0]) gives an empty object.
Also as you said the message_tone doesnt have a key angry is true. Then why in the end of the document that you shared says
You can access and use tone scores to help drive the flow of your dialog task using conditional transition statements, for example,

if context.message_tone.angry > 2.0
    then goTo liveAgent

@swagata.sengupta Thank you for your response.
i’ve tried with the code shared in your response.
png
png

So you can see in the above messages, even though there are objects in the message_tone and dialog_tone from debug window it gives an empty array in the bot response i.e coming from not satisfying the condition if(context.message_tone.length)