Advertisement
Guest User

Untitled

a guest
Feb 11th, 2017
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.74 KB | None | 0 0
  1. var personen = {
  2. "Heiko" : {
  3. "persönlichkeit": "Triggered gerne andere",
  4. "skill": "Kann gut lol Spielen"
  5. },
  6. "Dominik" : {
  7. "persönlichkeit": "Ist komisch",
  8. "skill": "ERROR: Skill.exe not found"
  9. },
  10. }
  11.  
  12. exports.handler = function (event, context) {
  13.  
  14. try {
  15. console.log("event.session.application.applicationId=" + event.session.application.applicationId);
  16.  
  17. if(event.session.new){
  18. onSessionStarted({requestId: event.request.requestId}, event.session);
  19. }
  20.  
  21. if (event.request.type === "LaunchRequest") {
  22. onLaunch(event.request,
  23. event.session,
  24. function callback(sessionAttributes, speechletResponse) {
  25. context.succeed(buildResponse(sessionAttributes, speechletResponse));
  26. });
  27.  
  28. } else if (event.request.type === "IntenRequest") {
  29. onIntent(event.request,
  30. event.session,
  31. function callback(sessionAttributes, speechletResponse) {
  32. context.succeed(buildResponse(sessionAttributes, speechletResponse));
  33. });
  34. } else if (event.request.type === "SessionEndedRequest") {
  35. onSessionEnded(event.request, event.session);
  36. context.succeed();
  37. }
  38.  
  39. } catch (e) {
  40. context.fail("Exception: " + e);
  41. }
  42. };
  43.  
  44. function onSessionStarted(sessionStartedRequest, session){
  45.  
  46. }
  47.  
  48. function onLaunch(launchRequest, session, callback) {
  49. getWelcomeResponce(callback)
  50. }
  51.  
  52. function onIntent (intentRequest, session, callback) {
  53.  
  54. var intent = intentRequest.intent
  55. var intentName = intentRequest.intent.name;
  56.  
  57. if(intentName == "TestIntent") {
  58. handleTestResponse(intent, session, callback)
  59.  
  60. } else if (intentName == AMAZON.YesIntent) {
  61. handleYesResponce(intent, session, callback)
  62.  
  63. } else if (intentName == AMAZON.NoIntent) {
  64. handleNoResponce(intent, session, callback)
  65.  
  66. } else if (intentName == AMAZON.HelpIntent) {
  67. handleGetHelpRequest(intent, session, callback)
  68.  
  69. } else if (intentName == AMAZON.StopIntent) {
  70. handleFinishSessionRequest(intent, session, callback)
  71.  
  72. } else if (intentName == AMAZON.CancelIntent) {
  73. handleFinishSessionRequest(intent, session, callback)
  74.  
  75. }else {
  76. throw "Invalid intent"
  77. }
  78.  
  79. }
  80.  
  81. function onSessionEnded(sessionEndedRequest, session) {
  82.  
  83. }
  84.  
  85. function getWelcomeResponce(callback) {
  86. var speechOutput = "Jo digga was geht?" + "Willst du etwas über Heiko oder Dominik erfahren?"
  87.  
  88. var reprompt = "Alter, was ist das nur für 1 Life entscheide dich mal!"
  89.  
  90. var header = "Random Infos"
  91.  
  92. var shouldEndSession = false
  93.  
  94. var sessionAttributes = {
  95. "speechOutput" : speechOutput,
  96. "reprompt" : reprompt
  97. }
  98. callback(sessionAttributes, buildSpeechletResponse(header, speechOutput, reprompt, shouldEndSession))
  99. }
  100.  
  101.  
  102. function handleTestResponse(intent, session, callback) {
  103.  
  104. var person = intent.slots.Test.value.toLowerCase()
  105.  
  106. if(!personen[person]) {
  107. var speechOutput = "Alter, das Ist keine verfügbare Möglichkeit du noob"
  108. var repromptText = "Versuch halt mal was anderes wie z.B Heiko oder Dominik"
  109. var header = "Nicht Verfügbar"
  110. } else {
  111. var persönlichkeit = personen[person].persönlichkeit
  112. var skill = personen[person].skill
  113. var speechOutput = capitalizeFirst(person) + " " + persönlichkeit + " und " + skill + ". Willst noch was anderes Wissen?"
  114. var repromptText = "Willst noch was anderes Wissen?"
  115. var header = capitalizeFirst(person)
  116. }
  117.  
  118. var shouldEndSession = false;
  119.  
  120. callback(session.attributes, buildSpeechletResponse(header, speechOutput, repromptText, shouldEndSession))
  121. }
  122.  
  123. function handleYesResponce(intent, session, callback) {
  124.  
  125. var speechOutput = "Ok über wen willst du etwas erfahren? Es gibt Heiko und Dominik"
  126. var repromptText = speechOutput
  127. var shouldEndSession = false
  128.  
  129. callback(session.attributes , buildSpeechletResponseWithoutCard(speechOutput,repromptText,shouldEndSession))
  130.  
  131. }
  132.  
  133. function handleNoResponce(intent, session, callback) {
  134.  
  135. handleFinishSessionRequest(intent,session,callback)
  136.  
  137. }
  138.  
  139. function handleGetHelpRequest(intent, session, callback) {
  140.  
  141. if(!session.attributes) {
  142. session.attributes = {};
  143. }
  144.  
  145. var speechOutput = "Ich kann die alles über diese Personen sagen: Heiko, Dominik"
  146. var repromptText = speechOutput
  147. var shouldEndSession = false;
  148.  
  149. callback(session.attributes,buildSpeechletResponseWithoutCard(speechOutput, repromptText, shouldEndSession))
  150.  
  151. }
  152.  
  153. function handleFinishSessionRequest(intent, session, callback) {
  154.  
  155. callback(session.attributes,
  156. buildSpeechletResponseWithoutCard("Tschau du Lappen","Bis bald",true));
  157.  
  158. }
  159.  
  160. // ------- Helper functions to build responses for Alexa -------
  161. function buildSpeechletResponse(title, output, repromptText, shouldEndSession) {
  162. return {
  163. outputSpeech: {
  164. type: "PlainText",
  165. text: output
  166. },
  167. card: {
  168. type: "Simple",
  169. title: title,
  170. content: output
  171. },
  172. reprompt: {
  173. outputSpeech: {
  174. type: "PlainText",
  175. text: repromptText
  176. }
  177. },
  178. shouldEndSession: shouldEndSession
  179. };
  180. }
  181.  
  182. function buildSpeechletResponseWithoutCard(output, repromptText, shouldEndSession) {
  183. return {
  184. outputSpeech: {
  185. type: "PlainText",
  186. text: output
  187. },
  188. reprompt: {
  189. outputSpeech: {
  190. type: "PlainText",
  191. text: repromptText
  192. }
  193. },
  194. shouldEndSession: shouldEndSession
  195. };
  196. }
  197.  
  198. function buildResponse(sessionAttributes, speechletResponse) {
  199. return {
  200. version: "1.0",
  201. sessionAttributes: sessionAttributes,
  202. response: speechletResponse
  203. };
  204. }
  205.  
  206. function capitalizeFirst (s) {
  207.  
  208. return s.charST(0).toUpperCase() + s.slice(1)
  209. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement