OfficeDev / microsoft-teams-faqplusplus-app

DEPRECATED - This repository contains a deprecated version of the FAQ Plus app template. Please see the README file for more details and a link to the new repository
MIT License
48 stars 49 forks source link

Bot not replying #78

Closed DanMcGuinness closed 4 years ago

DanMcGuinness commented 4 years ago

Hey. I've tried a couple times to make the bot work but it always has the same behaviour: I get no response. This is the same if I try from Teams or using 'test in web chat' under bot management in Azure. How can I troubleshoot? Thanks!

himsoni85 commented 4 years ago

I have the same issue. If you browse the BOT's Web App URL (https://xxxxxxxxxxxxxx.azurewebsites.net/api/messages), you will get a 404 error. This is most likely the cause of the issue. Standard troubleshooting requires redeploying the bot. I am still trying to figure how to do that since we deployed this bot through the template. I do not want to redeploy the whole template again.

GeorgianaMihaela commented 4 years ago

It is expected that a browse to the /api/messages to return 404 because the endpoint accepts only POST requests. See this SO thread for detailed explanation: https://stackoverflow.com/questions/50480422/c-sharp-bot-framework-resource-not-found-error

Also, you could test the same thing for a working bot: take the messaging endpoint from the Azure portal and paste it into a browser window. You will have the same outcome: 404.

Example: working bot:

image

and the not found page:

image

GeorgianaMihaela commented 4 years ago

Hi @DanPerfect

For teams:

The bot is responding in teams if the tenantId of your Teams is the same as the one in your Azure subscription.

The code checks the turnContext tenant id to be equal to the id which is present in the appsettings.json and the web.config:

public override Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken)) { if (!this.IsActivityFromExpectedTenant(turnContext)) { this.telemetryClient.TrackTrace($"Unexpected tenant id {turnContext.Activity.Conversation.TenantId}", SeverityLevel.Warning); return Task.CompletedTask; }

https://github.com/OfficeDev/microsoft-teams-faqplusplus-app/blob/master/Source/Microsoft.Teams.Apps.FAQPlusPlus/Bots/FaqPlusPlusBot.cs You could comment out the above if statement and redeploy the bot in Azure using these steps https://social.technet.microsoft.com/wiki/contents/articles/52864.visual-studio-2019-publishing-bot-application-to-azure.aspx

For the test in webchat:

This bot is designed to work in teams, because it does some checks on the conversation type: protected override async Task OnMessageActivityAsync( ITurnContext turnContext, CancellationToken cancellationToken) { try { var message = turnContext.Activity;

            this.telemetryClient.TrackTrace($"Received message activity");
            this.telemetryClient.TrackTrace($"from: {message.From?.Id}, conversation: {message.Conversation.Id}, replyToId: {message.ReplyToId}");

            await this.SendTypingIndicatorAsync(turnContext);

            switch (message.Conversation.ConversationType)
            {
                case "personal":
                    await this.OnMessageActivityInPersonalChatAsync(message, turnContext, cancellationToken);
                    break;

                case "channel":
                    await this.OnMessageActivityInChannelAsync(message, turnContext, cancellationToken);
                    break;

                default:
                    this.telemetryClient.TrackTrace($"Received unexpected conversationType {message.Conversation.ConversationType}", SeverityLevel.Warning);
                    break;
            }
        }

When testing in webchat, this returns null message.Conversation.ConversationType --> null. Thus, the above switch goes to the default branch.

See here the conversationtype example (personal and channel): https://docs.microsoft.com/en-us/microsoftteams/platform/concepts/bots/bots-notifications#schema-example-bot-added-to-team

To troubleshoot, you may download the bot code from here https://github.com/OfficeDev/microsoft-teams-faqplusplus-app Run it locally and add a breakpoint in the OnTurnAsync method, main bot class
Test it using the emulator. Please see this link on how to debug https://docs.microsoft.com/en-us/azure/bot-service/bot-service-debug-bot?view=azure-bot-service-4.0#debug-a-c-bot-using-breakpoints-in-visual-studio

Start by commenting the tenant id validation, if you do not have teams and azure in the same tenant. The bot should work in teams. I did not manage to make it work into the chat, because of the above switch going to the default branch.

Hope this helps.

DanMcGuinness commented 4 years ago

I blew away the bot and started again. This time I'm getting replies. :)