本文整理汇总了TypeScript中botbuilder.Library.dialog方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Library.dialog方法的具体用法?TypeScript Library.dialog怎么用?TypeScript Library.dialog使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类botbuilder.Library
的用法示例。
在下文中一共展示了Library.dialog方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
constructor(instrumentation: BotFrameworkInstrumentation) {
this.instrumentation = instrumentation;
this.library = new Library('faq');
this.library.localePath(path.join(__dirname, '../../../src/bots/faq/locale'));
this.library.dialog('/', faq.createDialog(this));
this.library.dialog('qna', qna.createDialog(this));
}
示例2: async
lib.dialog('prompt', [
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);
}
},
async (session: builder.Session, results: any, next?: (results?: builder.IDialogResult<any>) => void) => {
let data: ISearchStoredData = session.dialogData.search;
let drug = undefined;
if (results && results.response && results.response.entity && data.source) {
let response = results.response.entity;
if (data.source == 'fr') {
for (let item of data.search) {
if (item.denomination == response) {
drug = await openmedicament.getMedicationFromIdAsync(item.codeCIS);
}
}
}
if (data.source == 'us') {
for (let item of data.search) {
if (item.brand_name == response) {
drug = await openfda.getMedicationFromIdAsync(item.id);
}
}
}
}
let result : builder.IDialogResult<any> = {
response : {
source: data.source,
drug: drug
}};
return session.endDialogWithResult(result);
//.........这里部分代码省略.........
示例3: getCardsAttachments
import * as builder from 'botbuilder';
import { SiteUrl } from '../helpers/helper-siteurl';
let lib = new builder.Library('greetings');
lib.dialog('start',
(session: builder.Session, args: any) => {
let cards = getCardsAttachments(session);
if (args === 'default') {
session.send("greetings_lost");
} else {
session.send("greetings_details_firstline");
session.send("greetings_details_secondline");
}
// Create reply with Carousel AttachmentLayout
var message = new builder.Message(session)
.text("greetings_welcome")
.attachmentLayout(builder.AttachmentLayout.carousel)
.attachments(cards);
session.send(message);
session.endDialog(); // <--- DON'T FORGET TO END THE DIALOG
});
export function getCardsAttachments(session: builder.Session) {
return [
new builder.HeroCard(session)
.title(session.localizer.gettext(session.preferredLocale(), 'greetings_menu_title_findplace', "greetings"))
.subtitle(session.localizer.gettext(session.preferredLocale(), 'greetings_menu_subtitletitle_findplace', "greetings"))
示例4: catch
lib.dialog('findplace', [
(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();
}
},
(session: builder.Session, results: builder.IDialogResult<IEntity>, next?: (results?: builder.IDialogResult<any>) => void) => {
let place: IStoredData = session.dialogData.place;
if (results && results.response) {
place.type = session.dialogData.place.type = results.response.entity;
}
// Check if we already have a location
if (place.location) {
if (next) return next()
}
let location_text = session.localizer.gettext(session.preferredLocale(), "location_prompt", "places")
// Trigger prompt to get the user location
let options = {
prompt: location_text,
useNativeControl: true,
reverseGeocode: true,
skipConfirmationAsk: true,
skipFavorites: true,
requiredFields:
locationDialog.LocationRequiredFields.locality
};
try {
locationDialog.getLocation(session, options);
}
catch (error) {
console.error("locationDialog.getLocation failed. " + error);
}
},
async (session: builder.Session, results: any, next?: (results?: builder.IDialogResult<any>) => void) => {
let place: IStoredData = session.dialogData.place;
if (results && results.response) {
place.location = session.dialogData.place.location = results.response;
}
let type = (place.type == 'pharmacy') ? EntityType.Pharmacy : EntityType.Hospital;
// We have a location and type of location - we can perform the search
try {
let data = undefined;
if (place.location.geo && place.location.geo.latitude && place.location.geo.longitude) {
data = await spatialData.getSpatialDataFromLatitudeLongitudeAsync(place.location.geo.latitude, place.location.geo.longitude, type);
}
else {
data = await spatialData.getSpatialDataFromAddressAsync(place.location, type);
}
let message = formatCarouselMessage(session, place, data);
session.send(message);
}
catch (error) {
console.error("spatialData.getSpatialDataFromAreaAsync. " + error);
}
return session.endDialog()
}
]).triggerAction({ matches: 'Intent.Places.FindLocation' });
示例5: async
lib.dialog('information', [
async (session: builder.Session, args: any, next?: (results?: builder.IDialogResult<any>) => void) => {
let data: IInformationStoredData | undefined = undefined;
// Get the Medication entity
if (args && args.intent) {
let intent = args.intent;
let medicationEntity: IEntityEx = builder.EntityRecognizer.findEntity(intent.entities, 'Medication.Name') as IEntityEx;
let typeEntity: IEntityEx = builder.EntityRecognizer.findEntity(intent.entities, 'Medication.Type') as IEntityEx;
data = session.dialogData.drug = {
name: medicationEntity ? medicationEntity.entity : undefined,
type: typeEntity ? typeEntity.resolution : undefined
}
}
if (data && data.name) {
if (next) return next();
}
else {
session.send("drugs_help_tip_image");
return builder.Prompts.text(session, "medication_prompt")
}
},
async (session: builder.Session, results: any, next?: (results?: builder.IDialogResult<any>) => void) => {
if (results && results.response) {
session.dialogData.drug.name = results.response;
}
let data: IInformationStoredData = session.dialogData.drug;
if (data && data.name) {
return session.beginDialog('medication-prompt:prompt', data.name);
}
},
async (session: builder.Session, results: any, next?: (results?: builder.IDialogResult<any>) => void) => {
// Formatting the response
if (results && results.response) {
let data = results.response;
if (data.source == 'fr') {
let drug: Medication = data.drug;
// Brand Name
session.send("**" + drug.denomination + "**");
// Indications and Usage
let indication_message = "Indications and Usage \n\n";
let translatedIndications = await translator.getTranslationAsync(drug.indicationsTherapeutiques, 'fr', 'en');
let turndown = new turndownService();
if (translatedIndications) {
indication_message += turndown.turndown(translatedIndications);
}
session.send(indication_message);
// Composition
let composition_message = "Composition \n\n";
for (var composition of drug.compositions) {
composition_message += ` └ ${composition.designationElementPharmaceutique} \n\n`;
for (var substance of composition.substancesActives) {
let translatedSubstance = await translator.getTranslationAsync(substance.denominationSubstance, 'fr', 'en');
composition_message += ` └ ${translatedSubstance} with a dosage of ${substance.dosageSubstance} \n\n`;
}
}
session.send(composition_message);
}
if (data.source == 'us') {
let drug: Result = data.drug.results[0];
// Brand Name
session.send("**" + drug.openfda.brand_name[0] + "**");
// Indications and Usage
let indication_message = "Indications and Usage \n\n";
indication_message += drug.indications_and_usage;
session.send(indication_message);
// Composition
let composition_message = "Composition \n\n";
if (drug.active_ingredient) {
for (let composition of drug.active_ingredient) {
composition_message += ` └ ${composition} \n\n`;
}
}
session.send(composition_message);
}
}
return session.endDialog();
}
]).triggerAction({ matches: 'Intent.Medications.GetInformation' });
示例6: async
lib.dialog('detection', [
async (session: builder.Session, args: any, next?: (results?: builder.IDialogResult<any>) => void) => {
session.send("Image received. Analysis in progress.");
session.sendTyping();
if (attachment.hasImageAttachment(session.message)) {
image = undefined;
image = await attachment.getImageFromMessageAsync(session.message, session.connector);
if (!image) {
return session.endDialog("Not able to get the image you sent, sorry :(");
}
let isMedicineImage = await custom.isMedicineImage(image);
if (!isMedicineImage) {
let caption = await vision.getCaptionFromImageAsync(image);
return session.endDialog(`This image is not medicine package. It seems ${caption}.`);
}
return session.beginDialog("language-dialog");
}
},
async (session: builder.Session, results: any, next?: (results?: builder.IDialogResult<any>) => void) => {
let ocrResult = undefined;
if (image) {
if (results.response == "unknown") {
ocrResult = await vision.getTextFromImageAsync(image);
} else {
ocrResult = await vision.getTextFromImageAsync(image, results.response.languageCode);
}
}
if (!ocrResult) {
return session.endDialog("Sorry, I didn’t recognize this, please try with another one.");
}
let language: string | undefined;
let ocrText: string[] | undefined;
let fullText: string | undefined;
let translationText: string | undefined;
if (ocrResult.language) {
language = await translator.getLanguageNameAsync(ocrResult.language);
ocrText = await vision.getTextFromOcrResult(ocrResult);
}
if (language === undefined || ocrText === undefined || ocrText.join('') == '') {
return session.endDialog("Sorry, I didn’t recognize this, please try with another one.");
}
session.send(`We recognized a medicine package with ${language} language.`)
if (ocrText) {
fullText = ocrText.join('');
translationText = await translator.getTranslationAsync(fullText, ocrResult.language, "en");
}
session.send(`Text description in ${language}: ${fullText}.`);
session.send(`Translation in English : ${translationText}.`)
return session.endDialog();
}]).triggerAction({ matches: 'Intent.Upload.Image' });
示例7: require
import countrydata from '../helpers/helper-countrydata';
let lib = new builder.Library('country-prompt');
let languages = require('country-data').languages;
lib.dialog('prompt', [
(session: builder.Session, results: any, next?: (results?: builder.IDialogResult<any>) => void) => {
// Prompt the user for a country
builder.Prompts.text(session, "drugs_country_prompt");
},
(session: builder.Session, results: any, next?: (results?: builder.IDialogResult<any>) => void) => {
if (results && results.response) {
let searchCountry = countrydata.getCountryByName(results.response);
if (searchCountry) {
let result = {
country: searchCountry.name,
countryCode: searchCountry.alpha2
};
return session.endDialogWithResult({ response: result });
}
}
session.send("drugs_default_country");
return session.replaceDialog("prompt");
}
]);
export function createLibrary(): builder.Library {
return lib.clone();
}