Last active
August 3, 2018 03:44
-
-
Save n0bisuke/7cdc5e57851ba934869d7536350037e7 to your computer and use it in GitHub Desktop.
Clova CEKの開発をNode.jsではじめてみるやつ。 カレースキル https://dotstud.io/blog/line-clova-skill-tutorial
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
'use strict'; | |
const clova = require('@line/clova-cek-sdk-nodejs'); | |
const express = require('express'); | |
const clovaSkillHandler = clova.Client | |
.configureSkill() | |
//起動時に喋る | |
.onLaunchRequest(responseHelper => { | |
responseHelper.setSimpleSpeech({ | |
lang: 'ja', | |
type: 'PlainText', | |
value: 'カレー屋さんを探します。', | |
}); | |
}) | |
//ユーザーからの発話が来たら反応する箇所 | |
.onIntentRequest(async responseHelper => { | |
const intent = responseHelper.getIntentName(); | |
const sessionId = responseHelper.getSessionId(); | |
console.log('Intent:' + intent); | |
if(intent === 'CurreySearchIntent'){ | |
const slots = responseHelper.getSlots(); | |
console.log(slots); | |
//デフォルトのスピーチ内容を記載 - 該当スロットがない場合をデフォルト設定 | |
let speech = { | |
lang: 'ja', | |
type: 'PlainText', | |
value: `まだ登録されていないエリアです。` | |
} | |
if(slots.area === '秋葉原'){ | |
speech.value = `${slots.area}のオススメのカレー屋は フジヤマドラゴンカレー です。`; | |
}else if(slots.area === '神保町'){ | |
speech.value = `${slots.area}のオススメのカレー屋は 共栄堂 です。`; | |
}else if(slots.area === '神田'){ | |
//神田のカレー情報検索 | |
//何か自分で書いてみましょう。 | |
} | |
responseHelper.setSimpleSpeech(speech); | |
responseHelper.setSimpleSpeech(speech, true); | |
} | |
}) | |
//終了時 | |
.onSessionEndedRequest(responseHelper => { | |
const sessionId = responseHelper.getSessionId(); | |
}) | |
.handle(); | |
const app = new express(); | |
const port = process.env.PORT || 3000; | |
//リクエストの検証を行う場合。環境変数APPLICATION_ID(値はClova Developer Center上で入力したExtension ID)が必須 | |
const clovaMiddleware = clova.Middleware({applicationId: 'YOUR_EXTENSION_ID'}); | |
app.post('/clova', clovaMiddleware, clovaSkillHandler); | |
app.listen(port, () => console.log(`Server running on ${port}`)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment