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