1
votes

protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken) { //I have code here that works fine. }

Second Method

public QnABot(IConfiguration configuration, ILogger<QnABot> logger, IHttpClientFactory httpClientFactory)
    {
        _configuration = configuration;
        _logger = logger;
        _httpClientFactory = httpClientFactory;
    }


    protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
    {
        var httpClient = _httpClientFactory.CreateClient();

        var qnaMaker = new QnAMaker(new QnAMakerEndpoint
        {
            KnowledgeBaseId = _configuration["QnAKnowledgebaseId"],
            EndpointKey = _configuration["QnAAuthKey"],
            Host = GetHostname()
        },
        null,
        httpClient);

        _logger.LogInformation("Calling QnA Maker");

        // The actual call to the QnA Maker service.
        var response = await qnaMaker.GetAnswersAsync(turnContext);
        if (response != null && response.Length > 0)
        {
            await turnContext.SendActivityAsync(MessageFactory.Text(response[0].Answer), cancellationToken);
        }
        else
        {
            await turnContext.SendActivityAsync(MessageFactory.Text("No QnA Maker answers were found."), cancellationToken);
        }
    }

Error: 'Type QnABot' already defines a member called 'OnMessageActivityAsync' with the same parameter types.

I have used a third party API with my bot using the HTTP Client. Now, I want to add the QnA maker to my bot. The thing is i only want the user to use the API when they need to and the QnA maker for a different reason. Basically, the QnA maker has the information for specific apps that we use at my company. The API knowledge base however answers natural language questions like ‘How do I install outlook on my iPhone?’ So this is the matter for the user being able to choose if they want specific app information from the QnA maker or ask a ‘how to’ question from the API.

I already made a QnA bot as well. I have the code for the QnA maker and now I was trying to implement both my web api code and the qna maker code together. I have used my logic from the API to use it with my QnAbot.cs file but I am getting this OnMessageActivityAsync error. Obviously because I have two of those and the program doesn’t know when to access which method. So how do I set both these methods apart?

Getting "OnMessageActivityAsync" error as I have two of those methods and I don't know how to differentiate between the two. I need the bot to be able to query either the API or the QnA maker, not together.This is my first OnMessageActivityAsync second on messageactivity which gives me an error

1
You gave us only the function/part of hte code the compiler has an issue with. You did not actually tell us what the error message is.Christopher

1 Answers

0
votes

The message is pretty clear. You got the same function with the same arguments twice. That is not allowed. Multiple functions with the same name area allowed, but only within the overloading rules - wich requires the arguments to be different, so the compiler can keep them appart.

Based on the name, those are event handlers the signature is fixed. That means they need to varry on the name.

I see these options:

1) You manually define and register one of the two. That way you can define the name

2) Delte both, give the elements you register them to a name in the designer. Then try implementing them again - the name of the element should be used as prefix.

3) Is not availible here, as those events do not follow the proper event handler pattern.

I would advise learning how to manually do event registering and definition. You can not rely on the Designer help forever.