Skip to content

Commit

Permalink
mail notifications when a 4S "renews" assistant id (CreateAssistant)
Browse files Browse the repository at this point in the history
  • Loading branch information
Filipe Pina committed Dec 30, 2011
1 parent 325e90f commit cc73355
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions config.example.yml
@@ -1,5 +1,12 @@
port: 443 port: 443
log_level: 1 log_level: 1

# Email notification - Send email notification when a 4S connects and creates a new session (Assistant)
#mail_from: from@host.com # required
#mail_to: to@host.com # required
#mail_subject: SiriProxy # defaults to SiriProxy
#mail_host: localhost # defaults to localhost

plugins: plugins:
# NOTE: run bundle after changing plugin configurations to update required gems # NOTE: run bundle after changing plugin configurations to update required gems


Expand Down
22 changes: 22 additions & 0 deletions lib/siriproxy/connection.rb
@@ -1,5 +1,6 @@
require 'cfpropertylist' require 'cfpropertylist'
require 'siriproxy/interpret_siri' require 'siriproxy/interpret_siri'
require 'net/smtp'


class SiriProxy::Connection < EventMachine::Connection class SiriProxy::Connection < EventMachine::Connection
include EventMachine::Protocols::LineText2 include EventMachine::Protocols::LineText2
Expand Down Expand Up @@ -217,6 +218,27 @@ def prep_received_object(object)
return nil return nil
end end


if @faux == false and object["class"] == "CreateAssistant"
from = $APP_CONFIG.mail_from
to = $APP_CONFIG.mail_to
subj = $APP_CONFIG.mail_subject
host = $APP_CONFIG.mail_host
host = "localhost" if host == nil
subj = "SiriProxy" if subj == nil
msg = <<END_OF_MESSAGE
From: #{from}
To: #{to}
Subject: #{subj}
A 4S just created a new assistant.
END_OF_MESSAGE
if from != nil and to != nil
Net::SMTP.start(host) do |smtp|
smtp.send_message msg, from, to
end
end
end

if @faux == true if @faux == true
if object["class"] == "CreateAssistant" if object["class"] == "CreateAssistant"
puts "[Warning] Non-4S devices cannot CreateAssistant. This device either requires proper initial configuration (refer to http://methoddk.com/siriguide/ Step 3) or the cached session expired and a new 4S needs to connect." puts "[Warning] Non-4S devices cannot CreateAssistant. This device either requires proper initial configuration (refer to http://methoddk.com/siriguide/ Step 3) or the cached session expired and a new 4S needs to connect."
Expand Down

0 comments on commit cc73355

Please sign in to comment.