"Unable to reach app." error with successful login for MS Teams using the Bot Builder Framework

Sumabat, Gabriel 1 Reputation point
2022-07-13T13:50:58.827+00:00

When using Python with the BotBuilderFramework to display the OAuthPrompt, the Authentication Sign In Card is displayed.
This card is part of Microsoft's python botbuilder-dialogs==4.14.2 and is used to handle all the Oauth authentication.

The login itself does succeed and return a correct token, but an error message is displayed on the Login card itself saying "Unable to reach app. Please try again."

220482-image.png

Although it claims it was unable to reach the app, the rest of the waterfall workflow was kicked off successfully and I can see my successful login function being called if I run my debugger.
I do not see any error thrown from my API and am not able to see any error thrown in the bot logs.

Why is it unable to reach my app? How do I prevent this error message from appearing?

Azure AI Bot Service
Azure AI Bot Service
An Azure service that provides an integrated environment for bot development.
833 questions
{count} votes

6 answers

Sort by: Most helpful
  1. Anonymous
    2022-11-22T13:47:54.933+00:00

    After some debugging found real reason for that behavior.

    The botframework responds to activity, by only setting the code 200 ok. But body is None by default

            await context.send_activity(  
                Activity(  
                    type="invokeResponse",  
                    value=InvokeResponse(status=HTTPStatus.OK),  
                )  
            )  
    

    botbuilder/dialogs/prompts/oauth_prompt.py:430

    Here it's got body=invoke_response.value.body where body is None

    return InvokeResponse(  
                status=invoke_response.value.status, body=invoke_response.value.body,  
            )  
    

    botbuilder/core/bot_framework_adapter.py:514

    Then later in code this activity got dumped into json. And body=None becomes body=b'null'

    See aiohttp.web_response.json_response

    Looks like some bug ether in samples or in botframework.

    Workaround is to prevent dumping None as null

    # Listen for incoming requests on /api/messages  
    async def messages(req: Request) -> Response:  
        # Main bot message handler.  
        if "application/json" in req.headers["Content-Type"]:  
            body = await req.json()  
        else:  
            return Response(status=415)  
      
        activity = Activity().deserialize(body)  
        auth_header = req.headers["Authorization"] if "Authorization" in req.headers else ""  
      
        response = await ADAPTER.process_activity(activity, auth_header, BOT.on_turn)  
        if response:  
            # prevent sending None body as 'null'  
            if response.body is None:  
                args = {'status': response.status}  
            else:  
                args = {'data': response.body, 'status': response.status}  
      
            return json_response(**args)  
        return Response(status=201)  
    
    1 person found this answer helpful.

  2. Sumabat, Gabriel 1 Reputation point
    2022-07-14T15:18:45.51+00:00

    @Prasad-MSFT

    I've run some more tests using the different sample templates.

    Using the following tutorial code I am not seeing the same error with my configuration: https://github.com/microsoft/BotBuilder-Samples/blob/main/samples/python/46.teams-auth/bots/teams_bot.py

    So the difference should be in the code.

    The only method I can see that I was not implementing was:

    async def on_teams_signin_verify_state(self, turn_context: TurnContext):
    # Run the Dialog with the new Token Response Event Activity.
    # The OAuth Prompt needs to see the Invoke Activity in order to complete the login process.
    await DialogHelper.run_dialog(
    self.dialog,
    turn_context,
    self.conversation_state.create_property("DialogState"),
    )

    I've tried adding it into my code, but I'm still not able to resolve the issue.

    Is there somewhere where I can see the error message?
    What is the method expected to return?


  3. Sumabat, Gabriel 1 Reputation point
    2022-07-15T16:48:35.067+00:00

    If it comes from the Adaptive Card how can I resolve this message? It can still reach my API so I'm not clear why this error is being displayed each time a user logs in.


  4. Indy Kaur 1 Reputation point
    2022-09-23T13:54:50.607+00:00

    @Sumabat, Gabriel : I am getting the same. The bot was working fine with app studio but now we converted to developers portal. I cannot login to the bot.

    Please let me know if you resolve this issue.

    244264-image.png

    0 comments No comments

  5. Sumabat, Gabriel 1 Reputation point
    2022-09-23T17:05:44.42+00:00

    You'll probably want to check the Oauth 2 connection you set up to make sure it works.

    My issue is slightly different. Even if this error message appears the login is still successful and proceeds to the next step.

    @Indy Kaur

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.