Commits

Miki Tebeka committed 942ed57

twilio-response

  • Participants
  • Parent commits 475fc03

Comments (0)

Files changed (1)

File src/duderemember.clj

   (:gen-class :extends javax.servlet.http.HttpServlet)
   (:use appengine.datastore
         appengine.users 
+        clojure.contrib.prxml
         compojure.core
         hiccup.core
         hiccup.form-helpers
        (text-field :phone)
        (submit-button "Update"))))
 
+(defn twilio-response [& params]
+  (with-out-str (prxml [:Response params])))
+
 (defn twilio-sms [params]
   (let [phone (params "From")
         text (params "Body")
         user (phone->user phone)]
     (if user
       (do (add-sms user text)
-        "<Response />")
+        (twilio-response))
       ; Can't find user, SMS back how to register
-      "<Response>
-         <Sms>Unknown number, register at 
-              http://dude-remember.appspot.com
-         </Sms>
-      </Response>")))
+      (twilio-response [:Sms "Dude, I don't know you! "
+                            "Check out http://dude-remember.appspot.com"]))))
 
 (defn twilio-voice [params]
   (let [phone (params "From")
         user (phone->user phone)]
     (if (nil? user)
-      "<Response>
-        <Say voice=\"woman\">
-          Dude, I don't know you. Ciao!
-        </Say>
-        <Hangup />
-       </Response>"
+      (twilio-response [:Say {:voice "woman"} "Dude, I don't know you. Ciao!"]
+                      [:Hangup])
       (let [url (params "RecordingUrl")]
         (if (nil? url) ; New call
-          "<Response>
-            <Say voice=\"woman\">Talk to me babe.</Say>
-            <Record maxLength=\"30\" />
-           </Response>"
+          (twilio-response [:Say {:voice "woman"} "Talk to me babe!"]
+                          [:Record {:maxLength "30"}])
           (do (add-voice user url)
-            "<Response>
-              <Say voice=\"woman\">Gotcha! Later dude.</Say>
-              <Hangup />
-             </Response>"))))))
+            (twilio-response [:Say {:voice "woman"} "Gotcha! Later dude."]
+                            [:Hangup])))))))
 
 (defn welcome-page []
   (let [user (current-user)]