Back to Parent

require 'sinatra'
require "sinatra/reloader" if development?

require 'dotenv'
Dotenv.load

require 'twilio-ruby'
enable :sessions

# create a twilio client using your account info
@client = Twilio::REST::Client.new ENV["TWILIO_ACCOUNT_SID"], ENV["TWILIO_AUTH_TOKEN"]
get "/sms/incoming" do
    session["last_intent"] ||= nil

    session["counter"] ||= 1
    count = session["counter"]

    sender = params[:From] || ""
    body = params[:Body] || ""
    body = body.downcase.strip

    if session["counter"] == 1
      message = "Hi. Please type one of the following to know more about me. Type 'Name', 'Age', 'Education', 'Favorite color', 'Favorite food'"
      media = "https://media.giphy.com/media/l2YWFGWKH3b32bEIg/giphy.gif"
  end

    if body == "Name"
    message = "Sarthak Giri"
  end

  if body == "Age"
    message = "27"
end

  if body == "education"
    message = "Masters of Integrated Innovation in Product and Services"
end

if body == "favorite color"
    message = "blue"
end

  if body == "favorite food"
      message = "Dal bhat"
    end

    session["counter"] += 1

    twiml = Twilio::TwiML::MessagingResponse.new do |r|
      r.message do |m|
        m.body( message )
        unless media.nil?
          m.media( media )
        end
      end
    end
    #3

    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!

0