Sep 02 2024 05:44 AM - edited Sep 02 2024 05:53 AM
Hi Everyone,
I need help in debugging an issue I am facing while using the Azure bot on the teams channel.
I have created a Teams Meeting bot using the botbuilder framework in python and tested it using the teams toolkit. It works fine using the toolkit. I also used an ngrok domain in the messaging endpoint in the configuration page of the bot and that works too.
Now we took this bot logic and hosted it on AWS ECS. The api/messages endpoint is reachable through postman. But when the request comes from teams, our server just hangs and it becomes unreachable and eventually restarts. I have tried to add some logs and I am able to print the activity, auth header and the request body the teams sends to the API. I have ensured all the env variables are correct. Also, for the server to be reachable from the teams channel to AWS, we had to whitelist a few ips. Only then the server on AWS was reachable.
Steps to reproduce the server restarts.:
1) I zip my manifest file and upload the custom app to a teams meeting.
2) When I add the app to the meeting, it counts as an event and teams calls the api/messages endpoint. I am able to see the logs for this event.
3) After I add the app, I open the custom app tab and the content comes up as expected. The issue starts after this step.
4) I start the meeting, teams sends an event (meetingstart) to the API and then the server just hangs. No logs are printed and then the server restarts and nothing is tracked.
The bot in that meeting does not work anymore. Because when you start a meeting again, the server restarts.
The same thing works fine on local and it checks for these teams events and performs the logic within that function.
We are clueless on what's happening here as there are no logs either. Is there something we need to cross check when trying to host it on a server instead of running it on local using a teams toolkit.?
The request gets sent to
SETTINGS = BotFrameworkAdapterSettings(CONFIG.APP_ID, CONFIG.APP_PASSWORD)
ADAPTER = BotFrameworkAdapter(SETTINGS)
# Listen for incoming requests on /api/messages
@app.post("/api/messages", response_model=None)
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_code=HTTPStatus.UNSUPPORTED_MEDIA_TYPE)
activity = Activity().deserialize(body)
auth_header = req.headers["Authorization"] if "Authorization" in req.headers else ""
print(auth_header)
response = await ADAPTER.process_activity(activity, auth_header, BOT.on_turn)
if response:
return JSONResponse(content=response.body, status_code=response.status)
return Response(status_code=HTTPStatus.OK)
It fails at line 15 I believe, as I have tried to comment the line to see if the restarts happen. It did not restart then. So the issue is clearly with line 15.
Hoping for a reply from anyone. Thank you.
Sep 03 2024 04:13 AM
Sep 04 2024 05:11 AM - edited Sep 04 2024 05:14 AM
Hi @Meghana-MSFT Thanks for the response.
I have an update and more information on the issue. I have pinpointed where it is breaking.
I have the below function in the Activity handler class.
async def on_teams_meeting_start_event(self, meeting, turn_context: TurnContext):
try:
await turn_context.send_activity("Meeting Started")
return
except Exception as e:
return e
It fails at await turn_context.send_activity("Meeting Started"). This line just fails without any logs and I do not get any card on the teams meeting. This also causes the server restarts.
Sep 11 2024 12:37 AM