Search code examples
c#methodsbotframeworkoverriding

Is there a way to make this method suitable to override?


i have implemented a transcription feature inside my bot based on the Microsoft Bot Framework v4 (c#). For the storage type i used the Azure Table Storage. Everything works like expected. From there i want that the bot gets the access credentials to the storage strictly from the configuration tab in the App Service.

But then after i implemented this, it says that my method isnt suitable to override anymore.

protected override async Task OnMessageActivityAsync(IConfiguration configuration, ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            // First, we use the dispatch model to determine which cognitive service (LUIS or QnA) to use.
            var recognizerResult = await _botServices.Dispatch.RecognizeAsync(turnContext, cancellationToken);

            // Top intent tell us which cognitive service to use.
            var topIntent = recognizerResult.GetTopScoringIntent();

            // Next, we call the dispatcher with the top intent.
            await DispatchToTopIntentAsync(configuration, turnContext, topIntent.intent, recognizerResult, cancellationToken);
        }

This Error appears after i add the configuration parameter in the OnMessageActivityAsync method. But i need the parameter there because i make use of it inside the DispatchToTopIntentAsync:

// Suche nach der richtigen KnowledgeBase
        private async Task DispatchToTopIntentAsync(IConfiguration configuration, ITurnContext<IMessageActivity> turnContext, string intent, RecognizerResult recognizerResult, CancellationToken cancellationToken)
        {
            switch (intent)
            {
                case "q_SEKAI_Allgemein":
                    await ProcessSEKAI_AllgemeinAsync(configuration, turnContext, cancellationToken);
                    break;
                case "q_SEKAI_HomeOffice":
                    await ProcessSEKAI_HomeOfficeAsync(configuration, turnContext, cancellationToken);
                    break;
                case "q_SEKAI_MixedReality":
                    await ProcessSEKAI_MixedRealityAsync(configuration, turnContext, cancellationToken);
                    break;

                default:
                    // Wird ausgeführt, wenn keine KnowledgeBase gefunden wird
                    _logger.LogInformation($"Dispatch unrecognized intent: {intent}.");

                    await TableStorageEintrag(configuration, turnContext, cancellationToken);
                    break;
            }
        }

In this part the bot decids which KnowledgeBase fits the best for further work.

But how can i fix this issue? Feel free to ask if you need more informations. I will then edit my post asap :)

enter image description here

(This screenshot refers to a answer from this post)


Solution

  • You can not change the parameters of a base virtual class and expect to override it. The correct signature is as follows, given on MSDN

    protected virtual Task OnMessageActivityAsync(
        ITurnContext<IMessageActivity> turnContext,
        CancellationToken cancellationToken);
    

    Can you inject IConfigration at the consturctor of your class

    private readonly IConfiguration _iConfiguration;
    // Inject it here
    public ConstructorOfYourClass(IConfiguration iConfiguration) {
        _iConfiguration = iConfiguration;
    }
    
    protected override async Task OnMessageActivityAsync(
        ITurnContext<IMessageActivity> turnContext,
        CancellationToken cancellationToken) {
            .......
        // Use it here
        await DispatchToTopIntentAsync(_iConfiguration, turnContext, topIntent.intent, recognizerResult, cancellationToken);
    }