microsoft / BotFramework-Services

Microsoft Bot Framework Services
Creative Commons Attribution 4.0 International
38 stars 11 forks source link

c# bot stop to work on FB channel #281

Closed Enghouse-CCSP-PS closed 3 years ago

Enghouse-CCSP-PS commented 3 years ago

Version

What package version of the SDK are you using. 3.12.2.4

Describe the bug

suddenly all our FB bot stop to work on FB channel with error Microsoft.Rest.HttpOperationException Facebook API error in app insight we see below log:

Microsoft.Bot.Schema.BotException:
   at Microsoft.Bot.ChannelConnector.BotAPI+<PostActivityToBotAsync>d__35.MoveNext (Microsoft.Bot.Base.ChannelConnector, Version=3.2.3.13, Culture=neutral, PublicKeyToken=nullMicrosoft.Bot.Base.ChannelConnector, Version=3.2.3.13, Culture=neutral, PublicKeyToken=null: D:\a\1\s\ChannelSDK\Microsoft.Bot.Base.ChannelConnector\API\BotAPI.csMicrosoft.Bot.Base.ChannelConnector, Version=3.2.3.13, Culture=neutral, PublicKeyToken=null: 483)
Inner exception System.Exception handled at Microsoft.Bot.ChannelConnector.BotAPI+<PostActivityToBotAsync>d__35.MoveNext:
   at Microsoft.Bot.ChannelConnector.BotAPI.ThrowOnFailedStatusCode (Microsoft.Bot.Base.ChannelConnector, Version=3.2.3.13, Culture=neutral, PublicKeyToken=nullMicrosoft.Bot.Base.ChannelConnector, Version=3.2.3.13, Culture=neutral, PublicKeyToken=null: D:\a\1\s\ChannelSDK\Microsoft.Bot.Base.ChannelConnector\API\BotAPI.csMicrosoft.Bot.Base.ChannelConnector, Version=3.2.3.13, Culture=neutral, PublicKeyToken=null: 640)
   at Microsoft.Bot.ChannelConnector.BotAPI+<PostActivityToBotAsync>d__35.MoveNext (Microsoft.Bot.Base.ChannelConnector, Version=3.2.3.13, Culture=neutral, PublicKeyToken=nullMicrosoft.Bot.Base.ChannelConnector, Version=3.2.3.13, Culture=neutral, PublicKeyToken=null: D:\a\1\s\ChannelSDK\Microsoft.Bot.Base.ChannelConnector\API\BotAPI.csMicrosoft.Bot.Base.ChannelConnector, Version=3.2.3.13, Culture=neutral, PublicKeyToken=null: 465)

To Reproduce

Steps to reproduce the behavior: just start to chat to bot

EricDahlvang commented 3 years ago

Transferring to the BotFramework-Services repo.

Hi @Enghouse-CCSP-PS

I'm not aware of anything which might be causing this, but it seems unlikely to be the Bot Builder sdk.

MichaelHaydenAtMicrosoft commented 3 years ago

@Enghouse-CCSP-PS -

  1. The return call from the send should include FBs error message internally.
  2. Verify your channel config thru FB
  3. Failing the above, please submit a ticket to Azure support with the Bot ID.
v-kydela commented 3 years ago

@Enghouse-CCSP-PS - Can you post any screenshots of what you're seeing in the Messenger window? Is the bot not responding or responding with an error message or what?

Enghouse-CCSP-PS commented 3 years ago

The issue presented itself like this Exception, other than the Facebook API error message not much to go on:

Microsoft.Rest.HttpOperationException: **Facebook API error**
    at Microsoft.Bot.Connector.ErrorHandling.<HandleErrorAsync>d__2`1.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.Bot.Connector.ConversationsExtensions.<ReplyToActivityAsync>d__7.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()

However, we have used the stack-trace to locate that the issue is coming from trying to set the Typing indicator (not new code for us):

var reply = ((Activity)activity).CreateReply();
reply.Type = ActivityTypes.Typing;
await connector.Conversations.ReplyToActivityAsync(reply);

When we comment this section out the subsequent Dialog works fine. I tried adding a 3s delay between Typing and subsequent Dialog, in case related to the speed between the 2 activities, but it seemed throw the same Exception ~0.5s after setting the Typing anyway.

v-kydela commented 3 years ago

@Enghouse-CCSP-PS

That's very strange that typing activities would suddenly start returning errors for you. Facebook typing indicators are working fine for me, and I've tested in a v4 bot and in Postman. It's possible that the problem is unique to the v3 SDK, but you will notice in the readme that v3 has been deprecated and long-term support has ended. There are some other possibilities besides the v3 SDK that could explain what's going wrong. Here are some troubleshooting steps for you to take:

  1. Try running the bot locally in debug mode and tunneling messages from Facebook Messenger to your local machine using something like ngrok. See if you still get the same error, and if you do you can check the error message when execution breaks. Alternatively, you could try reproducing the error in Postman and reading the error message there. You would need to familiarize yourself with the REST API if you haven't already.
  2. In case the fact that it's a typing activity is just a red herring, try changing the typing activity to a normal message activity in that same place in your code and see if you get the same error.
  3. In case the problem has to do with your Facebook app registration or page, try creating a new Facebook app registration and a new Facebook page and connect your bot to them by following the instructions and see if you still get the same error.

Regardless of what happens, the general advice for v3 bots is always to migrate to v4.

v-kydela commented 3 years ago

@Enghouse-CCSP-PS - Are you still working on this?