Bot built with MS Bot SDK 4 quites working for facebook channel after an hour or more of idle time

扶醉桌前 提交于 2021-01-29 21:25:02

问题


There are several questions here and on git for v3 of the bot sdk wherein the bot gets 'unauthorized' responses after about an hour on my facebook channel, webchat works fine.

I have that problem in the v4 SDK, using .net core 2.1, AspNetCore 2.1.6 and using something trivial like the echobot c# example. It is not clear to me if the unauthorized is coming from microsofts bot framework, or from facebook itself.

Below is my code and the trace... Note that the failure appears to come out of : Microsoft.Bot.Builder.Integration.IAdapterIntegration.

My code: for the reply:

public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
{
    if (turnContext.Activity.Type == ActivityTypes.Message)
    {
        _logger.LogInformation("OnTurnAsync got message");
        try
        {
           _logger.LogInformation("create activity");
           Activity reply = turnContext.Activity.CreateReply();
           _logger.LogInformation("send simple message");
           await turnContext.SendActivityAsync("hello world");
...

the trace:

[Information] CISBaseBot.CISBaseBot: OnTurnAsync got message
[Information] CISBaseBot.CISBaseBot: create activity
[Information] CISBaseBot.CISBaseBot: send simple message
[Information] Microsoft.Bot.Builder.Integration.IAdapterIntegration: Sending activity.  ReplyToId: TaqxSedy0NHkuz6v2d1SSDBtz0lj6KSn5cH__9maU0vjkxJiCcGelCs0gM-p7raz4eATFN1XtVpWMb_RYGQIFg
[Trace] CISBaseBot.CISBaseBot: Operation returned an invalid status code 'Unauthorized'
[Debug] Microsoft.AspNetCore.Server.Kestrel: Connection id "0HLIRTMBEP9BP" completed keep alive response.

Hugely appreciate any help in advance... based on my reading it appears to be an expired token but I have been unable to find how to refresh the token in the V4 SDK.


回答1:


Ok, so I decided I had better check the facebook side here and sure enough there are several Stack questions about expiring page or user tokens. To make the bot authenticate again I had to do this:

1) I regened the facebook page token (using the Messenger/settings/tokens on the fb developer portal NOT the graph API explorer which I had problems with) and then updated that in the facebook channel in the MS bot 2) On the fb for developers Dashboard for the page, under webhooks/edit subscription, I pasted the 'verify token' from the bot page on azure into the verification dialog and resubmitted.

The bot then started working(no restart, just that one update in azure/bot/channel). This question deals with the access tokens out of the bot context but for sure its in the same general top of 'authenticating facebook pages and users and apps'.

Facebook Page Access Tokens - Do these expire? Facebook Page Access Tokens - Do these expire?



来源:https://stackoverflow.com/questions/53662567/bot-built-with-ms-bot-sdk-4-quites-working-for-facebook-channel-after-an-hour-or

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!