我在这里定义了一个字典
var dict = {'English 101?': 'Room 205', 'English 102?': 'Room 309',
'Math 301': 'Room 705', 'Math 302': 'Room 704'};
当用户询问“英语 101 在哪里”时,我希望机器人回复“在 205 房间”。
我通过以下方式对其进行硬编码:
var builder = require('botbuilder');
var helloBot = new builder.TextBot();
var dialog = new builder.CommandDialog();
dialog.matches('^Where is English 101?', builder.DialogAction.send('In Room 205'));
dialog.matches('^Where is English 102?', builder.DialogAction.send('In Room 309'));
dialog.matches('^Where is Math 301?', builder.DialogAction.send('In Room 705'));
dialog.matches('^Where is Math 302?', builder.DialogAction.send('In Room 704'));
dialog.onDefault(builder.DialogAction.send("I'm sorry. I didn't understand."));
helloBot.listenStdin();
我不想对每个问题进行硬编码,而是将一些正则表达式传递给 dialog.matches() 函数的第一个参数并将其用作键,Bot 应该能够从字典中获取值并发送回用户
我尝试了以下方法,但没有奏效:
var str = ""
dialog.matches(str = ? , builder.DialogAction.send(dict[str.slice(9)]))
我怎样才能将标准输入传递给“str”并从字典中获取值?