この Fulfillment の実態は Google Cloud Functions のようですが、左のナビゲーションの Fulfillment メニューで Inline Editor を On にすることで、 Dialogflow のコンソールから手軽に実装できます。
エディタに以下を記述します。
// index.js
'use strict';
// Import the Dialogflow module from the Actions on Google client library.
const {dialogflow} = require('actions-on-google');
// Import the firebase-functions package for deployment.
const functions = require('firebase-functions');
// Instantiate the Dialogflow client.
const app = dialogflow({debug: true});
// Import request module to call POST request to the Google Apps Script API.
const request = require('request');
// Handle the Dialogflow intent named 'poop condition' with parameters.
app.intent('poop condition', (conv, {condition, amount}) => {
// Google Apps Script API's URL.
const uri = "https://script.google.com/macros/s/<API endpoint>";
let options = {
uri: uri,
headers: {
"Content-type": "application/json",
},
json: {
"condition": condition,
"amount": amount
}
};
return new Promise((resolve, reject) => {
request.post(options, (err, res, body) => {
if (err) {
// Respond with an error message and end the conversation.
conv.close('エラーが発生しました。');
console.log("error: " + err);
resolve();
} else {
// Respond with the message and end the conversation.
conv.close(`わかりました。 ${condition}のうんちが${amount}ですね。`);
resolve();
}
});
});
});
// Set the DialogflowApp object to handle the HTTPS POST request.
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);
例えば、フラッシュカードの表でpensionを書いて、裏側年金と書きます。逆に表に年金を書いて、裏側にpensionを書くのです。語彙だけではなく、発音や文法もカードにしましょう。文法は自分が「English Grammar in Use」で間違った問題をそのままにします。あとはTOP-BOTTOMのカードです。例えば、表面に「あなたはレストランに食べ終わって店員さんにレシートをもらいたいときどう話す。」裏側に「Can I have the bill?」、一瞬で思い出すようにこのようにカードにします。