Skip to content

Instantly share code, notes, and snippets.

@monoxgas
Forked from laxman01/siriproxy-nick.rb
Created December 10, 2011 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monoxgas/1456063 to your computer and use it in GitHub Desktop.
Save monoxgas/1456063 to your computer and use it in GitHub Desktop.
siriproxy-nick.rb
require 'cora'
require 'siri_objects'
require 'pp'
class SiriProxy::Plugin::Nick < SiriProxy::Plugin
def initialize(config)
#if you have custom configuration options, process them here!
end
#get the user's location and display it in the logs
#filters are still in their early stages. Their interface may be modified
filter "SetRequestOrigin", direction: :from_iphone do |object|
puts "[Info - User Location] lat: #{object["properties"]["latitude"]}, long: #{object["properties"]["longitude"]}"
#
end
listen_for /say (.+)/i do |word|
`say "#{word}"`
request_completed #always complete your request! Otherwise the phone will "spin" at the user!
end
#Demonstrate that you can have Siri say one thing and write another"!
listen_for /you don't say/i do
say "Sometimes I don't write what I say", spoken: "Sometimes I don't say what I write"
end
#demonstrate state change
listen_for /siri proxy test state/i do
set_state :some_state #set a state... this is useful when you want to change how you respond after certain conditions are met!
say "I set the state, try saying 'confirm state change'"
request_completed #always complete your request! Otherwise the phone will "spin" at the user!
end
listen_for /confirm state change/i, within_state: :some_state do #this only gets processed if you're within the :some_state state!
say "State change works fine!"
set_state nil #clear out the state!
request_completed #always complete your request! Otherwise the phone will "spin" at the user!
end
#demonstrate asking a question
listen_for /siri proxy test question/i do
response = ask "Is this thing working?" #ask the user for something
if(response =~ /yes/i) #process their response
say "Great!"
else
say "You could have just said 'yes'!"
end
request_completed #always complete your request! Otherwise the phone will "spin" at the user!
end
#demonstrate capturing data from the user (e.x. "Siri proxy number 15")
listen_for /siri proxy number ([0-9,]*[0-9])/i do |number|
say "Detected number: #{number}"
request_completed #always complete your request! Otherwise the phone will "spin" at the user!
end
#demonstrate injection of more complex objects without shortcut methods.
listen_for /test map/i do
add_views = SiriAddViews.new
add_views.make_root(last_ref_id)
map_snippet = SiriMapItemSnippet.new
map_snippet.items << SiriMapItem.new
utterance = SiriAssistantUtteranceView.new("Testing map injection!")
add_views.views << utterance
add_views.views << map_snippet
#you can also do "send_object object, target: :guzzoni" in order to send an object to guzzoni
send_object add_views #send_object takes a hash or a SiriObject object
request_completed #always complete your request! Otherwise the phone will "spin" at the user!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment