Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 38 lines (32 sloc) 1.019 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
require 'rubygems'
require 'sinatra'
require 'smsapp_models.rb'
require 'smsapp_apps.rb'

get '/' do
  load 'smsapp_models.rb'
  load 'smsapp_apps.rb'
  phone = params[:phoneno]
  message = params[:content]
  longcode = nil

  if phone.blank? || message.blank?
    halt "Go away!"
  end

  scanned_msg = message.scan(/(\w+) (.*)/)
  keyword = scanned_msg[0][0]
  app_message = scanned_msg[0][1]
  Smsapp::App_Logger.info "Will look for keyword #{keyword}"

  unless (kw = Keyword.find_by_name(keyword))
    halt "Unallocated keyword!"
  end
  app = Object::const_get(kw.smsapp.name).find(kw.smsapp_id)
  ph = Phone.new(phone)
  if ph.invalid?
    halt "Invalid phone number"
  else
    app.incoming(longcode, keyword, ph, app_message, Time.now.to_i)
  end
  "Successful"
end

#TODO: Need one or more dedicated long or short codes
#TODO: Need to set callback URLs on all the above codes such that the receiving code can be figured out
#TODO: Need an enterprise account with dynamic masking enabled and dndCheck disabled
Something went wrong with that request. Please try again.