Permalink
Browse files

mail notifications when a 4S "renews" assistant id (CreateAssistant)

  • Loading branch information...
1 parent 325e90f commit cc7335578f96c5fa3b7124bc3b878a23243433aa Filipe Pina committed Dec 30, 2011
Showing with 29 additions and 0 deletions.
  1. +7 −0 config.example.yml
  2. +22 −0 lib/siriproxy/connection.rb
View
@@ -1,5 +1,12 @@
port: 443
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:
# NOTE: run bundle after changing plugin configurations to update required gems
@@ -1,5 +1,6 @@
require 'cfpropertylist'
require 'siriproxy/interpret_siri'
+require 'net/smtp'
class SiriProxy::Connection < EventMachine::Connection
include EventMachine::Protocols::LineText2
@@ -217,6 +218,27 @@ def prep_received_object(object)
return nil
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 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."

0 comments on commit cc73355

Please sign in to comment.