Search code examples
botframework

Accessing Key name of turn.intents in Composer


For the sake of this discussion, let's say I need to echo back the name of the intent that was recognized without having a trigger for every intent.

The system returns turn.recognized.intents which is

{
“Inmate”: {
"score": 0.433454782
}

There are various things listed in the documentation (memory-model-overview), none of which I've been able to get to work.

turn.recognized.score returns the value of score (0.433454782).

turn.recognized.intentName (as described in the doc) returns null.

How do I get the name "Inmate" back?

To test this out, I created a simple EchoBot which uses LUIS and has two intents: none & greeting. I create a trigger for the greeting intent which echos back @{turn.activity.text}. It also echoes back @{turn.recognized.score}. The following return as null or rather "object reference not set to an instance of an object"

  • turn.recognized.intents.intentName
  • turn.recognized.intents
  • turn.recognized

Solution

  • It's because the structure is actually:

    turn.recognized.intent not "intents" as described in the documentation.

    Or rather, the documentation is not fully descriptive. The turn.recognized object is:

    {
    “text”: “hello”,
    “alteredText”: null,
    “intent”: “Greeting”,
    “score”: 0.960900247,
    “intents”: {
    "Greeting": {
      "score": 0.960900247
    }
    },
    “entities”: {
    "$instance": {}
    }
    

    and this does contain "intents" as well as "intent". I think that the reference in the documentation to "IntentName" was meant to be descriptive rather than literal. There is no property "IntentName" but I'm guessing it was referring to the intent name (in this case) "Greeting" in the structure.