botbuilder-core
Advanced tools
Comparing version 4.5.3 to 4.6.0-preview1
@@ -8,3 +8,4 @@ /** | ||
*/ | ||
import { TurnContext } from '.'; | ||
import { MessageReaction, TurnContext } from '.'; | ||
import { ActivityHandlerBase } from './activityHandlerBase'; | ||
export declare type BotHandler = (context: TurnContext, next: () => Promise<void>) => Promise<any>; | ||
@@ -56,4 +57,6 @@ /** | ||
*/ | ||
export declare class ActivityHandler { | ||
private readonly handlers; | ||
export declare class ActivityHandler extends ActivityHandlerBase { | ||
protected readonly handlers: { | ||
[type: string]: BotHandler[]; | ||
}; | ||
/** | ||
@@ -176,13 +179,151 @@ * Bind a handler to the Turn event that is fired for every incoming activity, regardless of type | ||
/** | ||
* Private method used to bind handlers to events by name | ||
* Overwrite this method to use different logic than the default initial Activity processing logic. | ||
* @remarks | ||
* The default logic is below: | ||
* ```ts | ||
* await this.handle(context, 'Turn', async () => { | ||
* await super.onTurnActivity(context); | ||
* }); | ||
* ``` | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
protected onTurnActivity(context: TurnContext): Promise<void>; | ||
/** | ||
* Runs all `onMesssage()` handlers before calling the `ActivityHandler.defaultNextEvent()`. | ||
* @remarks | ||
* Developers may overwrite this method when having supporting multiple channels to have a | ||
* channel-tailored experience. | ||
* @remarks | ||
* The default logic is below: | ||
* ```ts | ||
* await await this.handle(context, 'Message', this.defaultNextEvent(context)); | ||
* ``` | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
protected onMessageActivity(context: TurnContext): Promise<void>; | ||
/** | ||
* Runs all `onUnrecognizedActivityType()` handlers before calling `ActivityHandler.dispatchConversationUpdateActivity()`. | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
protected onUnrecognizedActivity(context: TurnContext): Promise<void>; | ||
/** | ||
* Runs all `onConversationUpdate()` handlers before calling `ActivityHandler.dispatchConversationUpdateActivity()`. | ||
* @remarks | ||
* The default logic is below: | ||
* ```ts | ||
* await this.handle(context, 'ConversationUpdate', async () => { | ||
* await this.dispatchConversationUpdateActivity(context); | ||
* }); | ||
* ``` | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
protected onConversationUpdateActivity(context: TurnContext): Promise<void>; | ||
/** | ||
* Override this method when dispatching off of a `'ConversationUpdate'` event to trigger other sub-events. | ||
* @remarks | ||
* The default logic is below: | ||
* ```ts | ||
* if (context.activity.membersAdded && context.activity.membersAdded.length > 0) { | ||
* await this.handle(context, 'MembersAdded', this.defaultNextEvent(context)); | ||
* } else if (context.activity.membersRemoved && context.activity.membersRemoved.length > 0) { | ||
* await this.handle(context, 'MembersRemoved', this.defaultNextEvent(context)); | ||
* } else { | ||
* await this.defaultNextEvent(context)(); | ||
* } | ||
* ``` | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
protected dispatchConversationUpdateActivity(context: TurnContext): Promise<void>; | ||
/** | ||
* Runs all `onMessageReaction()` handlers before calling `ActivityHandler.dispatchMessageReactionActivity()`. | ||
* @remarks | ||
* The default logic is below: | ||
* ```ts | ||
* await this.handle(context, 'MessageReaction', async () => { | ||
* await this.dispatchMessageReactionActivity(context); | ||
* }); | ||
* ``` | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
protected onMessageReactionActivity(context: TurnContext): Promise<void>; | ||
/** | ||
* | ||
* @param reactionsAdded The list of reactions added | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
protected onReactionsAddedActivity(reactionsAdded: MessageReaction[], context: TurnContext): Promise<void>; | ||
/** | ||
* | ||
* @param reactionsRemoved The list of reactions removed | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
protected onReactionsRemovedActivity(reactionsRemoved: MessageReaction[], context: TurnContext): Promise<void>; | ||
/** | ||
* Override this method when dispatching off of a `'MessageReaction'` event to trigger other sub-events. | ||
* @remarks | ||
* If there are no reactionsAdded or reactionsRemoved on the incoming activity, it will call `this.defaultNextEvent` | ||
* which emits the `'Dialog'` event by default. | ||
* The default logic is below: | ||
* ```ts | ||
* if (context.activity.reactionsAdded || context.activity.reactionsRemoved) { | ||
* super.onMessageReactionActivity(context); | ||
* } else { | ||
* await this.defaultNextEvent(context)(); | ||
* } | ||
* ``` | ||
* `super.onMessageReactionActivity()` will dispatch to `onReactionsAddedActivity()` | ||
* or `onReactionsRemovedActivity()`. | ||
* | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
protected dispatchMessageReactionActivity(context: TurnContext): Promise<void>; | ||
/** | ||
* Runs all `onEvent()` handlers before calling `ActivityHandler.dispatchEventActivity()`. | ||
* @remarks | ||
* The default logic is below: | ||
* ```ts | ||
* await this.handle(context, 'Event', async () => { | ||
* await this.dispatchEventActivity(context); | ||
* }); | ||
* ``` | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
protected onEventActivity(context: TurnContext): Promise<void>; | ||
/** | ||
* Override this method when dispatching off of a `'Event'` event to trigger other sub-events. | ||
* @remarks | ||
* For certain channels (e.g. Web Chat, custom Direct Line clients), developers can emit | ||
* custom `'event'`-type activities from the client. Developers should then overwrite this method | ||
* to support their custom `'event'` activities. | ||
* | ||
* The default logic is below: | ||
* ```ts | ||
* if (context.activity.name === 'tokens/response') { | ||
* await this.handle(context, 'TokenResponseEvent', this.defaultNextEvent(context)); | ||
* } else { | ||
* await this.defaultNextEvent(context)(); | ||
* } | ||
* ``` | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
protected dispatchEventActivity(context: TurnContext): Promise<void>; | ||
/** | ||
* Returns an async function that emits the `'Dialog'` event when called. | ||
* Overwrite this function to emit a different default event once all relevant | ||
* events are emitted. | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
protected defaultNextEvent(context: TurnContext): () => Promise<void>; | ||
/** | ||
* Used to bind handlers to events by name | ||
* @param type string | ||
* @param handler BotHandler | ||
*/ | ||
private on; | ||
protected on(type: string, handler: BotHandler): this; | ||
/** | ||
* Private method used to fire events and execute any bound handlers | ||
* Used to fire events and execute any bound handlers | ||
* @param type string | ||
* @param handler BotHandler | ||
*/ | ||
private handle; | ||
protected handle(context: TurnContext, type: string, onNext: () => Promise<void>): Promise<any>; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const activityHandlerBase_1 = require("./activityHandlerBase"); | ||
/** | ||
* @module botbuilder | ||
*/ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
const _1 = require("."); | ||
/** | ||
* Event-emitting base class bots. | ||
@@ -56,4 +49,5 @@ * | ||
*/ | ||
class ActivityHandler { | ||
class ActivityHandler extends activityHandlerBase_1.ActivityHandlerBase { | ||
constructor() { | ||
super(...arguments); | ||
this.handlers = {}; | ||
@@ -201,12 +195,190 @@ } | ||
async run(context) { | ||
if (!context) { | ||
throw new Error(`Missing TurnContext parameter`); | ||
await super.run(context); | ||
} | ||
/** | ||
* Overwrite this method to use different logic than the default initial Activity processing logic. | ||
* @remarks | ||
* The default logic is below: | ||
* ```ts | ||
* await this.handle(context, 'Turn', async () => { | ||
* await super.onTurnActivity(context); | ||
* }); | ||
* ``` | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
async onTurnActivity(context) { | ||
await this.handle(context, 'Turn', async () => { | ||
await super.onTurnActivity(context); | ||
}); | ||
} | ||
/** | ||
* Runs all `onMesssage()` handlers before calling the `ActivityHandler.defaultNextEvent()`. | ||
* @remarks | ||
* Developers may overwrite this method when having supporting multiple channels to have a | ||
* channel-tailored experience. | ||
* @remarks | ||
* The default logic is below: | ||
* ```ts | ||
* await await this.handle(context, 'Message', this.defaultNextEvent(context)); | ||
* ``` | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
async onMessageActivity(context) { | ||
await this.handle(context, 'Message', this.defaultNextEvent(context)); | ||
} | ||
/** | ||
* Runs all `onUnrecognizedActivityType()` handlers before calling `ActivityHandler.dispatchConversationUpdateActivity()`. | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
async onUnrecognizedActivity(context) { | ||
await this.handle(context, 'UnrecognizedActivityType', this.defaultNextEvent(context)); | ||
} | ||
/** | ||
* Runs all `onConversationUpdate()` handlers before calling `ActivityHandler.dispatchConversationUpdateActivity()`. | ||
* @remarks | ||
* The default logic is below: | ||
* ```ts | ||
* await this.handle(context, 'ConversationUpdate', async () => { | ||
* await this.dispatchConversationUpdateActivity(context); | ||
* }); | ||
* ``` | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
async onConversationUpdateActivity(context) { | ||
await this.handle(context, 'ConversationUpdate', async () => { | ||
await this.dispatchConversationUpdateActivity(context); | ||
}); | ||
} | ||
/** | ||
* Override this method when dispatching off of a `'ConversationUpdate'` event to trigger other sub-events. | ||
* @remarks | ||
* The default logic is below: | ||
* ```ts | ||
* if (context.activity.membersAdded && context.activity.membersAdded.length > 0) { | ||
* await this.handle(context, 'MembersAdded', this.defaultNextEvent(context)); | ||
* } else if (context.activity.membersRemoved && context.activity.membersRemoved.length > 0) { | ||
* await this.handle(context, 'MembersRemoved', this.defaultNextEvent(context)); | ||
* } else { | ||
* await this.defaultNextEvent(context)(); | ||
* } | ||
* ``` | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
async dispatchConversationUpdateActivity(context) { | ||
if (context.activity.membersAdded && context.activity.membersAdded.length > 0) { | ||
await this.handle(context, 'MembersAdded', this.defaultNextEvent(context)); | ||
} | ||
if (!context.activity) { | ||
throw new Error(`TurnContext does not include an activity`); | ||
else if (context.activity.membersRemoved && context.activity.membersRemoved.length > 0) { | ||
await this.handle(context, 'MembersRemoved', this.defaultNextEvent(context)); | ||
} | ||
if (!context.activity.type) { | ||
throw new Error(`Activity is missing it's type`); | ||
else { | ||
await this.defaultNextEvent(context)(); | ||
} | ||
// Allow the dialog system to be triggered at the end of the chain | ||
} | ||
/** | ||
* Runs all `onMessageReaction()` handlers before calling `ActivityHandler.dispatchMessageReactionActivity()`. | ||
* @remarks | ||
* The default logic is below: | ||
* ```ts | ||
* await this.handle(context, 'MessageReaction', async () => { | ||
* await this.dispatchMessageReactionActivity(context); | ||
* }); | ||
* ``` | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
async onMessageReactionActivity(context) { | ||
await this.handle(context, 'MessageReaction', async () => { | ||
await this.dispatchMessageReactionActivity(context); | ||
}); | ||
} | ||
/** | ||
* | ||
* @param reactionsAdded The list of reactions added | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
async onReactionsAddedActivity(reactionsAdded, context) { | ||
await this.handle(context, 'ReactionsAdded', this.defaultNextEvent(context)); | ||
} | ||
/** | ||
* | ||
* @param reactionsRemoved The list of reactions removed | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
async onReactionsRemovedActivity(reactionsRemoved, context) { | ||
await this.handle(context, 'ReactionsRemoved', this.defaultNextEvent(context)); | ||
} | ||
/** | ||
* Override this method when dispatching off of a `'MessageReaction'` event to trigger other sub-events. | ||
* @remarks | ||
* If there are no reactionsAdded or reactionsRemoved on the incoming activity, it will call `this.defaultNextEvent` | ||
* which emits the `'Dialog'` event by default. | ||
* The default logic is below: | ||
* ```ts | ||
* if (context.activity.reactionsAdded || context.activity.reactionsRemoved) { | ||
* super.onMessageReactionActivity(context); | ||
* } else { | ||
* await this.defaultNextEvent(context)(); | ||
* } | ||
* ``` | ||
* `super.onMessageReactionActivity()` will dispatch to `onReactionsAddedActivity()` | ||
* or `onReactionsRemovedActivity()`. | ||
* | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
async dispatchMessageReactionActivity(context) { | ||
if (context.activity.reactionsAdded || context.activity.reactionsRemoved) { | ||
await super.onMessageReactionActivity(context); | ||
} | ||
else { | ||
await this.defaultNextEvent(context)(); | ||
} | ||
} | ||
/** | ||
* Runs all `onEvent()` handlers before calling `ActivityHandler.dispatchEventActivity()`. | ||
* @remarks | ||
* The default logic is below: | ||
* ```ts | ||
* await this.handle(context, 'Event', async () => { | ||
* await this.dispatchEventActivity(context); | ||
* }); | ||
* ``` | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
async onEventActivity(context) { | ||
await this.handle(context, 'Event', async () => { | ||
await this.dispatchEventActivity(context); | ||
}); | ||
} | ||
/** | ||
* Override this method when dispatching off of a `'Event'` event to trigger other sub-events. | ||
* @remarks | ||
* For certain channels (e.g. Web Chat, custom Direct Line clients), developers can emit | ||
* custom `'event'`-type activities from the client. Developers should then overwrite this method | ||
* to support their custom `'event'` activities. | ||
* | ||
* The default logic is below: | ||
* ```ts | ||
* if (context.activity.name === 'tokens/response') { | ||
* await this.handle(context, 'TokenResponseEvent', this.defaultNextEvent(context)); | ||
* } else { | ||
* await this.defaultNextEvent(context)(); | ||
* } | ||
* ``` | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
async dispatchEventActivity(context) { | ||
if (context.activity.name === 'tokens/response') { | ||
await this.handle(context, 'TokenResponseEvent', this.defaultNextEvent(context)); | ||
} | ||
else { | ||
await this.defaultNextEvent(context)(); | ||
} | ||
} | ||
/** | ||
* Returns an async function that emits the `'Dialog'` event when called. | ||
* Overwrite this function to emit a different default event once all relevant | ||
* events are emitted. | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
defaultNextEvent(context) { | ||
const runDialogs = async () => { | ||
@@ -217,54 +389,6 @@ await this.handle(context, 'Dialog', async () => { | ||
}; | ||
// List of all Activity Types: | ||
// https://github.com/Microsoft/botbuilder-js/blob/master/libraries/botframework-schema/src/index.ts#L1627 | ||
await this.handle(context, 'Turn', async () => { | ||
switch (context.activity.type) { | ||
case _1.ActivityTypes.Message: | ||
await this.handle(context, 'Message', runDialogs); | ||
break; | ||
case _1.ActivityTypes.ConversationUpdate: | ||
await this.handle(context, 'ConversationUpdate', async () => { | ||
if (context.activity.membersAdded && context.activity.membersAdded.length > 0) { | ||
await this.handle(context, 'MembersAdded', runDialogs); | ||
} | ||
else if (context.activity.membersRemoved && context.activity.membersRemoved.length > 0) { | ||
await this.handle(context, 'MembersRemoved', runDialogs); | ||
} | ||
else { | ||
await runDialogs(); | ||
} | ||
}); | ||
break; | ||
case _1.ActivityTypes.MessageReaction: | ||
await this.handle(context, 'MessageReaction', async () => { | ||
if (context.activity.reactionsAdded && context.activity.reactionsAdded.length > 0) { | ||
await this.handle(context, 'ReactionsAdded', runDialogs); | ||
} | ||
else if (context.activity.reactionsRemoved && context.activity.reactionsRemoved.length > 0) { | ||
await this.handle(context, 'ReactionsRemoved', runDialogs); | ||
} | ||
else { | ||
await runDialogs(); | ||
} | ||
}); | ||
break; | ||
case _1.ActivityTypes.Event: | ||
await this.handle(context, 'Event', async () => { | ||
if (context.activity.name === 'tokens/response') { | ||
await this.handle(context, 'TokenResponseEvent', runDialogs); | ||
} | ||
else { | ||
await runDialogs(); | ||
} | ||
}); | ||
break; | ||
default: | ||
// handler for unknown or unhandled types | ||
await this.handle(context, 'UnrecognizedActivityType', runDialogs); | ||
break; | ||
} | ||
}); | ||
return runDialogs; | ||
} | ||
/** | ||
* Private method used to bind handlers to events by name | ||
* Used to bind handlers to events by name | ||
* @param type string | ||
@@ -283,3 +407,3 @@ * @param handler BotHandler | ||
/** | ||
* Private method used to fire events and execute any bound handlers | ||
* Used to fire events and execute any bound handlers | ||
* @param type string | ||
@@ -286,0 +410,0 @@ * @param handler BotHandler |
@@ -11,5 +11,10 @@ /** | ||
/** | ||
* An interface components can use to read and write individual properties to the bot's state | ||
* management system. | ||
* @param T (Optional) type of property being persisted. Defaults to `any` type. | ||
* Defines methods for accessing a state property created in a | ||
* [BotState](xref:botbuilder-core.BotState) object. | ||
* | ||
* @typeparam T Optional. The type of the state property to access. Default type is `any`. | ||
* | ||
* @remarks | ||
* To create a state property in a state management objet, use the | ||
* [createProperty\<T>](xref:botbuilder-core.BotState.createProperty) method. | ||
*/ | ||
@@ -16,0 +21,0 @@ export interface StatePropertyAccessor<T = any> { |
@@ -8,3 +8,3 @@ /** | ||
*/ | ||
import { AnimationCard, Attachment, AudioCard, CardAction, CardImage, HeroCard, MediaUrl, ReceiptCard, ThumbnailCard, VideoCard } from 'botframework-schema'; | ||
import { AnimationCard, Attachment, AudioCard, CardAction, CardImage, HeroCard, MediaUrl, O365ConnectorCard, ReceiptCard, ThumbnailCard, VideoCard } from 'botframework-schema'; | ||
/** | ||
@@ -119,2 +119,24 @@ * A set of utility functions designed to assist with the formatting of the various card types a | ||
/** | ||
* Returns an attachment for an 0365Connector card. | ||
* | ||
* @remarks | ||
* ```JavaScript | ||
* const card = CardFactory.o365ConnectorCard({ | ||
* "title": "card title", | ||
* "text": "card text", | ||
* "summary": "O365 card summary", | ||
* "themeColor": "#E67A9E", | ||
* "sections": [ | ||
* { | ||
* "title": "**section title**", | ||
* "text": "section text", | ||
* "activityTitle": "activity title", | ||
* } | ||
* ] | ||
* }); | ||
* ``` | ||
* @param card The o365Connector card to return as an attachment. | ||
*/ | ||
static o365ConnectorCard(card: O365ConnectorCard): Attachment; | ||
/** | ||
* Returns an attachment for a receipt card. | ||
@@ -121,0 +143,0 @@ * @param card The adaptive card to return as an attachment. |
@@ -116,2 +116,26 @@ "use strict"; | ||
/** | ||
* Returns an attachment for an 0365Connector card. | ||
* | ||
* @remarks | ||
* ```JavaScript | ||
* const card = CardFactory.o365ConnectorCard({ | ||
* "title": "card title", | ||
* "text": "card text", | ||
* "summary": "O365 card summary", | ||
* "themeColor": "#E67A9E", | ||
* "sections": [ | ||
* { | ||
* "title": "**section title**", | ||
* "text": "section text", | ||
* "activityTitle": "activity title", | ||
* } | ||
* ] | ||
* }); | ||
* ``` | ||
* @param card The o365Connector card to return as an attachment. | ||
*/ | ||
static o365ConnectorCard(card) { | ||
return { contentType: CardFactory.contentTypes.o365ConnectorCard, content: card }; | ||
} | ||
/** | ||
* Returns an attachment for a receipt card. | ||
@@ -225,2 +249,3 @@ * @param card The adaptive card to return as an attachment. | ||
} | ||
exports.CardFactory = CardFactory; | ||
/** | ||
@@ -236,2 +261,3 @@ * List of content types for each card style. | ||
oauthCard: 'application/vnd.microsoft.card.oauth', | ||
o365ConnectorCard: 'application/vnd.microsoft.teams.card.o365connector', | ||
signinCard: 'application/vnd.microsoft.card.signin', | ||
@@ -241,3 +267,2 @@ thumbnailCard: 'application/vnd.microsoft.card.thumbnail', | ||
}; | ||
exports.CardFactory = CardFactory; | ||
/** | ||
@@ -244,0 +269,0 @@ * @private |
@@ -10,2 +10,3 @@ /** | ||
export * from './activityHandler'; | ||
export * from './activityHandlerBase'; | ||
export * from './autoSaveStateMiddleware'; | ||
@@ -28,2 +29,3 @@ export * from './botAdapter'; | ||
export * from './showTypingMiddleware'; | ||
export * from './skypeMentionNormalizeMiddleware'; | ||
export * from './storage'; | ||
@@ -30,0 +32,0 @@ export * from './telemetryLoggerMiddleware'; |
@@ -15,2 +15,3 @@ "use strict"; | ||
__export(require("./activityHandler")); | ||
__export(require("./activityHandlerBase")); | ||
__export(require("./autoSaveStateMiddleware")); | ||
@@ -31,2 +32,3 @@ __export(require("./botAdapter")); | ||
__export(require("./showTypingMiddleware")); | ||
__export(require("./skypeMentionNormalizeMiddleware")); | ||
__export(require("./storage")); | ||
@@ -33,0 +35,0 @@ __export(require("./telemetryLoggerMiddleware")); |
@@ -27,3 +27,3 @@ "use strict"; | ||
// Ensure proxy supported (some browsers don't) | ||
if (Proxy && Proxy.revocable) { | ||
if (typeof Proxy !== 'undefined' && Proxy.revocable) { | ||
return Proxy.revocable(target, handler || {}); | ||
@@ -30,0 +30,0 @@ } |
@@ -145,4 +145,4 @@ "use strict"; | ||
} | ||
exports.MemoryTranscriptStore = MemoryTranscriptStore; | ||
MemoryTranscriptStore.pageSize = 20; | ||
exports.MemoryTranscriptStore = MemoryTranscriptStore; | ||
/** | ||
@@ -149,0 +149,0 @@ * @private |
@@ -234,2 +234,3 @@ "use strict"; | ||
} | ||
exports.TelemetryLoggerMiddleware = TelemetryLoggerMiddleware; | ||
/** | ||
@@ -251,3 +252,2 @@ * The name of the event when when new message is received from the user. | ||
TelemetryLoggerMiddleware.botMsgDeleteEvent = 'BotMessageDelete'; | ||
exports.TelemetryLoggerMiddleware = TelemetryLoggerMiddleware; | ||
//# sourceMappingURL=telemetryLoggerMiddleware.js.map |
@@ -44,3 +44,11 @@ "use strict"; | ||
const responses = await next2(); | ||
activities.forEach((a) => this.logActivity(transcript, this.cloneActivity(a))); | ||
activities.map((a, index) => { | ||
const clonedActivity = this.cloneActivity(a); | ||
if (index < responses.length) { | ||
if (!clonedActivity.id) { | ||
clonedActivity.id = responses[index].id; | ||
} | ||
} | ||
this.logActivity(transcript, clonedActivity); | ||
}); | ||
return responses; | ||
@@ -47,0 +55,0 @@ }); |
@@ -73,9 +73,17 @@ /** | ||
/** | ||
* Rewrites the activity text without any at mention. Specifying a particular recipient id. | ||
* Use with caution because this function is altering the text on the Activity. | ||
* Remove any mention text for given id from the Activity.Text property. For example, given the message | ||
* "@echoBot Hi Bot", this will remove "@echoBot", leaving "Hi Bot". | ||
* | ||
* @remarks | ||
* Some channels, for example Microsoft Teams, add at mention details into the text on a message activity. | ||
* This can interfer with later processing. This is a helper function to remove the at mention. | ||
* Typically this would be used to remove the mention text for the target recipient (the bot usually), though | ||
* it could be called for each member. For example: | ||
* turnContext.Activity.RemoveMentionText(turnContext.Activity.Recipient.Id); | ||
* | ||
* The format of a mention Activity.Entity is dependent on the Channel. But in all cases we | ||
* expect the Mention.Text to contain the exact text for the user as it appears in | ||
* Activity.Text. | ||
* | ||
* For example, Teams uses "<at>username</at>", whereas slack use "@username". It | ||
* is expected that text is in Activity.Text and this method will remove that value from | ||
* Activity.Text. | ||
* | ||
* ```JavaScript | ||
@@ -82,0 +90,0 @@ * const updatedText = TurnContext.removeRecipientMention(context.request); |
@@ -51,9 +51,17 @@ "use strict"; | ||
/** | ||
* Rewrites the activity text without any at mention. Specifying a particular recipient id. | ||
* Use with caution because this function is altering the text on the Activity. | ||
* Remove any mention text for given id from the Activity.Text property. For example, given the message | ||
* "@echoBot Hi Bot", this will remove "@echoBot", leaving "Hi Bot". | ||
* | ||
* @remarks | ||
* Some channels, for example Microsoft Teams, add at mention details into the text on a message activity. | ||
* This can interfer with later processing. This is a helper function to remove the at mention. | ||
* Typically this would be used to remove the mention text for the target recipient (the bot usually), though | ||
* it could be called for each member. For example: | ||
* turnContext.Activity.RemoveMentionText(turnContext.Activity.Recipient.Id); | ||
* | ||
* The format of a mention Activity.Entity is dependent on the Channel. But in all cases we | ||
* expect the Mention.Text to contain the exact text for the user as it appears in | ||
* Activity.Text. | ||
* | ||
* For example, Teams uses "<at>username</at>", whereas slack use "@username". It | ||
* is expected that text is in Activity.Text and this method will remove that value from | ||
* Activity.Text. | ||
* | ||
* ```JavaScript | ||
@@ -66,11 +74,6 @@ * const updatedText = TurnContext.removeRecipientMention(context.request); | ||
static removeMentionText(activity, id) { | ||
var mentions = TurnContext.getMentions(activity); | ||
for (var i = 0; i < mentions.length; i++) { | ||
if (mentions[i].mentioned.id === id) { | ||
var mentionNameMatch = mentions[i].text.match(/(?<=<at.*>)(.*?)(?=<\/at>)/i); | ||
if (mentionNameMatch.length > 0) { | ||
activity.text = activity.text.replace(mentionNameMatch[0], ''); | ||
activity.text = activity.text.replace(/<at><\/at>/g, ''); | ||
} | ||
} | ||
const mentions = TurnContext.getMentions(activity); | ||
const mentionsFiltered = mentions.filter((mention) => mention.mentioned.id === id); | ||
if (mentionsFiltered.length) { | ||
activity.text = activity.text.replace(mentionsFiltered[0].text, '').trim(); | ||
} | ||
@@ -264,3 +267,5 @@ return activity.text; | ||
updateActivity(activity) { | ||
return this.emit(this._onUpdateActivity, activity, () => this.adapter.updateActivity(this, activity)); | ||
const ref = TurnContext.getConversationReference(this.activity); | ||
const a = TurnContext.applyConversationReference(activity, ref); | ||
return this.emit(this._onUpdateActivity, a, () => this.adapter.updateActivity(this, a)); | ||
} | ||
@@ -267,0 +272,0 @@ /** |
@@ -5,3 +5,3 @@ { | ||
"description": "Core components for Microsoft Bot Builder. Components in this library can run either in a browser or on the server.", | ||
"version": "4.5.3", | ||
"version": "4.6.0-preview1", | ||
"license": "MIT", | ||
@@ -25,3 +25,3 @@ "keywords": [ | ||
"assert": "^1.4.1", | ||
"botframework-schema": "^4.5.3" | ||
"botframework-schema": "^4.6.0-preview1" | ||
}, | ||
@@ -41,3 +41,3 @@ "devDependencies": { | ||
"clean": "erase /q /s .\\lib", | ||
"set-version": "npm version --allow-same-version 4.5.3" | ||
"set-version": "npm version --allow-same-version 4.6.0-preview1" | ||
}, | ||
@@ -44,0 +44,0 @@ "files": [ |
@@ -8,3 +8,4 @@ /** | ||
*/ | ||
import { Activity, ActivityTypes, TurnContext } from '.'; | ||
import { ChannelAccount, MessageReaction, TurnContext } from '.'; | ||
import { ActivityHandlerBase } from './activityHandlerBase'; | ||
@@ -58,4 +59,4 @@ export type BotHandler = (context: TurnContext, next: () => Promise<void>) => Promise<any>; | ||
*/ | ||
export class ActivityHandler { | ||
private readonly handlers: {[type: string]: BotHandler[]} = {}; | ||
export class ActivityHandler extends ActivityHandlerBase { | ||
protected readonly handlers: {[type: string]: BotHandler[]} = {}; | ||
@@ -214,16 +215,198 @@ /** | ||
public async run(context: TurnContext): Promise<void> { | ||
await super.run(context); | ||
} | ||
if (!context) { | ||
throw new Error(`Missing TurnContext parameter`); | ||
/** | ||
* Overwrite this method to use different logic than the default initial Activity processing logic. | ||
* @remarks | ||
* The default logic is below: | ||
* ```ts | ||
* await this.handle(context, 'Turn', async () => { | ||
* await super.onTurnActivity(context); | ||
* }); | ||
* ``` | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
protected async onTurnActivity(context: TurnContext): Promise<void> { | ||
await this.handle(context, 'Turn', async () => { | ||
await super.onTurnActivity(context); | ||
}); | ||
} | ||
/** | ||
* Runs all `onMesssage()` handlers before calling the `ActivityHandler.defaultNextEvent()`. | ||
* @remarks | ||
* Developers may overwrite this method when having supporting multiple channels to have a | ||
* channel-tailored experience. | ||
* @remarks | ||
* The default logic is below: | ||
* ```ts | ||
* await await this.handle(context, 'Message', this.defaultNextEvent(context)); | ||
* ``` | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
protected async onMessageActivity(context: TurnContext): Promise<void> { | ||
await this.handle(context, 'Message', this.defaultNextEvent(context)); | ||
} | ||
/** | ||
* Runs all `onUnrecognizedActivityType()` handlers before calling `ActivityHandler.dispatchConversationUpdateActivity()`. | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
protected async onUnrecognizedActivity(context: TurnContext): Promise<void> { | ||
await this.handle(context, 'UnrecognizedActivityType', this.defaultNextEvent(context)); | ||
} | ||
/** | ||
* Runs all `onConversationUpdate()` handlers before calling `ActivityHandler.dispatchConversationUpdateActivity()`. | ||
* @remarks | ||
* The default logic is below: | ||
* ```ts | ||
* await this.handle(context, 'ConversationUpdate', async () => { | ||
* await this.dispatchConversationUpdateActivity(context); | ||
* }); | ||
* ``` | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
protected async onConversationUpdateActivity(context: TurnContext): Promise<void> { | ||
await this.handle(context, 'ConversationUpdate', async () => { | ||
await this.dispatchConversationUpdateActivity(context); | ||
}); | ||
} | ||
/** | ||
* Override this method when dispatching off of a `'ConversationUpdate'` event to trigger other sub-events. | ||
* @remarks | ||
* The default logic is below: | ||
* ```ts | ||
* if (context.activity.membersAdded && context.activity.membersAdded.length > 0) { | ||
* await this.handle(context, 'MembersAdded', this.defaultNextEvent(context)); | ||
* } else if (context.activity.membersRemoved && context.activity.membersRemoved.length > 0) { | ||
* await this.handle(context, 'MembersRemoved', this.defaultNextEvent(context)); | ||
* } else { | ||
* await this.defaultNextEvent(context)(); | ||
* } | ||
* ``` | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
protected async dispatchConversationUpdateActivity(context: TurnContext): Promise<void> { | ||
if (context.activity.membersAdded && context.activity.membersAdded.length > 0) { | ||
await this.handle(context, 'MembersAdded', this.defaultNextEvent(context)); | ||
} else if (context.activity.membersRemoved && context.activity.membersRemoved.length > 0) { | ||
await this.handle(context, 'MembersRemoved', this.defaultNextEvent(context)); | ||
} else { | ||
await this.defaultNextEvent(context)(); | ||
} | ||
} | ||
if (!context.activity) { | ||
throw new Error(`TurnContext does not include an activity`); | ||
/** | ||
* Runs all `onMessageReaction()` handlers before calling `ActivityHandler.dispatchMessageReactionActivity()`. | ||
* @remarks | ||
* The default logic is below: | ||
* ```ts | ||
* await this.handle(context, 'MessageReaction', async () => { | ||
* await this.dispatchMessageReactionActivity(context); | ||
* }); | ||
* ``` | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
protected async onMessageReactionActivity(context: TurnContext): Promise<void> { | ||
await this.handle(context, 'MessageReaction', async () => { | ||
await this.dispatchMessageReactionActivity(context); | ||
}); | ||
} | ||
/** | ||
* | ||
* @param reactionsAdded The list of reactions added | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
protected async onReactionsAddedActivity(reactionsAdded: MessageReaction[], context: TurnContext): Promise<void> { | ||
await this.handle(context, 'ReactionsAdded', this.defaultNextEvent(context)); | ||
} | ||
/** | ||
* | ||
* @param reactionsRemoved The list of reactions removed | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
protected async onReactionsRemovedActivity(reactionsRemoved: MessageReaction[], context: TurnContext): Promise<void> { | ||
await this.handle(context, 'ReactionsRemoved', this.defaultNextEvent(context)); | ||
} | ||
/** | ||
* Override this method when dispatching off of a `'MessageReaction'` event to trigger other sub-events. | ||
* @remarks | ||
* If there are no reactionsAdded or reactionsRemoved on the incoming activity, it will call `this.defaultNextEvent` | ||
* which emits the `'Dialog'` event by default. | ||
* The default logic is below: | ||
* ```ts | ||
* if (context.activity.reactionsAdded || context.activity.reactionsRemoved) { | ||
* super.onMessageReactionActivity(context); | ||
* } else { | ||
* await this.defaultNextEvent(context)(); | ||
* } | ||
* ``` | ||
* `super.onMessageReactionActivity()` will dispatch to `onReactionsAddedActivity()` | ||
* or `onReactionsRemovedActivity()`. | ||
* | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
protected async dispatchMessageReactionActivity(context: TurnContext): Promise<void> { | ||
if (context.activity.reactionsAdded || context.activity.reactionsRemoved) { | ||
await super.onMessageReactionActivity(context); | ||
} else { | ||
await this.defaultNextEvent(context)(); | ||
} | ||
} | ||
if (!context.activity.type) { | ||
throw new Error(`Activity is missing it's type`); | ||
/** | ||
* Runs all `onEvent()` handlers before calling `ActivityHandler.dispatchEventActivity()`. | ||
* @remarks | ||
* The default logic is below: | ||
* ```ts | ||
* await this.handle(context, 'Event', async () => { | ||
* await this.dispatchEventActivity(context); | ||
* }); | ||
* ``` | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
protected async onEventActivity(context: TurnContext): Promise<void> { | ||
await this.handle(context, 'Event', async () => { | ||
await this.dispatchEventActivity(context); | ||
}); | ||
} | ||
/** | ||
* Override this method when dispatching off of a `'Event'` event to trigger other sub-events. | ||
* @remarks | ||
* For certain channels (e.g. Web Chat, custom Direct Line clients), developers can emit | ||
* custom `'event'`-type activities from the client. Developers should then overwrite this method | ||
* to support their custom `'event'` activities. | ||
* | ||
* The default logic is below: | ||
* ```ts | ||
* if (context.activity.name === 'tokens/response') { | ||
* await this.handle(context, 'TokenResponseEvent', this.defaultNextEvent(context)); | ||
* } else { | ||
* await this.defaultNextEvent(context)(); | ||
* } | ||
* ``` | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
protected async dispatchEventActivity(context: TurnContext): Promise<void> { | ||
if (context.activity.name === 'tokens/response') { | ||
await this.handle(context, 'TokenResponseEvent', this.defaultNextEvent(context)); | ||
} else { | ||
await this.defaultNextEvent(context)(); | ||
} | ||
// Allow the dialog system to be triggered at the end of the chain | ||
} | ||
/** | ||
* Returns an async function that emits the `'Dialog'` event when called. | ||
* Overwrite this function to emit a different default event once all relevant | ||
* events are emitted. | ||
* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter | ||
*/ | ||
protected defaultNextEvent(context: TurnContext): () => Promise<void> { | ||
const runDialogs = async (): Promise<void> => { | ||
@@ -234,55 +417,12 @@ await this.handle(context, 'Dialog', async () => { | ||
}; | ||
// List of all Activity Types: | ||
// https://github.com/Microsoft/botbuilder-js/blob/master/libraries/botframework-schema/src/index.ts#L1627 | ||
await this.handle(context, 'Turn', async () => { | ||
switch (context.activity.type) { | ||
case ActivityTypes.Message: | ||
await this.handle(context, 'Message', runDialogs); | ||
break; | ||
case ActivityTypes.ConversationUpdate: | ||
await this.handle(context, 'ConversationUpdate', async () => { | ||
if (context.activity.membersAdded && context.activity.membersAdded.length > 0) { | ||
await this.handle(context, 'MembersAdded', runDialogs); | ||
} else if (context.activity.membersRemoved && context.activity.membersRemoved.length > 0) { | ||
await this.handle(context, 'MembersRemoved', runDialogs); | ||
} else { | ||
await runDialogs(); | ||
} | ||
}); | ||
break; | ||
case ActivityTypes.MessageReaction: | ||
await this.handle(context, 'MessageReaction', async () => { | ||
if (context.activity.reactionsAdded && context.activity.reactionsAdded.length > 0) { | ||
await this.handle(context, 'ReactionsAdded', runDialogs); | ||
} else if (context.activity.reactionsRemoved && context.activity.reactionsRemoved.length > 0) { | ||
await this.handle(context, 'ReactionsRemoved', runDialogs); | ||
} else { | ||
await runDialogs(); | ||
} | ||
}); | ||
break; | ||
case ActivityTypes.Event: | ||
await this.handle(context, 'Event', async () => { | ||
if (context.activity.name === 'tokens/response') { | ||
await this.handle(context, 'TokenResponseEvent', runDialogs); | ||
} else { | ||
await runDialogs(); | ||
} | ||
}); | ||
break; | ||
default: | ||
// handler for unknown or unhandled types | ||
await this.handle(context, 'UnrecognizedActivityType', runDialogs); | ||
break; | ||
} | ||
}); | ||
return runDialogs; | ||
} | ||
/** | ||
* Private method used to bind handlers to events by name | ||
* Used to bind handlers to events by name | ||
* @param type string | ||
* @param handler BotHandler | ||
*/ | ||
private on(type: string, handler: BotHandler) { | ||
protected on(type: string, handler: BotHandler) { | ||
if (!this.handlers[type]) { | ||
@@ -297,7 +437,7 @@ this.handlers[type] = [handler]; | ||
/** | ||
* Private method used to fire events and execute any bound handlers | ||
* Used to fire events and execute any bound handlers | ||
* @param type string | ||
* @param handler BotHandler | ||
*/ | ||
private async handle(context: TurnContext, type: string, onNext: () => Promise<void>): Promise<any> { | ||
protected async handle(context: TurnContext, type: string, onNext: () => Promise<void>): Promise<any> { | ||
let returnValue: any = null; | ||
@@ -326,3 +466,2 @@ | ||
} | ||
} |
@@ -12,5 +12,10 @@ /** | ||
/** | ||
* An interface components can use to read and write individual properties to the bot's state | ||
* management system. | ||
* @param T (Optional) type of property being persisted. Defaults to `any` type. | ||
* Defines methods for accessing a state property created in a | ||
* [BotState](xref:botbuilder-core.BotState) object. | ||
* | ||
* @typeparam T Optional. The type of the state property to access. Default type is `any`. | ||
* | ||
* @remarks | ||
* To create a state property in a state management objet, use the | ||
* [createProperty\<T>](xref:botbuilder-core.BotState.createProperty) method. | ||
*/ | ||
@@ -17,0 +22,0 @@ export interface StatePropertyAccessor<T = any> { |
@@ -8,3 +8,3 @@ /** | ||
*/ | ||
import { ActionTypes, AnimationCard, Attachment, AudioCard, CardAction, CardImage, HeroCard, MediaUrl, OAuthCard, ReceiptCard, SigninCard, ThumbnailCard, VideoCard } from 'botframework-schema'; | ||
import { ActionTypes, AnimationCard, Attachment, AudioCard, CardAction, CardImage, HeroCard, MediaUrl, OAuthCard, O365ConnectorCard, ReceiptCard, SigninCard, ThumbnailCard, VideoCard } from 'botframework-schema'; | ||
@@ -44,2 +44,3 @@ /** | ||
oauthCard: 'application/vnd.microsoft.card.oauth', | ||
o365ConnectorCard: 'application/vnd.microsoft.teams.card.o365connector', | ||
signinCard: 'application/vnd.microsoft.card.signin', | ||
@@ -185,3 +186,29 @@ thumbnailCard: 'application/vnd.microsoft.card.thumbnail', | ||
/** | ||
* Returns an attachment for an 0365Connector card. | ||
* | ||
* @remarks | ||
* ```JavaScript | ||
* const card = CardFactory.o365ConnectorCard({ | ||
* "title": "card title", | ||
* "text": "card text", | ||
* "summary": "O365 card summary", | ||
* "themeColor": "#E67A9E", | ||
* "sections": [ | ||
* { | ||
* "title": "**section title**", | ||
* "text": "section text", | ||
* "activityTitle": "activity title", | ||
* } | ||
* ] | ||
* }); | ||
* ``` | ||
* @param card The o365Connector card to return as an attachment. | ||
*/ | ||
public static o365ConnectorCard(card: O365ConnectorCard): Attachment { | ||
return { contentType: CardFactory.contentTypes.o365ConnectorCard, content: card }; | ||
} | ||
/** | ||
* Returns an attachment for a receipt card. | ||
@@ -188,0 +215,0 @@ * @param card The adaptive card to return as an attachment. |
@@ -11,2 +11,3 @@ /** | ||
export * from './activityHandler'; | ||
export * from './activityHandlerBase'; | ||
export * from './autoSaveStateMiddleware'; | ||
@@ -29,2 +30,3 @@ export * from './botAdapter'; | ||
export * from './showTypingMiddleware'; | ||
export * from './skypeMentionNormalizeMiddleware'; | ||
export * from './storage'; | ||
@@ -31,0 +33,0 @@ export * from './telemetryLoggerMiddleware'; |
@@ -23,3 +23,3 @@ /** | ||
// Ensure proxy supported (some browsers don't) | ||
if (Proxy && Proxy.revocable) { | ||
if (typeof Proxy !== 'undefined' && Proxy.revocable) { | ||
return Proxy.revocable(target, handler || {}); | ||
@@ -26,0 +26,0 @@ } else { |
@@ -52,4 +52,13 @@ /** | ||
const responses: ResourceResponse[] = await next2(); | ||
activities.forEach((a: ResourceResponse) => this.logActivity(transcript, this.cloneActivity(a))); | ||
activities.map((a: Partial<Activity>, index: number) => { | ||
const clonedActivity = this.cloneActivity(a); | ||
if (index < responses.length) { | ||
if (!clonedActivity.id) { | ||
clonedActivity.id = responses[index].id; | ||
} | ||
} | ||
this.logActivity(transcript, clonedActivity); | ||
}); | ||
return responses; | ||
@@ -142,9 +151,9 @@ }); | ||
*/ | ||
private transcriptLoggerErrorHandler(err: Error|any): void { | ||
private transcriptLoggerErrorHandler(err: Error | any): void { | ||
// tslint:disable:no-console | ||
if (err instanceof Error) { | ||
console.error(`TranscriptLoggerMiddleware logActivity failed: "${ err.message }"`); | ||
console.error(`TranscriptLoggerMiddleware logActivity failed: "${err.message}"`); | ||
console.error(err.stack); | ||
} else { | ||
console.error(`TranscriptLoggerMiddleware logActivity failed: "${ JSON.stringify(err) }"`); | ||
console.error(`TranscriptLoggerMiddleware logActivity failed: "${JSON.stringify(err)}"`); | ||
} | ||
@@ -151,0 +160,0 @@ // tslint:enable:no-console |
@@ -100,9 +100,17 @@ /** | ||
/** | ||
* Rewrites the activity text without any at mention. Specifying a particular recipient id. | ||
* Use with caution because this function is altering the text on the Activity. | ||
* Remove any mention text for given id from the Activity.Text property. For example, given the message | ||
* "@echoBot Hi Bot", this will remove "@echoBot", leaving "Hi Bot". | ||
* | ||
* @remarks | ||
* Some channels, for example Microsoft Teams, add at mention details into the text on a message activity. | ||
* This can interfer with later processing. This is a helper function to remove the at mention. | ||
* | ||
* Typically this would be used to remove the mention text for the target recipient (the bot usually), though | ||
* it could be called for each member. For example: | ||
* turnContext.Activity.RemoveMentionText(turnContext.Activity.Recipient.Id); | ||
* | ||
* The format of a mention Activity.Entity is dependent on the Channel. But in all cases we | ||
* expect the Mention.Text to contain the exact text for the user as it appears in | ||
* Activity.Text. | ||
* | ||
* For example, Teams uses "<at>username</at>", whereas slack use "@username". It | ||
* is expected that text is in Activity.Text and this method will remove that value from | ||
* Activity.Text. | ||
* | ||
* ```JavaScript | ||
@@ -115,11 +123,6 @@ * const updatedText = TurnContext.removeRecipientMention(context.request); | ||
public static removeMentionText(activity: Partial<Activity>, id: string): string { | ||
var mentions = TurnContext.getMentions(activity); | ||
for (var i=0; i<mentions.length; i++) { | ||
if (mentions[i].mentioned.id === id) { | ||
var mentionNameMatch = mentions[i].text.match(/(?<=<at.*>)(.*?)(?=<\/at>)/i); | ||
if (mentionNameMatch.length > 0) { | ||
activity.text = activity.text.replace(mentionNameMatch[0], ''); | ||
activity.text = activity.text.replace(/<at><\/at>/g, ''); | ||
} | ||
} | ||
const mentions = TurnContext.getMentions(activity); | ||
const mentionsFiltered = mentions.filter((mention): boolean => mention.mentioned.id === id); | ||
if (mentionsFiltered.length) { | ||
activity.text = activity.text.replace(mentionsFiltered[0].text, '').trim(); | ||
} | ||
@@ -322,3 +325,5 @@ return activity.text; | ||
public updateActivity(activity: Partial<Activity>): Promise<void> { | ||
return this.emit(this._onUpdateActivity, activity, () => this.adapter.updateActivity(this, activity)); | ||
const ref: Partial<ConversationReference> = TurnContext.getConversationReference(this.activity); | ||
const a: Partial<Activity> = TurnContext.applyConversationReference(activity, ref); | ||
return this.emit(this._onUpdateActivity, a, () => this.adapter.updateActivity(this, a)); | ||
} | ||
@@ -325,0 +330,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
508670
122
10860
2