Adapt Intent Parser: Get Additional Info From Utterance

Sorry if this is noobish, but I’ve spent a lot of time looking at the adapt documentation, but am having trouble fitting it into my skill.

I’m working on a skill that does some home automation. I have two intent handlers configured as shown below. While I am inside one of these handlers, how can I access the other parts of the utterance? I tried reading from the variable ‘message’, but it is not a neatly formatted JSON object as I am expecting returned from adapt.

@intent_handler(IntentBuilder("OnIntent").require("OnKeyword"))
def handle_on_intent(self, message):
    #do some stuff

@intent_handler(IntentBuilder("OffIntent").require("OffKeyword"))
def handle_off_intent(self, message):
    #do some stuff

Great question, try
(message.data.get('utterance'))

Best, Kathy

Thanks for the fast reply. That will work, but I’d have to parse the utterance again to get the expected values out. Do you know if there is any way to separate additional values from the utterance when it is parsed for an intent?

I don’t off the top of my head, but @forslund might know?

as @KathyReid indicated. The complete result from adapt is stored as a dict in .data of the message. in here you’ll find entries for your keywords as well. (For example if you have “switch on” and “turn on” registered as OnKeyword you can check which one was used by accessing message.data['OnKeyword'])

There is also a method on the message to get the parts of the message not captured by adapt message.utterance_remainder() Not sure if that’s what you’re after?

2 Likes

Hey, thanks for the help. I was trying to spare you some details, but at this point it might help. Basically, I would like to user to be able to specify the device name, like “turn on nameOfDevice”. I can parse the message parameter and try to get a device name, but the utterance was already parsed for intent.

Is there some way to use adapt to do this? I was able to clone the example script (python examples/multi_intent_parser.py) such that when I pass that script “turn on deviceName”, adapt finds the intent, deviceName, and powerStatus, and returns a JSON object like the one below (I deleted my example file, so this is the default content).

Do you know if adapt is the default intent parser for incoming utterances?

{
“confidence”: 1.0,
“target”: null,
“Artist”: “the clash”,
“intent_type”: “MusicIntent”,
“MusicVerb”: “play”,
“MusicKeyword”: “music”
}

@forslund might be able to provide more info here

First of all, sorry for the delay

Adapt is the default intent parser, if the intent isn’t found it’s dropped to the fallback system and through that first to padatious (example based intent handler)

No quite sure I understand what you’re getting at here, but you can register keywords from a list of known entities during runtime

    def initialize(self):
        for d in devices_names:
            self.register_vocabulary(d, 'DeviceName')

  @intent_handler(IntentBuilder("OnIntent").require("OnKeyword")
                                           .require("DeviceName"))
    def handle_on_intent(self, message):
        #do some stuff

(register vocabulary can be run at any point during runtime to add new vocab for a keyword)

If you have a device called “kitchen light” and say “turn on kitchen light” it would hit the handle_on_intent and message.data would contain a DeviceName entry containing kitchen light.

Another option is to use regexes which can be good but is a bit trixy at times.

I might have completely misunderstood your request, sorry about that…

/Åke

Hi @GotTheNumbers,

Maybe you can look at my ESP8266 skill where I did exactly what you try to accomplish : https://github.com/Dark5ide/esp8266-skill

:slight_smile:

in the intent handler you can do

artist = message.data.get(“Artist”)

i your json example artist would contain “the clash"