UNPKG

botbuilder-dialogs-adaptive

Version:

Rule system for the Microsoft BotBuilder dialog system.

74 lines 3.77 kB
"use strict"; /** * @module botbuilder-dialogs-adaptive */ /** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ChannelMentionEntityRecognizer = void 0; const adaptiveRecognizer_1 = require("../adaptiveRecognizer"); /** * Recognizer which maps channel activity.entities of type mention into [RecognizerResult](xref:botbuilder-core.RecognizerResult) format. */ class ChannelMentionEntityRecognizer extends adaptiveRecognizer_1.AdaptiveRecognizer { /** * To recognize intents and entities in a users utterance. * * @param {DialogContext} _dialogContext Dialog Context. * @param {Partial<Activity>} activity Activity. * @param {object} _telemetryProperties Additional properties to be logged to telemetry with event. * @param {object} _telemetryMetrics Additional metrics to be logged to telemetry with event. * @returns {Promise<RecognizerResult>} Analysis of utterance. */ recognize(_dialogContext, activity, _telemetryProperties, _telemetryMetrics) { return __awaiter(this, void 0, void 0, function* () { const result = { text: '', intents: {}, entities: {}, }; const entities = result.entities; // prompt external mention entities from the activity into recognizer result if (activity.entities) { let iStart = 0; activity.entities .filter((e) => e.type === 'mention') .forEach((entity) => { var _a, _b, _c; (_a = entities.channelMention) !== null && _a !== void 0 ? _a : (entities.channelMention = []); entities.channelMention.push(entity.mentioned); (_b = entities['$instance']) !== null && _b !== void 0 ? _b : (entities['$instance'] = {}); const instance = entities['$instance']; (_c = instance.channelMention) !== null && _c !== void 0 ? _c : (instance.channelMention = []); const mentionedText = `${entity.text}`; iStart = activity.text.indexOf(mentionedText, iStart); if (iStart >= 0) { instance.channelMention.push({ startIndex: iStart, endIndex: iStart + mentionedText.length, text: mentionedText, score: 1.0, }); // note, we increment so next pass through continues after the token we just processed. iStart++; } }); } return result; }); } } exports.ChannelMentionEntityRecognizer = ChannelMentionEntityRecognizer; ChannelMentionEntityRecognizer.$kind = 'Microsoft.ChannelMentionEntityRecognizer'; //# sourceMappingURL=channelMentionEntityRecognizer.js.map