Skip to content

Instantly share code, notes, and snippets.

@blacklight
Created July 26, 2019 16:54
Show Gist options
  • Save blacklight/cae50f74e996d34621deda9d940ac7d3 to your computer and use it in GitHub Desktop.
Save blacklight/cae50f74e996d34621deda9d940ac7d3 to your computer and use it in GitHub Desktop.
[Medium] platypush event hook example 1
# Play a specific radio on the mpd (or mopidy) plugin
event.hook.PlayRadioParadiseAssistantCommand:
if:
type: platypush.message.event.assistant.SpeechRecognizedEvent
phrase: "play (the)? radio paradise"
then:
action: music.mpd.play
args:
resource: tunein:station:s13606
# Search and play a song by an artist. Note the use of ${} to identify
# parts of the target attribute that should be preprocessed by the hook
event.hook.SearchSongVoiceCommand:
if:
type: platypush.message.event.assistant.SpeechRecognizedEvent
phrase: "play ${title} by ${artist}"
then:
- action: music.mpd.clear # Clear the current playlist
-
action: music.mpd.search
args:
filter:
- artist
- ${context.get('artist')} # Note the special map variable "context" to access data from the current context
- title
- ${context.get('title')}
- # music.mpd.search will return a list of results under "output". context['output'] will
# therefore always containt the output of the last request. We can then get the first
# result and play it.
action: music.mpd.play
args:
resource: ${context['output'][0]['file']}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment