Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Obniz = require('obniz');
- const express = require('@runkit/runkit/express-endpoint/1.0.0');
- const clova = require('@line/clova-cek-sdk-nodejs');
- const app = express(exports);
- const clovaExtensionId = 'jp.makeitfun.XXXXXXXX';
- const myObnizId = 'XXXX-XXXX';
- async function showAnswer(qq) {
- let obniz = new Obniz(myObnizId);
- let connected = await obniz.connectWait({timeout:10});
- if(connected){
- obniz.display.clear();
- // obniz.display.print(qq.question) // node.jsから全角文字は描画できないよう
- obniz.display.print(qq.formula)
- obniz.display.print(" = ")
- obniz.display.print(qq.answer)
- }
- }
- const data = {
- "1" : {
- "1" : {
- question : "いん いち が",
- answer : "1",
- formula : "1 * 1"
- },
- "2" : {
- question : "いん に が",
- answer : "2",
- formula : "1 * 2"
- },
- "3" : {
- question : "いん さん が",
- answer : "3",
- formula : "1 * 3"
- },
- "4" : {
- question : "いん し が",
- answer : "4",
- formula : "1 * 4"
- },
- "5" : {
- question : "いん ご が",
- answer : "5",
- formula : "1 * 5"
- },
- "6" : {
- question : "いん ろく が",
- answer : "6",
- formula : "1 * 6"
- },
- "7" : {
- question : "いん しち が",
- answer : "7",
- formula : "1 * 7"
- },
- "8" : {
- question : "いん はち が",
- answer : "8",
- formula : "1 * 8"
- },
- "9" : {
- question : "いん く が",
- answer : "9",
- formula : "1 * 9"
- }
- },
- .
- .
- .
- .
- .
- .
- }
- const clovaSkillHandler = clova.Client.configureSkill()
- //アプリ起動時の応答
- .onLaunchRequest(responseHelper => {
- responseHelper.setSimpleSpeech({
- lang: 'ja',
- type: 'PlainText',
- value: `復習したい九九の段をおしえてください。`,
- });
- })
- //各インテントごとの対応
- .onIntentRequest(async responseHelper => {
- const intent = responseHelper.getIntentName();
- if (intent === 'danIntent') {
- let slots = responseHelper.getSlots();
- let dan = slots.dan_slot;
- var qq = "";
- if (dan == "1"){
- qq = data[dan][String(Math.floor( Math.random() * 9 ))];
- }else if (dan == "2"){
- .
- .
- .
- .
- }
- //応答する
- responseHelper.setSimpleSpeech({
- lang: 'ja',
- type: 'PlainText',
- value: `いまから問題を出します。答えがわかったら画面をみてね。それでは、問題です。${qq.question}`,
- },true);
- await showAnswer(qq);
- } else if (intent === 'Clova.GuideIntent') {
- responseHelper.setSimpleSpeech({
- lang: 'ja',
- type: 'PlainText',
- value: `復習したい九九の段をおしえてください。`,
- });
- } else {
- responseHelper.setSimpleSpeech({
- lang: 'ja',
- type: 'PlainText',
- value: `復習したい九九の段をおしえてください。`,
- });
- }
- })
- .onSessionEndedRequest(responseHelper => {})
- .handle();
- const clovaMiddleware = clova.Middleware({
- applicationId: clovaExtensionId,
- });
- app.post('/', clovaMiddleware, clovaSkillHandler);
Add Comment
Please, Sign In to add comment