Skip to content

Plugin Developer Guide

DelvarWorld edited this page Mar 5, 2012 · 27 revisions

So you want to write a plugin?! You came to the right place!

Modify the default plugin

The easiest way to create a plugin is to modify the existing one. Open this file:

plugins/siriproxy-example/lib/siriproxy-example.rb

You can see a simple structure of how Siri intercepts voice commands. The syntax is:

listen_for /regular expression/i do
    say something
    request_completed
end

When you speak to Siri, it matches the captured text against the regular expressions you specify with each "listen_for". See later in this document for some Ruby regular expression tricks if you aren't familiar with Ruby syntax.

Try changing this line:

  listen_for /test siri proxy/i do

to:

  listen_for /hello siri proxy/i do

Installing your plugin

After modifying the default plugin, stop your Siri server (Ctrl-C). In your Siri root directory (not .siriproxy, but the root of your Siri proxy checkout) run:

siriproxy update .

The '.' is required because otherwise the update will go out to Github to find things. This isn't documented anywhere, so hopefully you found this page!

Start up your Siri proxy server again with:

rvmsudo siriproxy server

Now test it out! Use your phone to say "hello siri proxy". If you get the correct response, it works! Congratulations!

Regex tips

Ruby regexes are similar to other languages. If you are not familiar with a regular expression, go read up on it, because you won't be able to develop a plugin without that knowledge.

To specify a capture group:

listen_for /siri proxy word ([a-z]*)/i do |word|

To specify multiple capture groups (test this by saying "siri proxy word hello number three"):

listen_for /siri proxy word ([a-z]*) number ([a-z]*)/i do |word, number|

SUPER IMPORTANT NOTE: Why did we make "number" a letter group instead of digits? It's because nothing magic happens when you say a number. Siri will interpret you saying "three" as the word "three". The exception to this is if you say a string of numbers like "four five six" Siri will interpret that as "456".

To specify optional words:

listen_for /how do I get to(?: the)? store/i do

There are two important things in the above statement. First, the ?: in the group means it will not capture, so you don't need to add a |capture| after the do. If you want to capture the optional word, remove the ?:. The second important thing is the space is IN the capture group. If you just did this:

listen_for /how do I get to (?:the)? store/i do

And you said "how do I get to store" to Siri, it wouldn't match, because the regex would be looking for two spaces, one before the group and one after. Tricky and stupid stuff!

Troubleshooting

If you get this when starting up Siri proxy:

rescue in block in initialize': Cannot start the server on port 443

Run this command to find out which programs are listening on port 443:

sudo lsof -i:443

Then get their PIDs (you probably only need to kill ruby) from the PID column and kill them with:

sudo kill -9 xxxx

Clone this wiki locally