Guest User

Untitled

a guest
Dec 16th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. const Obniz = require('obniz');
  2. const express = require('@runkit/runkit/express-endpoint/1.0.0');
  3. const clova = require('@line/clova-cek-sdk-nodejs');
  4. const app = express(exports);
  5.  
  6. const clovaExtensionId = 'jp.makeitfun.XXXXXXXX';
  7. const myObnizId = 'XXXX-XXXX';
  8.  
  9. async function showAnswer(qq) {
  10. let obniz = new Obniz(myObnizId);
  11. let connected = await obniz.connectWait({timeout:10});
  12. if(connected){
  13. obniz.display.clear();
  14. // obniz.display.print(qq.question)  // node.jsから全角文字は描画できないよう
  15. obniz.display.print(qq.formula)
  16. obniz.display.print(" = ")
  17. obniz.display.print(qq.answer)
  18. }
  19.  
  20. }
  21.  
  22. const data = {
  23. "1" : {
  24. "1" : {
  25. question : "いん いち が",
  26. answer : "1",
  27. formula : "1 * 1"
  28. },
  29. "2" : {
  30. question : "いん に が",
  31. answer : "2",
  32. formula : "1 * 2"
  33. },
  34. "3" : {
  35. question : "いん さん が",
  36. answer : "3",
  37. formula : "1 * 3"
  38. },
  39. "4" : {
  40. question : "いん し が",
  41. answer : "4",
  42. formula : "1 * 4"
  43. },
  44. "5" : {
  45. question : "いん ご が",
  46. answer : "5",
  47. formula : "1 * 5"
  48. },
  49. "6" : {
  50. question : "いん ろく が",
  51. answer : "6",
  52. formula : "1 * 6"
  53. },
  54. "7" : {
  55. question : "いん しち が",
  56. answer : "7",
  57. formula : "1 * 7"
  58. },
  59. "8" : {
  60. question : "いん はち が",
  61. answer : "8",
  62. formula : "1 * 8"
  63. },
  64. "9" : {
  65. question : "いん く が",
  66. answer : "9",
  67. formula : "1 * 9"
  68. }
  69. },
  70. .
  71. .
  72. .
  73. .
  74. .
  75. .
  76. }
  77.  
  78. const clovaSkillHandler = clova.Client.configureSkill()
  79.  
  80. //アプリ起動時の応答
  81. .onLaunchRequest(responseHelper => {
  82. responseHelper.setSimpleSpeech({
  83. lang: 'ja',
  84. type: 'PlainText',
  85. value: `復習したい九九の段をおしえてください。`,
  86. });
  87. })
  88.  
  89. //各インテントごとの対応
  90. .onIntentRequest(async responseHelper => {
  91. const intent = responseHelper.getIntentName();
  92.  
  93. if (intent === 'danIntent') {
  94. let slots = responseHelper.getSlots();
  95.  
  96. let dan = slots.dan_slot;
  97. var qq = "";
  98. if (dan == "1"){
  99.  
  100. qq = data[dan][String(Math.floor( Math.random() * 9 ))];
  101.  
  102. }else if (dan == "2"){
  103.  
  104. .
  105. .
  106. .
  107. .
  108.  
  109. }
  110.  
  111. //応答する
  112. responseHelper.setSimpleSpeech({
  113. lang: 'ja',
  114. type: 'PlainText',
  115. value: `いまから問題を出します。答えがわかったら画面をみてね。それでは、問題です。${qq.question}`,
  116. },true);
  117.  
  118. await showAnswer(qq);
  119.  
  120.  
  121. } else if (intent === 'Clova.GuideIntent') {
  122. responseHelper.setSimpleSpeech({
  123. lang: 'ja',
  124. type: 'PlainText',
  125. value: `復習したい九九の段をおしえてください。`,
  126. });
  127. } else {
  128. responseHelper.setSimpleSpeech({
  129. lang: 'ja',
  130. type: 'PlainText',
  131. value: `復習したい九九の段をおしえてください。`,
  132. });
  133. }
  134. })
  135. .onSessionEndedRequest(responseHelper => {})
  136. .handle();
  137.  
  138. const clovaMiddleware = clova.Middleware({
  139. applicationId: clovaExtensionId,
  140. });
  141.  
  142. app.post('/', clovaMiddleware, clovaSkillHandler);
Add Comment
Please, Sign In to add comment