Mycroft Community Forum

Catch-all intent handler for contexts

Can someone confirm that event handlers based on context should be fired on any utterance?

It seems that was the case until recently, now one of my skills is broken.

Consider the following.

# bridge.of.death.voc
# bridge of death
    @intent_handler(IntentBuilder('BridgeOfDeathIntent')
                    .require('bridge.of.death'))   
    def handle_bridge_of_death_intent(self, message):
        self.speak_dialog("What is your name?", expect_response=True)
        self.set_context('AskQuestContex')
        
    @intent_handler(IntentBuilder('').require('AskQuestContex').build())   
    def handle_quest_context_intent(self, message):
        self.remove_context('AskQuestContex')
        self.speak_dialog("What is your quest?")

I expect the second handler to respond to any utterance, since ‘AskQuestContext’ is set.

This is what happens:

 bridge of death                                                                                         
 >> What is your name?                                                                                   
 sir robin                                                                                       --- 4.59
 >> You might have to say that a different way.

Interestingly I have a file named “sir.lancelot.voc” containing the single line “sir lancelot”.

Even though the file is never mentioned in init.py this happens:

 bridge of death                                                                                         
 >> What is your name?                                                                                   
 sir lancelot                                                                                  5 -*- 4.80
 >> What is your quest? 

Hi Wiggins,

Contexts should certainly be taken into account for any intent handler, however I’d advise against having an Adapt intent handler with only 1 requirement, and especially where that requirement is a context.

If you know you want to capture the response within the same Skill, I’d suggest using self.get_response() rather than setting expect_response=True

There’s a section of our docs detailing a few different ways you can prompt the user, it also includes video’s for a few of them if you prefer that medium:

In this instance it might look something like:

from mycroft import AdaptIntent, MycroftSkill, intent_handler

class BridgeOfDeathSkill(MycroftSkill):

    @intent_handler(AdaptIntent('BridgeOfDeathIntent')
                    .require('bridge.of.death'))   
    def handle_bridge_of_death_intent(self, message):
        name = self.get_response('ask-for-name')
        self.ask_for_quest('name')
        
    def ask_for_quest(self, name: str):
        self.speak_dialog('ask-for-quest', name)

Would that meet your needs or is there another reason you want to use contexts?
I appreciate the code you posted is probably just a quick example.

Hey Gez,

Thanks for the reply and taking the time to write the code. The code I posted was an altered version of the hello world skill to show a problem I’m having in a skill that has been in the marketplace for 2 years working fine but has recently had an issue because of my misuse of context.

I see now the difference between Conversational Context and Get Response. It should be pretty straight-forward to convert my code.

I’m curious about what determines the length of recording time Mycroft uses. The docs say get_response() will “activate the microphone for 3-10 seconds allowing the User to respond”, I wonder how that time interval is selected or if there is a way to set it. Not relevant to my issue, but it caught my eye.

1 Like

Ah right - Adapt has certainly had a lot of updates lately so it’s possible that this did change some thing. There’s also many newer ways to do things so sounds like the Skill will be better than ever soon :slight_smile:

As for the 3-10 seconds
3 seconds is the minimum recording period and it will stop when a period of silence is detected as this is assumed to be the end of the utterance.