Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass Messages to CommonSkill handlers #2875

Open
NeonDaniel opened this issue Mar 31, 2021 · 4 comments · May be fixed by #2876
Open

Pass Messages to CommonSkill handlers #2875

NeonDaniel opened this issue Mar 31, 2021 · 4 comments · May be fixed by #2876

Comments

@NeonDaniel
Copy link
Member

Is your feature request related to a problem? Please describe.
Similar to #2812, Messages are easier to write generic methods around so a CommonSkill match method could be easily adapted from an intent handler, more data is available, supporting methods can always expect Messages, etc.

Describe the solution you'd like
Like #2813 resolved #2812, I propose passing messages instead of just text. I think passing the callback data in the action methods does provide some convenience, though that is also included in the message so it would be possible to use messages alone.

Describe alternatives you've considered
There is currently no other means for passing extra data into match_query_phrase. action can receive extra data via the callback_data param, though inserting a message into the callback_data seems like more of a workaround than a solution.

Additional context
None

@forslund
Copy link
Collaborator

forslund commented Mar 31, 2021

What sort of extra data are you interested to pass into the CPS_match_query() method?

The signature was made like it is to provide a simple interface where the purpose of the arguments are understandable and easy to operate on.

If we want to give access to the Message maybe we can make a lowelevel version that can be used in place of the more highlevel versions.

for the common playback skill something like:

    def __handle_play_query(self, message):
        """Query skill if it can start playback from given phrase."""
        search_phrase = message.data["phrase"]

        # First, notify the requestor that we are attempting to handle
        # (this extends a timeout while this skill looks for a match)
        self.bus.emit(message.response({"phrase": search_phrase,
                                        "skill_id": self.skill_id,
                                        "searching": True}))

        # CALL THE NEW COOL LOW LEVEL METHOD WITH THE MESSAGE
        result = self._CPS_low_level_match_query(message)

        if result:
            match = result[0]
            level = result[1]
            callback = result[2] if len(result) > 2 else None
            confidence = self.__calc_confidence(match, search_phrase, level)
            self.bus.emit(message.response({"phrase": search_phrase,
                                            "skill_id": self.skill_id,
                                            "callback_data": callback,
                                            "service_name": self.spoken_name,
                                            "conf": confidence}))
        else:
            # Signal we are done (can't handle it)
            self.bus.emit(message.response({"phrase": search_phrase,
                                            "skill_id": self.skill_id,
"searching": False}))

    def _CPS_low_level_match_query(self, message):
        return self.CPS_match_query_phrase(message.data['phrase'])

So if the complete message object is of interest the _CPS_low_level_match_query() method can be overridden.

Edit: fixed some issues in the code...

@NeonDaniel
Copy link
Member Author

I do see advantages to passing something simple like 'phrase'. My initial thought was actually just to add message so it would be an optional parameter in addition to phrase. I mainly did this the way I did to match what we did in converse (removed utterance based on feedback that it was redundant)..

For the Neon use case that prompted this change for me, we include user data in message objects for our requests to support multiple users. In general, adding params to Message objects helps maintain context throughout the core which I see as a benefit.

@NeonDaniel
Copy link
Member Author

Is there a strong preference from anyone here one way or the other? I like Ake's suggestion as it means less work to maintain backwards comatibility now, though I see adding an extra 'message' param (in addition to phrase) as possibly more logical going forward.. Skill authors would be encouraged to add the param for signatures to match, but wouldn't have to do anything differently to interface

@JarbasAl
Copy link
Contributor

JarbasAl commented Apr 9, 2021

i like @forslund suggestion! not sure about the naming of the new function, but the implementation looks solid and i would like to see that in all common_XXX frameworks. for the hivemind i often need the message object for proper routing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants