Permalink
Browse files

added sms support

  • Loading branch information...
1 parent 5008361 commit ae81c8dbbe22365ba497425ac58f7a4984a8fddf @bigfolio committed Jul 8, 2009
View
7 app/controllers/messages_controller.rb
@@ -53,6 +53,13 @@ def create
if current_user
@ticket.close! if params[:close_ticket]
format.html { redirect_to(@ticket) }
+
+ # Send a text message to the customer
+ # This should really be done in the model, but sms-fu doesn't seem to like that
+ url = view_by_key_url(@ticket.key, :host => 'bighelp.bigfolio.com')
+ deliver_sms(@ticket.mobile_number.gsub(/[^0-9]/,""), @ticket.carrier_name, "We have an update to your support request (#{@ticket.key}). Please visit #{url}") unless @ticket.mobile_number.blank?
+
+
else
format.html { redirect_to(view_by_key_url(@ticket.key)) }
end
View
6 app/controllers/tickets_controller.rb
@@ -4,6 +4,7 @@ class TicketsController < ApplicationController
before_filter :login_required, :except => [:new, :create]
has_mobile_fu
+ has_sms_fu
# GET /tickets
# GET /tickets.xml
@@ -88,6 +89,11 @@ def create
flash[:notice] = 'Ticket was successfully created.'
format.html { redirect_to(view_by_key_url(@ticket.key)) }
format.xml { render :xml => @ticket, :status => :created, :location => @ticket }
+
+ # Send a text message
+ deliver_sms(@ticket.mobile_number.gsub(/[^0-9]/,""), @ticket.carrier_name, "Your support ticket has been received.") unless @ticket.mobile_number.blank?
+
+
else
format.html { render :action => "new" }
format.xml { render :xml => @ticket.errors, :status => :unprocessable_entity }
View
9 app/models/ticket.rb
@@ -1,4 +1,6 @@
class Ticket < ActiveRecord::Base
+
+
belongs_to :category
belongs_to :user
@@ -11,6 +13,7 @@ class Ticket < ActiveRecord::Base
state :closed
before_create :generate_key
+ after_create :strip_mobile
after_create :send_alerts
event :research do
@@ -36,12 +39,16 @@ def classes
protected
+ def strip_mobile
+ self.mobile_number.gsub!(/[^0-9]/,"") unless self.mobile_number.blank?
+ self.save
+ end
+
def send_alerts
users = User.find(:all)
users.each { |u| TicketMailer.deliver_ticket_alert(u, self) if u.categories.include?(self.category) }
TicketMailer.deliver_ticket_confirmation(self)
-
end
def generate_key
View
5 app/views/tickets/new.html.erb
@@ -22,6 +22,11 @@
<%= f.label :domain, "Domain name" %><br />
<%= f.text_field :domain %>
</p>
+ <p>
+ <%= f.label :mobile_number, "Mobile phone" %><br />
+ <%= f.text_field :mobile_number %>
+ </p>
+ <p><%= carrier_select('ticket[carrier_name]', "Please choose your carrier") %></p>
</fieldset>
View
9 db/migrate/20090708221732_add_mobile_info_to_tickets.rb
@@ -0,0 +1,9 @@
+class AddMobileInfoToTickets < ActiveRecord::Migration
+ def self.up
+ add_column :tickets, :mobile_number, :string
+ add_column :tickets, :carrier_name, :string
+ end
+
+ def self.down
+ end
+end
View
10 db/schema.rb
@@ -9,12 +9,13 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20090221212303) do
+ActiveRecord::Schema.define(:version => 20090708221732) do
create_table "categories", :force => true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
+ t.string "help_url", :default => "http://www.bigfolio.com/help"
end
create_table "faqs", :force => true do |t|
@@ -56,6 +57,8 @@
t.string "os"
t.string "email_client"
t.string "browser"
+ t.string "mobile_number"
+ t.string "carrier_name"
end
create_table "user_notifications", :id => false, :force => true do |t|
@@ -75,6 +78,11 @@
t.datetime "updated_at"
t.string "remember_token", :limit => 40
t.datetime "remember_token_expires_at"
+ t.datetime "avatar_updated_at"
+ t.string "avatar_file_name"
+ t.string "avatar_content_type"
+ t.integer "avatar_file_size"
+ t.datetime "avatar_uploaded_at"
end
add_index "users", ["login"], :name => "index_users_on_login", :unique => true
1 vendor/plugins/sms_fu
@@ -0,0 +1 @@
+Subproject commit 899050db2a8877fe508738811c121247571aaea2

0 comments on commit ae81c8d

Please sign in to comment.