Json 使用Prompts.choice中的变量的Microsoft Bot框架
我当前询问是/否问题的代码是Json 使用Prompts.choice中的变量的Microsoft Bot框架,json,node.js,botframework,Json,Node.js,Botframework,我当前询问是/否问题的代码是 builder.Prompts.choice(session, q15, "Yes|No", { listStyle: builder.ListStyle.button }); 我想将字符串“Yes”和“No”存储在JSON文件中,并通过它们的变量名访问它们,而不是硬编码。我该怎么做 作为choice()的定义: choice(会话:会话,提示:TextOrMessageType,选项:string | Object | string[]| IChoice[],
builder.Prompts.choice(session, q15, "Yes|No", { listStyle: builder.ListStyle.button });
我想将字符串“Yes”和“No”存储在JSON文件中,并通过它们的变量名访问它们,而不是硬编码。我该怎么做 作为
choice()
的定义:
choice(会话:会话,提示:TextOrMessageType,选项:string | Object | string[]| IChoice[],选项?:IPromptChoiceOptions):void代码>
您可以传递字符串数组作为选项。请考虑下面的代码片段:
//assume you have read the json string from a file and use it as following
const json_string = `{
"VARIABLE_YES":"Yes",
"VARIABLE_NO":"No"
}`;
const json_obj = JSON.parse(json_string);
builder.Prompts.choice(session, 'Make a choice', [json_obj.VARIABLE_YES, json_obj.VARIABLE_NO], {
listStyle: builder.ListStyle.button
});