Skip to content

Instantly share code, notes, and snippets.

Avatar

Matt Steen neetso

  • London
View GitHub Profile
@neetso
neetso / tinyurl.rb
Created Nov 26, 2016 — forked from woods/tinyurl.rb
A complete URL-shortening web application, written in Ruby/Sinatra.
View tinyurl.rb
#!/usr/bin/env ruby
#
# A complete URL-shortening web application, written in Ruby/Sinatra. Run it
# from the command line, and then visit http://localhost:4567/
#
# Or to run it under apache/passenger, you'll need a config.ru file with the
# following contents:
#
# require 'tinyurl'
# run Sinatra::Application
View web.rb
post '/answer' do
user = params[:user]
if user == "voicemail"
notifier.ping "Call from: " + $redis.hget("call:#{params[:callId]}","from") + ". Hotline off.",
attachments: [call_details]
end
end
post '/hangup' do
hangupCause = "#{params[:cause]}"
View web.rb
post '/' do
phonenumber = params[:from]
$redis.hset("call:#{params[:callId]}","from",phonenumber[0...-3]+'XXX')
headers 'Content-Type' => "application/xml"
xml = Builder::XmlMarkup.new(:indent => 2)
xml.instruct!
xml.Response("onAnswer" => settings.responseUrl + "answer",
"onHangup" => settings.responseUrl + "hangup")
end
View web.rb
require 'slack-notifier'
require 'sinatra'
require 'builder'
require 'redis'
notifier = Slack::Notifier.new "https://hooks.slack.com/services/XXXXXXX/XXXXXXX/XXXXXXX"
call_details = {
fallback: "Call Details in the team <https://secure.live.sipgate.co.uk/|event list>.",
text: "Call Details in the team <https://secure.live.sipgate.co.uk/|event list>.",
You can’t perform that action at this time.