Commits

Miki Tebeka  committed 9de7ae0

Reading news with voice

  • Participants
  • Parent commits 9535712

Comments (0)

Files changed (1)

File src/tropo.clj

      [:h1 *title*]
      content]))
 
+(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 *index* (ref 0))
 
-(defn tropo-resonse [& params]
-  (json-str {:tropo [{:say [{:value "OMG, it works!"}]} {:hangup nil}]}))
+(def *on* {
+      :on (vec (for [event ["continue" "error" "hangup" "incomplete"]]
+                 {:event event :next "/tropo/voice"}))})
 
-(defn tropo-sms [params]
-  (log/info (str "SMS: " params))
-  (tropo-resonse))
+(defn ask [title]
+  {:ask {
+         :choices { :value "next, read" }
+         :bargein true
+         :timeout 1.0
+         :say [{:value title :voice "kate"}]}})
+
+(defn tropo-response [& params]
+  {:tropo params})
+
+(defn tropo-reply [params]
+  (if (< @*index* (count *titles*))
+    (let [title (*titles* @*index*)]
+      (dosync (alter *index* inc))
+      (tropo-response *on* (ask title)))
+    (do 
+      (dosync (alter *index* (fn [_] 0)))
+      (tropo-response {:say [{:value "That's all dude" :voice "kate"}]}
+                      {:hangup nil}))))
 
 (defn tropo-voice [params]
   (log/info (str "VOICE: " params))
-  (tropo-resonse))
+  (json-str (tropo-reply params)))
 
 (defn welcome-page []
   (page "Playing with Tropo"))
 
 (defn parse-tropo [body]
-  (:session (read-json (reader body))))
+  (let [json (read-json (reader body))]
+    (merge (:session json) (:result json))))
 
 (defroutes tropo-routes
   (GET "/" [] (welcome-page))
 
-  (POST "/tropo/sms" {params :params} (tropo-sms params))
   (POST "/tropo/voice" {body :body} (tropo-voice (parse-tropo body)))
 
 ; Uncomment these when debugging, *don't* let them slip to production