I have been working on a skill that is supposed to work before other skills. For example: if we want mycroft to act as a teacher (or just an authority figure), we would say something like “teacher mode” and if the person says something like “Hey mycroft dude give me the time” Mycroft would first say “that’s not a respectful way to speak to a teacher” and then answer.
Here is a better step by step to see how it’s supposed to work:
Activate the mode (with an intent like “teacher mode”).
2 Ask something (it is not meant to be used as a get_response() it should be triggered by “Hey Mycroft”).
Since the mode is active, Mycroft analyzes the request (that’s the part where it should say “that’s not respectful”).
It should then send the request for the other skills that are concerned (time, weather…)
So far it works for simple queries (fallback-query) but other skills (like weather, date, spelling…) override it and I was wondering if there was a way to make sure Mycroft goes first to my skill and there we could send the request with the message bus?
You can override the converse() method. This can look at all utterances, choose whether to handle them and whether to pass them onto the normal intent handling process.
The Timer Skill uses this to stop the beeping when a timer has expired.
You can see in converse() when a rude word is detected, we speak some dialog and then return True. This “consumes” the phrase so Mycroft doesn’t process it any further. Else if no rude word is found then we return False so Mycroft should pass this onto the normal intent handling process.
Yeah good addition, I’ve thrown this up on Github as a proper Skill:
The converse method will be called if the Skill has been active within the last 5 minutes. So as Jarbas has done, you can register a function to be called based on an event such as a message in the recognizer_loop. I’ve set it to call self.make_active() anytime the wake word is detected (which means this won’t trigger if you type a command into the CLI.
To implement the “teacher_mode” you can add an intent to add / remove the event trigger based on this.
In the polite-skill it shows how to use the converse() method.
When you use it, how do you know if the skills intent is triggered if you don’t use the intent_handler method?
In this example there is no intent that can be triggered. It processes every utterance that Mycroft receives and chooses whether to act or not. I did just realise that the self.log.debug didn’t make sense where it was, so have shifted that. This would then indicate in your logs which path the converse method took.
Is that what you mean?
You can also include intent handlers in the same Skill and they would be triggered in the same way as any other intent.
That Is not what I meant. I want my skill to be triggered for some words and then sometimes to continue to the regular skill.
The problem is, how do I make sure that my skill handler is triggered before the other skills?
My skill is adding a voice identification to Mycroft. So I copied every phrase that I want to be handled from the skills and I want my skill to start every time a phrase is said (like an intent handler) and then go to the regular skill.
The question is how do I add the converse() method with the intent handler together?
def converse(self, utterances):
utt = utterances[0]
# check my.phrases.voc to find matches with spoken utterance
if self.voc_match(utt, "my.phrases"):
# mock the standard message object to pass it to a standard intent handler
mock_message = {'data': {'utterance': utt}}
self.my_intent_handler(mock_message)
# if you don't really need an intent handler you can just pass the utterance
self.my_function(utt)
return True # consume the utterance
else:
return False # pass to normal intent handling process
def my_intent_handler(self, message):
...
def my_function(self, utt):
...
If it’s over matching things it shouldn’t then you could steal the voc_match_exact function from the Playback Control Skill.
I have two skills with the same intent phrase. One of them has a converse() method so it should always run first.
The problem is that both of the skills run. one each time (I think randomly).
Mycroft doesnt show that there was an error.