Mycroft Community Forum

Ask question to user without needing user interaction first

Hi!
This is my first time posting so I’d first like to say greetings to the mycroft community!
I’ve got experience with python but I’m trying to develop a skill on the picroft that I’d like to ask survey questions to a user. I’d like this skill to be prompted whenever an external application - say a mobile app - decides to send a question through. Or perhaps the questions are asked at particular times. In any case, I’m trying to figure out how to go about this and any help at all would be greatly appreciated!
I was wondering if there was a way to keep the skill running indefinitely? Or can I start the skill from a script on the raspberry pi? In any case, I’d like a question to be asked without the user needing to first interact with the picroft. I’d also need a way to record answers received.
As I said, any help is greatly appreciated thank you!

1 Like

Skills are called when the parser matches a question to their dialogue. If the question matches, the relevant skill is called, passing along the query.

One simply way would be to use the ``mycroft-sayto``` script in mycroft-core/bin.

so on the command line that would look like:
mycroft-core/bin/mycroft-sayto “what’s the weather like?”

You could also play with the mycroft message bus, and send things as json messages to mycroft and interact that way. This would be more useful if you needed to something more low level though imho.

https://mycroft-ai.gitbook.io/docs/mycroft-technologies/mycroft-core/message-types#messagebus-connection

2 Likes

Both options look like what I’m looking for thank you!
The second option appears to be more what I’m looking for. I’m a little unsure how to go about this. From looking at the messagebus connection I see that I could maybe add something like this to my external script:

question = “whats your name”
python3 -m mycroft.messagebus.send ‘question’
And I could have mycroft pick this this up in the skill with:

def initialize(self):
self.add_event(‘question’,
self.handler_question)

def handler_question(self, message):
response = self.response(message)
#send response to database

I’m not sure how mycroft would know what skill is being invoked but would this be plausible?

If you are just injecting your question as an utterance you can use:

python3 -m mycroft.messagebus.send 'recognizer_loop:utterance' '{ "utterances": ["how tall is the eiffel tower"] }'

If you want to use a custom message type I’d suggest something like:

python3 -m mycroft.messagebus.send 'skill.my-skill-name.question' '{ "text": "how tall is the eiffel tower" }'

Then adding the event handler as you have.

Giving it a unique namespace just avoids the chance of conflicts, it’s easy to see someone else creating a question message type that is completely different to yours, and if both ended up in the Marketplace and installed on someones device they would both try to respond to each others events.