Skip to content
This repository was archived by the owner on Sep 8, 2024. It is now read-only.

Conversation

@forslund
Copy link
Collaborator

A new way to create intent handlers for skills by simply decorating the methods with @intent_handler(...).

Example of what it would look like:

from mycroft.skills.core import MycroftSkill, intent_handler
from adapt.intent import IntentBuilder


class ASkill(MycroftSkill):
    def __init__(self):
        super(ASkill, self).__init__('ASkill')

    @intent_handler(IntentBuilder('AskillIntent').require('ASkill1').build())
    def handle(self, message):
        self.speak('A Skill handler')

    @intent_handler(IntentBuilder('AskillIntent2').require('ASkill2').build())
    def handle2(self, message):
        self.speak('Another Skill handler')

    @intent_handler(IntentBuilder('AskillIntent3').require('ASkill3').build())
    def handle3(self, message):
        self.speak('Third Skill handler')


def create_skill():
    return ASkill()

The above test case can be downloaded from GoogleDrive. Each of the intent handlers can be triggered with first skill, another skill and third_skill

Normal intent registration is still available (def initialize(self)...) so this is 100% backward compatible.

Future improvement: Adding possibility to read intent from file.

@forslund forslund added the Type: Enhancement - proposed New proposal for a feature that is not currently a priority on the roadmap. label Jun 30, 2017
@forslund forslund requested a review from penrods June 30, 2017 12:24
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.05%) to 40.042% when pulling 82575fd on forslund:feature/decorate-intenthandlers into 96c0818 on MycroftAI:dev.

@augustnmonteiro
Copy link
Contributor

That's awesome!

Copy link
Contributor

@penrods penrods left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@penrods penrods merged commit 54783a1 into MycroftAI:dev Jul 5, 2017
@forslund forslund deleted the feature/decorate-intenthandlers branch January 31, 2018 07:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Type: Enhancement - proposed New proposal for a feature that is not currently a priority on the roadmap.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants