Skip to content

fix: use start_webhook instead of run_webhook for async context#196

Open
Jecvay wants to merge 2 commits intoRichardAtCT:mainfrom
Jecvay:fix/webhook-async-context
Open

fix: use start_webhook instead of run_webhook for async context#196
Jecvay wants to merge 2 commits intoRichardAtCT:mainfrom
Jecvay:fix/webhook-async-context

Conversation

@Jecvay
Copy link
Copy Markdown

@Jecvay Jecvay commented Apr 26, 2026

Summary

  • Replace run_webhook() with start() + start_webhook() to fix "Cannot close a running event loop" error when WEBHOOK_URL is configured
  • run_webhook() internally manages its own event loop, which conflicts with the existing asyncio.run(main()) in src/main.py
  • The new pattern matches how polling mode already uses start_polling() — consistent async lifecycle management
  • Add "webhooks" extra to python-telegram-bot dependency (required by start_webhook())

Test plan

  • Start bot with WEBHOOK_URL set → starts successfully, setWebhook returns 200 OK
  • Start bot without WEBHOOK_URL → polling mode still works as before
  • All 530 existing unit tests pass

🤖 Generated with Claude Code

Jecvay and others added 2 commits April 26, 2026 23:00
run_webhook() manages its own event loop, which conflicts with
asyncio.run() and causes "Cannot close a running event loop" error.
Switch to start() + start_webhook() pattern, matching how polling
mode already uses start_polling().

Also add "webhooks" extra to python-telegram-bot dependency, which
is required by start_webhook().

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Verify that start_webhook is used instead of run_webhook in async
context, and that polling mode is unaffected by the fix.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant