Dialogflow v1とv2のInline Editorを使った会話サンプル
10671 ワード
Dialogflowがv1 -> v2にバージョンアップしましたね。それにともない、FulfillmentのInline Editorの書き方が結構変わりました。ということで、v1とv2の会話サンプルを比較しつつまとめてみました。
v1とv2のInline Editorを使った会話サンプル
v1
'use strict';
process.env.DEBUG = 'actions-on-google:*';
const functions = require('firebase-functions');
const { DialogflowApp } = require('actions-on-google');
const actionMap = new Map();
// ユーザからの入力パラメータを利用しない場合
// 'input.welcome' -> IntentsのAction
actionMap.set('input.welcome', app => {
// 会話を継続させる場合
app.ask('How are you?');
// 会話を終了させる場合
app.tell('Thanks for talking to me!');
});
// ユーザからの入力パラメータを利用する場合
// 'input.make_name' -> IntentsのAction
actionMap.set('input.make_name', app => {
// color, num -> Intentsのparameters
const color = app.getArgument('color');
const num = app.getArgument('num');
// 会話を継続させる場合
app.ask('Alright, your silly name is ' +
color + ' ' + num +
'! Are there any other numbers and colors you like?');
// 会話を終了させる場合
app.tell('Alright, your silly name is ' +
color + ' ' + num +
'! I hope you like it. See you next time.');
});
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((req, res) => {
const app = new DialogflowApp({ request: req, response: res });
app.handleRequest(actionMap);
});
v2
'use strict';
process.env.DEBUG = 'actions-on-google:*';
const functions = require('firebase-functions');
const { dialogflow } = require('actions-on-google');
const app = dialogflow();
// ユーザからの入力パラメータを利用しない場合
// 'Default Welcome Intent' -> Intents
app.intent('Default Welcome Intent', conv => {
// 会話を継続させる場合
conv.ask('How are you?');
// 会話を終了させる場合
conv.close('Thanks for talking to me!');
});
// ユーザからの入力パラメータを利用する場合
// 'make_name' -> Intents
// color, num -> Intentsのparameters
app.intent('make_name', (conv, { color, num }) => {
// 会話を継続させる場合
conv.ask(`Alright, your silly name is ${color} ${num} ! Are there any other numbers and colors you like?`);
// 会話を終了させる場合
conv.close(`Alright, your silly name is ${color} ${num} ! I hope you like it. See you next time.`);
});
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);
まとめ
- v1よりv2の方がコードがすっきりしている
- 会話の単位
- v1:アクション単位
- v2:インテント単位
参考リンク
v1
'use strict';
process.env.DEBUG = 'actions-on-google:*';
const functions = require('firebase-functions');
const { DialogflowApp } = require('actions-on-google');
const actionMap = new Map();
// ユーザからの入力パラメータを利用しない場合
// 'input.welcome' -> IntentsのAction
actionMap.set('input.welcome', app => {
// 会話を継続させる場合
app.ask('How are you?');
// 会話を終了させる場合
app.tell('Thanks for talking to me!');
});
// ユーザからの入力パラメータを利用する場合
// 'input.make_name' -> IntentsのAction
actionMap.set('input.make_name', app => {
// color, num -> Intentsのparameters
const color = app.getArgument('color');
const num = app.getArgument('num');
// 会話を継続させる場合
app.ask('Alright, your silly name is ' +
color + ' ' + num +
'! Are there any other numbers and colors you like?');
// 会話を終了させる場合
app.tell('Alright, your silly name is ' +
color + ' ' + num +
'! I hope you like it. See you next time.');
});
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((req, res) => {
const app = new DialogflowApp({ request: req, response: res });
app.handleRequest(actionMap);
});
v2
'use strict';
process.env.DEBUG = 'actions-on-google:*';
const functions = require('firebase-functions');
const { dialogflow } = require('actions-on-google');
const app = dialogflow();
// ユーザからの入力パラメータを利用しない場合
// 'Default Welcome Intent' -> Intents
app.intent('Default Welcome Intent', conv => {
// 会話を継続させる場合
conv.ask('How are you?');
// 会話を終了させる場合
conv.close('Thanks for talking to me!');
});
// ユーザからの入力パラメータを利用する場合
// 'make_name' -> Intents
// color, num -> Intentsのparameters
app.intent('make_name', (conv, { color, num }) => {
// 会話を継続させる場合
conv.ask(`Alright, your silly name is ${color} ${num} ! Are there any other numbers and colors you like?`);
// 会話を終了させる場合
conv.close(`Alright, your silly name is ${color} ${num} ! I hope you like it. See you next time.`);
});
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);
- v1よりv2の方がコードがすっきりしている
- 会話の単位
- v1:アクション単位
- v2:インテント単位
参考リンク
Author And Source
この問題について(Dialogflow v1とv2のInline Editorを使った会話サンプル), 我々は、より多くの情報をここで見つけました https://qiita.com/donchan922/items/af814a61ce7368374a7d著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .