Last active
April 7, 2017 23:52
-
-
Save jreighley/b6d394d0efa743292bf32d776be97682 to your computer and use it in GitHub Desktop.
Simple starter for Clojurescript AWS lambda app.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;This is untested off the top of my head -- but should give you the gist.. | |
;; use https://github.com/nervous-systems/cljs-lambda as a starter -- follow their lein build steps and then replace their core with something like this. | |
(ns alexalisten.core | |
(:require [cljs-lambda.util :as lambda] | |
[cljs-lambda.context :as ctx] | |
[cljs-lambda.macros :refer-macros [deflambda]])) | |
(deflambda alexa-listen [inputjson] | |
(let [jsonstring (js->clj inputjson) | |
sessionid (-> jsonstring :session :sessionId) | |
applicationid (-> jsonstring :session :application :applicationId) | |
userid (-> jsonstring :session :user :userId) | |
reqtype (-> jsonstring :request :type) | |
sessionstate (-> jsonstring :session :attributes) | |
targetfunc (-> jsonstring :request :intent :name) | |
slotval (-> jsonstring :request :intent :slots :<slotname> :value) | |
version (:version jsonstring) | |
timestamp (-> jsonstring :request :timestamp) | |
;;now you can dispatch based on reqtype, sessionstate and slotval | |
response (cond | |
(= reqtype "LaunchRequest") (dayfunc) | |
(= targetfunc "GetDay") (dayfunc) | |
(= targetfunc "GetHelp") (helpfunc))])) | |
;;Your functions should return something like this: | |
{:version 1.0 :sessionAttributes (:state "Whateveryouwanaremember") :response {:outputSpeech {:type "PlainText" :text (str response) ) }:shouldEndSession false}}) | |
;;where response is what you want Alexa to say. | |
;;you are emulating the json response here : https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/alexa-skills-kit-interface-reference |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment