import { ModelResult } from '@microsoft/recognizers-text' ; import { recognizeHashtag , recognizeMention } from '@microsoft/recognizers-text-sequence' ; import { ActivityTypes , Middleware , TurnContext } from 'botbuilder' ; module export class SocialMediaRecognizer implements Middleware { public defaultLocale ? : string ; public constructor ( defaultLocale ? ) { this . defaultLocale = defaultLocale ; } public async onTurn ( context , next ) { if ( context . activity . type === ActivityTypes . Message ) { const mentions = recognizeMention ( context . activity . text , this . defaultLocale ) ; const hastags = recognizeHashtag ( context . activity . text , this . defaultLocale ) ; const mentionEntities = [ ] ; const hastagEntities = [ ] ; if ( mentions . length > 0 ) { for ( const i of mentions ) { mentionEntities . push ( i . resolution . value ) ; } context . turnState . set ( 'mentionEntities' , mentionEntities ) ; } if ( hastags . length > 0 ) { for ( const i of hastags ) { hastagEntities . push ( i . resolution . value ) ; } context . turnState . set ( 'hastagEntities' , hastagEntities ) ; } } await next ( ) ; } }