Skip to content

Setup Webhook

Eana Hufwe edited this page Nov 20, 2021 · 4 revisions

Written for EFB Telegram Master 2.2.4

ETM 2.x now supports using webhook to power your Telegram bot instead of polling.

As webhooks can be configured in multiple different ways depending on your server condition, we currently only support the 2 most basic webhook configurations, as introduced by python-telegram-bot: "integrated webhook server", and "reverse proxy + integrated webhook server".

If you need a more customised webhook configuration, you can always create a local channel by extending the existing ETM classes, and override relevant methods.

To enable webhook in ETM, simply add a webhook section in the end of config.yaml.

Examples

The following examples are adopted from Python Telegram Bot wiki, licensed under CC-BY 3.0.

Integrated webhook server

If the bot is configured like this in Python...

updater.start_webhook(listen='0.0.0.0',
                      port=8443,
                      url_path='TOKEN',
                      key='/home/username/private.key',
                      cert='/home/username/cert.pem',
                      webhook_url='https://example.com:8443/TOKEN')

It can be configured like this in ETM...

webhook:
    start_webhook:
        listen: 0.0.0.0
        port: 8843
        url_path: TOKEN
        key: /home/username/private.key
        cert: /home/username/cert.pem
        webhook_url: https://example.com:8443/TOKEN

Reverse proxy + integrated webhook server

If the bot is configured like this in Python...

updater.start_webhook(listen='127.0.0.1', port=5000, url_path='TOKEN',
                      webhook_url ='https://bot1.example.com/TOKEN',
                      cert=open('/home/username/cert_bot1.pem', 'rb'))

It can be configured like this in ETM...

webhook:
    start_webhook:
        webhook_url: https://bot1.example.com/TOKEN
        cert: /home/username/cert_bot1.pem
        listen: 127.0.0.1
        port: 5000
        url_path: TOKEN

For details on how to set up a webhook, please refer to the detailed tutorial from python-telegram-bot.