Commits

Miki Tebeka committed e6cfaae

Start of slashvoice

  • Participants
  • Parent commits 2aef265

Comments (0)

Files changed (3)

+syntax: glob
+
+slashvoice/lib
+slashvoice/classes

File slashvoice/project.clj

+(defproject slashvoice "1.0.0-SNAPSHOT"
+  :description "Call to hear slashdot"
+  :dependencies [[org.clojure/clojure "1.2.0"]
+                 [org.clojure/clojure-contrib "1.2.0"]
+                 [ring "0.3.5"]
+                 [compojure "0.5.3"]]
+  :keep-non-project-classes true
+  :main slashvoice)

File slashvoice/src/slashvoice.clj

+(ns slashvoice
+  (:use [clojure.contrib.json :only (json-str read-json)]
+        [clojure.java.io :only [reader]]
+        compojure.core
+        hiccup.core
+        ring.adapter.jetty
+        ring.util.response)
+  (:require [compojure.route :as route]
+            [clojure.contrib.logging :as log])
+  (:import java.util.UUID))
+
+(def *titles* [
+  "Bread and Circuses: The State of Web App Startups"
+  "MongoDB's lead developer: Foursquare outage post mortem"
+  "IE6 effect in HTML5"
+  "Microsoft Buying Adobe?"
+  "Caught Spying on Student, FBI Demands GPS Tracker Back"
+  "Dear Gap, I have your new logo."
+  "Who are North Korea’s 13 Twitter friends?"
+  "Costco - Food for a whole year - $799 Awesome"
+  "Microsoft announces NuPack, a new package manager for open source .NET librarie"
+  "Writer for iPad: First Reactions"
+  "The stock market as a single, very big piece of multithreaded software"
+  "How to be a freelance web developer, part 2"])
+
+(def *session* (atom {}))
+
+(def *on* {
+      :on (vec (for [event ["continue" "error" "hangup" "incomplete"]]
+                 {:event event :next "/tropo/voice"}))})
+
+(defn ask [title]
+  {:ask {
+         :choices { :value "next, read" }
+         :bargein true
+         :timeout 1.0
+         :say [{:value title :voice "kate"}]}})
+
+(defn tropo-response [& params]
+  (json-str {:tropo params}))
+
+(def *index* (atom 0))
+
+(defn tropo-reply [params session]
+  (let [index @*index*]
+    (swap! *index* inc)
+    (if (< index (count *titles*))
+      (tropo-response *on* (ask (*titles* index)))
+      (tropo-response {:say [{:value "That's all dude" :voice "kate"}]}
+                      {:hangup nil}))))
+
+(defn parse-request [request]
+  (let [json (read-json (reader (:body request)))]
+    (spit (str "call-" (UUID/randomUUID)) json)
+    (merge (:session json) (:result json))))
+
+(defn tropo-voice [request]
+  (log/info request)
+  (let [params (parse-request request)]
+    (tropo-reply params (:session request))))
+
+(defn welcome-page []
+  (html
+    [:head
+     [:title "Slashvoice"]]
+    [:body
+     [:h1 "Slashvoice"]
+     "Please call (310) 895-9444"]))
+	
+(defroutes tropo-routes
+  (GET "/" [] (welcome-page))
+  (POST "/tropo/voice" request (tropo-voice request))
+
+  (route/not-found "Dude! I can't find it."))
+
+(defn -main []
+  (run-jetty #'tropo-routes {:port 8080}))