-
-
Notifications
You must be signed in to change notification settings - Fork 15
Intent declaration
Intents are declared on top of the module class
from core.base.model.Intent import Intent
from core.base.model.Module import Module
class FooModule(Module):
_INTENT_DELETE_ME = Intent('DeleteMe')
In this simple exemple we have declared a new static variable as an intent with the topic DeleteMe
. DeleteMe
refers to the intent name you've declared in your dialog template. The topic path and your dev name are appended automatically when the Intent instance is created/called. You can then use it later in your module script.
def onMessage(self, intent: str, session: DialogSession) -> bool:
if not self.filterIntent(intent, session):
return False
if intent == self._INTENT_DELETE_ME:
self.doSomething()
Alice can refuse to do something randomly, and the chance for her to deny a request is based on her mood. Her mood can evolve toward persons she likes, that are polite, that entertain her etc etc. Alice will never deny a request if that said request is nicely asked, so instead of turn off the lights!
which has a probability to be denied, you could say please, turn off the lights
.
But, sometimes, some intents should not be denied, such as a "Yes/No" confirmation per exemple. For that you can protect intents. Those intents will never be denied, whatever happens. To protect an intent, you have to declare it as protected:
from core.base.model.Intent import Intent
from core.base.model.Module import Module
class FooModule(Module):
_INTENT_CONFIRM = Intent('AnswerYesOrNo', isProtected=True)
She will never refuse to you answering yes or no, for this module!