require 'sinatra'
require "sinatra/reloader" if development?
require 'twilio-ruby'
enable :sessions
configure :development do
require 'dotenv'
Dotenv.load
end
# create a twilio client using your account info
@client = Twilio::REST::Client.new ENV["TWILIO_ACCOUNT_SID"], ENV["TWILIO_AUTH_TOKEN"]
get "/" do
404
end
get "/sms/incoming" do
body = params[:Body] || ""
body = body.downcase.strip
message = ""
media = nil
#Greeting & Intro & Tell what I do
GREETINGS = ["Hi,", "Hey,", "Ni Hao,", "Hej,", "Aloha,", "Hello,", "Hola,", "Nei Hou,"]
INTROS = ["I'm Yang's MeBot.", "You're talking to Yang's MeBot.", "I manage Yang's schedule."]
COMMANDS_OPTIONS = ["Ask me Yang's schedule by typing 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'.", "Ask me 'Monday', 'Tuesday' etc. to see Yang's schedule at CMU."]
APOLOGIES = ["I didn't catch that.", "Hmmm I don't know that.", "What did you say to me?"]
CASUAL_INTENTS = ["hi", "hello", "hey", "ni hao", "hej", "hola", "nei hou", "aloha"]
#Get yang's schedule
MONDAY_WEDNESDAY_SCHEDULE = ["Yang will be at studio in the morning. She has 'Business Fundamental' class in the afternoon and 'Design for Manufacturing' class in the evening", "Yang doesn't have class in the morning, she goes to 'Business Fundamental' class in the afternoon, and 'Design for Manufacturing' class in the evening."]
TUESDAY_THURSDAY_SCHEDULE = ["In the morning, she has 'IPD Method' class. In the afternoon, she has 'Programming for Online Prototype' class and 'Engineering Design Fundamental' class.", "That will be a busy day for her, she has 'IPD Methods' in the morning, 'Programming for Online Prototype' in the afternoon followed by 'Engineering Design Fundamental'."]
FRIDAY_SCHEDULE = ["Yang goes to 'Career Planning' class and 'Institute Seminar' in the morning. In the afternoon, she is free."]
WEEKEND_SCHEDULE = ["She needs some sleep.", "Yang probably will be working in the studio.", "She is alway from this planet that day.", "Yang loves to work on her secret projects during weekend.", "She would love to stay in bed on that day."]
TREAT_FOR_YANG_WEEKDAY = ["It a busy day, she would love some one buy her a coffee.", "Try to meet her at her studio."]
def get_greeting
GREETINGS.sample + " " + " Yang is busy studying at CMU." + " " + INTROS.sample
end
def get_misunderstanding
APOLOGIES.sample + " " + COMMANDS_OPTIONS.sample
end
session[:counter] ||=1
message = get_greeting + " " + COMMANDS_OPTIONS.sample
session[:counter] +=1
if session[:counter] > 1 and body == "monday"
message = MONDAY_WEDNESDAY_SCHEDULE.sample + TREAT_FOR_YANG_WEEKDAY.sample
session[:counter] +=1
elsif session[:counter] > 1 and body == "wednesday"
message = MONDAY_WEDNESDAY_SCHEDULE.sample + TREAT_FOR_YANG_WEEKDAY.sample
session[:counter] +=1
elsif session[:counter] > 1 and body == "tuesday"
message = TUESDAY_THURSDAY_SCHEDULE.sample + TREAT_FOR_YANG_WEEKDAY.sample
session[:counter] +=1
elsif session[:counter] > 1 and body == "thursday"
message = TUESDAY_THURSDAY_SCHEDULE.sample + TREAT_FOR_YANG_WEEKDAY.sample
session[:counter] +=1
elsif session[:counter] > 1 and body == "friday"
message = FRIDAY_SCHEDULE.sample + TREAT_FOR_YANG_WEEKDAY.sample
session[:counter] +=1
elsif session[:counter] > 1 and body == "saturday"
message = WEEKEND_SCHEDULE.sample
session[:counter] +=1
elsif session[:counter] > 1 and body == "sunday"
message = WEEKEND_SCHEDULE.sample
session[:counter] +=1
else
message = get_misunderstanding
session[:counter] +=1
end
#End the conversation or start another inquiry
twiml = Twilio::TwiML::MessagingResponse.new do |r|
r.message do |m|
m.body( message )
unless media.nil?
m.media( media )
end
end
end
content_type 'text/xml'
twiml.to_s
end
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .