botframework有一個很好的地方,
就是你可以設定,
這串Dialog 預期收到的資料格式,
使用 Prompt來幫你做過瀘錯誤語的資料。
目前有支援六種資料格式
// Ask the user for their name and greet them by name.
bot.dialog('greetings', [
function (session) {
session.beginDialog('askName');
},
function (session, results) {
session.endDialog(`Hello ${results.response}!`);
}
]);
bot.dialog('askName', [
function (session) {
builder.Prompts.text(session, 'Hi! What is your name?');
},
function (session, results) {
session.endDialogWithResult(results);
}
]);
這樣就可以獲得你需要的資料格式了.
builder.Prompts.text(session, "What is your name?");
s.response //就是 回文
builder.Prompts.confirm(session, "Are you sure you wish to cancel your order?");
//s.response 只有會 true / false
builder.Prompts.number(session, "How many would you like to order?”);
//自動轉譯成數字 例如 nine 會變 9
builder.Prompts.time(s, "What time would you like to set an alarm for?”);
21:00 at today
{ type: 'chrono.duration',
entity: '21:00 at today',
startIndex: 0,
endIndex: 14,
resolution:
{ resolution_type: 'chrono.duration',
start: 2017-12-14T13:00:00.000Z,
ref: 2017-12-14T15:00:28.000Z },
score: 1 }
builder.Prompts.choice(session, "Which color?", ["red","green","blue"]);
//s.response { score: 1, index: 1, entity: 'green’ }
//也可以全部自已訂義
var salesData = {
"west": {
units: 200,
total: "$6,000"
},
"central": {
units: 100,
total: "$3,000"
},
"east": {
units: 300,
total: "$9,000"
}
};
bot.dialog('getSalesData', [
function (session) {
builder.Prompts.choice(session, "Which region would you like sales for?", salesData);
},
function (session, results) {
if (results.response) {
var region = salesData[results.response.entity];
session.send(`We sold ${region.units} units for a total of ${region.total}.`);
} else {
session.send("OK");
}
}
]);
builder.Prompts.attachment(session, "Upload a picture for me to transform.”);
//就是要傳檔案給它,line有傳地址的功能,也只能用這個實現