本文整理汇总了TypeScript中botbuilder.Prompts.choice方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Prompts.choice方法的具体用法?TypeScript Prompts.choice怎么用?TypeScript Prompts.choice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类botbuilder.Prompts
的用法示例。
在下文中一共展示了Prompts.choice方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
(session: builder.Session, args: any, next?: (results?: builder.IDialogResult<any>) => void) => {
let place: IStoredData;
let heathplace: boolean = false
if (args && args.intent) {
let intent = args.intent;
// Get Place.Type and Place.Location entities
let typeEntity: IEntityEx = builder.EntityRecognizer.findEntity(intent.entities, 'Place.Type') as IEntityEx;
let locationEntity: IEntityEx = builder.EntityRecognizer.findEntity(intent.entities, 'Place.Location') as IEntityEx;
place = session.dialogData.place = {
type: typeEntity ? typeEntity.resolution.values[0] : undefined,
location: locationEntity ? locationEntity.entity : undefined,
};
// We want to manage only medical places
heathplace = place.type == 'hospital' || place.type == 'pharmacy';
}
if (!heathplace) {
builder.Prompts.choice(session, "choice_prompt", "hospital|pharmacy", { listStyle: ListStyle.button });
}
else {
if (next) return next();
}
},
示例2: RegExp
(session: builder.Session, results: any, next?: (results?: builder.IDialogResult<any>) => void) => {
let userAnswer : string = results.response;
let pattern = new RegExp(/^unknown/i );
let matches = userAnswer.match(pattern);
if (matches) {
return session.endDialogWithResult({ response: "unknown" })
}
if (results && results.response) {
let searchLanguage = countrydata.getVisionLanguageByName(results.response);
if (searchLanguage && searchLanguage.length == 1) {
let result = {
language: searchLanguage[0].name,
languageCode: searchLanguage[0].code
};
return session.endDialogWithResult({ response: result });
} else if (searchLanguage && searchLanguage.length > 1) {
let choices = new Array<string>();
searchLanguage.forEach(element => {
choices.push(element.name);
});
return builder.Prompts.choice(session, "Please select an option:", choices, {listStyle : ListStyle.button})
}
}
session.send("image_default_language");
return session.replaceDialog("language-dialog");
},
示例3: function
function (session, args) {
var qnaMakerResult = args as IQnAMakerResults;
session.dialogData.qnaMakerResult = qnaMakerResult;
var questionOptions: string[] = [];
qnaMakerResult.answers.forEach(function (qna: IQnAMakerResult) { questionOptions.push(qna.questions[0]); });
questionOptions.push("None of the above.");
var promptOptions: builder.IPromptOptions = {listStyle: builder.ListStyle.button, maxRetries: 0};
builder.Prompts.choice(session, "Did you mean:", questionOptions, promptOptions);
},
示例4: next
(session: Session, luisResults: IIntentRecognizerResult, next: (results?: IDialogResult<any>) => void) => {
const languageEntity = EntityRecognizer.findEntity(luisResults.entities, 'language');
const language = languageEntity && languageEntity.entity;
if (!language) {
Prompts.choice(session, 'master.languageSelection', Object.keys(languages),
{ listStyle: ListStyle.button, maxRetries: 3, retryPrompt: 'master.retryLanguageSelection' });
} else {
next({ response: { entity: language }});
}
},
示例5: function
function(session: any) {
if(this.criteria["type"] === "choice"){
var choices:any = [];
for(var choice of this.criteria["choices"]){
choices.push(choice.value);
}
builder.Prompts.choice(session, this.criteria["question"], choices);
}
//https://docs.botframework.com/en-us/node/builder/chat-reference/classes/_botbuilder_d_.luisrecognizer.html
else {
builder.Prompts[this.criteria["type"]](session, this.criteria["question"], null );
}
}, function(session: any, results: any) {
示例6: if
.then((routeList) => {
if (!routeList || !routeList.routes || routeList.routes.length == 0) {
console.log('Issue with route list. Undefined, null, or empty.');
session.send("I'm sorry, I found no routes for you.");
} else if (routeList.routes.length == 1) {
console.log('Found 1 route. ' + routeList.routes[0].details);
session.send(routeList.routes[0].details);
} else {
console.log('Found multiple routes');
session.userData.routeList = routeList;
let prompt = `I found ${routeList.routes.length} routes from ${routeList.origin} to ${routeList.destination}. Which one do you want the details for?`;
let choices = routeList.routes.map((route, index) => {
return route.summary;
});
builder.Prompts.choice(session, prompt, choices, {listStyle: ListStyle.list});
}
})
示例7:
(session: any, results: any) => {
session.send('I am looking for the nearest store to ' + results.response + ', please wait a few seconds');
session.send('Oh and based on what you need I can also recommand that you get a Office 365 subscription, are you interested in this?');
var msg = new builder.Message(session)
.textFormat(builder.TextFormat.xml)
.attachmentLayout(builder.AttachmentLayout.carousel)
.attachments([
new builder.HeroCard(session)
.title("Special Offer")
.text("Add an Office 365 subscription?")
.images([])
.buttons([
builder.CardAction.imBack(session, "Yes", "Yes"),
builder.CardAction.imBack(session, "No", "No")
])
]);
builder.Prompts.choice(session, msg, "Yes|No");
},
示例8: step1
private static async step1(session: builder.Session, args?: any | builder.IDialogResult<any>, next?: (args?: builder.IDialogResult<any>) => void): Promise<void> {
let buttons = new Array<builder.CardAction>();
buttons.push(builder.CardAction.imBack(session, "y_e_s", session.gettext(Strings.game_button_yes) + "3"));
buttons.push(builder.CardAction.imBack(session, "n_o", session.gettext(Strings.game_button_no) + "3"));
let newCard = new builder.HeroCard(session)
.title(session.gettext(Strings.default_title) + "3")
.subtitle(Strings.default_subtitle)
.text(Strings.quiz_choose)
.images([
new builder.CardImage(session)
.url(config.get("app.baseUri") + "/assets/computer_person.jpg")
.alt(session.gettext(Strings.img_default)),
])
.buttons(buttons);
let msg = new builder.Message(session)
.addAttachment(newCard);
builder.Prompts.choice(session, msg, ["y_e_s", "n_o"]);
}
示例9: request
(session: any, results: any) => {
session.send('Ok!');
session.send('Here is the nearest store I have found. A seller will be able to answer your questions. :)');
var address = "3 bis, rue rottembourg 75012 PARIS" //results.response;
var res = request('GET', 'http://dev.virtualearth.net/REST/v1/Locations?countryRegion=FR&key=AsiCMSmOq6O3MzsI4F7HqUXmB2JY7E76gdaCgtlranURBYOHgbariAXQxJURoTE8&addressLine=' + address);
var bing = JSON.parse(res.getBody('utf8'));
if (bing.resourceSets[0].estimatedTotal) {
let lat = bing.resourceSets[0].resources[0].point.coordinates[0];
let lng = bing.resourceSets[0].resources[0].point.coordinates[1];
this._store = [Number.MAX_SAFE_INTEGER, null];
for (let i = 0, len = this._stores.length; i < len; i++) {
let distance = this._geolocalisation.getDistanceFromLatLonInKm(lat, lng, this._stores[i].localisation.lat, this._stores[i].localisation.lng)
if (distance < this._store[0]) {
this._store[0] = distance;
this._store[1] = this._stores[i];
}
}
var msg = new builder.Message(session)
.textFormat(builder.TextFormat.xml)
.attachmentLayout(builder.AttachmentLayout.carousel)
.attachments([
new builder.HeroCard(session)
.title(this._store[1].name)
.text("12 Rue HalĂŠvy, 75009 Paris")
.images([
builder.CardImage.create(session, "http://www.timstanleyphoto.com/HDR/2012/i-GrS2b37/0/L/MicrosoftStore-L.jpg")
.tap(builder.CardAction.showImage(session, "http://www.timstanleyphoto.com/HDR/2012/i-GrS2b37/0/L/MicrosoftStore-L.jpg")),
])
.buttons([
builder.CardAction.openUrl(session, "http://bing.com/maps/default.aspx?rtp=adr." + "39%20quai%20du%20president%20roosevelt%2092130%20issy%20les%20moulineaux" + "~adr." + "12 Rue HalĂŠvy, 75009 Paris" + "&rtop=0~1~0", "Bing Direction"),
builder.CardAction.imBack(session, "Let's go !", "Go")
])
]);
builder.Prompts.choice(session, msg, "Let's go !");
} else {
session.send('I cannot find a store near you, try with a different address');
}
},
示例10: async
async (session: builder.Session, args: any, next?: (results?: builder.IDialogResult<any>) => void) => {
let query = args;
let medications = new Array<string>();
try {
// Verification in Open Medicaments data source (France)
let frSearch = await openmedicament.getMedicationCodeFromQueryAsync(query);
if (frSearch && frSearch.length > 0) {
if (frSearch.length > MAX_RESULTS) {
frSearch = frSearch.slice(0, MAX_RESULTS);
}
// Save the current search in dialogData state
let data: ISearchStoredData = {
source: 'fr',
search: frSearch
}
session.dialogData.search = data;
for (let item of frSearch) {
medications.push(item.denomination);
}
return builder.Prompts.choice(session, "medication_prompt", medications);
}
// Verification in Open FDA data source (US)
let usSearch = await openfda.getMedicationFromQueryAsync(query);
if (usSearch && usSearch.results && usSearch.results.length > 0) {
if (usSearch.results.length > MAX_RESULTS) {
usSearch.results = usSearch.results.slice(0, MAX_RESULTS);
}
// Save the current search in dialogData state
let search = new Array<IFdaSearch>();
for (let item of usSearch.results) {
medications.push(item.openfda.brand_name[0]);
search.push({
brand_name: item.openfda.brand_name[0],
id: item.id,
set_id: item.set_id,
version: item.version
});
}
// Save the current search in dialogData state
let data: ISearchStoredData = {
source: 'us',
search: search
}
session.dialogData.search = data;
return builder.Prompts.choice(session, "medication_prompt", medications);
}
session.send("notfound_message")
if (next) return session.endDialog();
} catch (error) {
console.error(error);
}
},