mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Fix certificate for webhooks
This commit is contained in:
parent
140befc132
commit
f8f147f9f4
@ -26,6 +26,8 @@ import string
|
|||||||
# webhooks module
|
# webhooks module
|
||||||
from telebot.extensions import SyncWebhookListener
|
from telebot.extensions import SyncWebhookListener
|
||||||
|
|
||||||
|
import ssl
|
||||||
|
|
||||||
logger = logging.getLogger('TeleBot')
|
logger = logging.getLogger('TeleBot')
|
||||||
|
|
||||||
formatter = logging.Formatter(
|
formatter = logging.Formatter(
|
||||||
@ -350,10 +352,17 @@ class TeleBot:
|
|||||||
if not webhook_url:
|
if not webhook_url:
|
||||||
webhook_url = "{}://{}:{}/{}".format(protocol, listen, port, url_path)
|
webhook_url = "{}://{}:{}/{}".format(protocol, listen, port, url_path)
|
||||||
|
|
||||||
|
if certificate and certificate_key:
|
||||||
|
ssl_ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
|
||||||
|
ssl_ctx.load_cert_chain(certificate, certificate_key)
|
||||||
|
else:
|
||||||
|
ssl_ctx = None
|
||||||
|
|
||||||
|
# open certificate if it exists
|
||||||
|
cert_file = open(certificate, 'rb') if certificate else None
|
||||||
self.set_webhook(
|
self.set_webhook(
|
||||||
url=webhook_url,
|
url=webhook_url,
|
||||||
certificate=certificate,
|
certificate=cert_file,
|
||||||
max_connections=max_connections,
|
max_connections=max_connections,
|
||||||
allowed_updates=allowed_updates,
|
allowed_updates=allowed_updates,
|
||||||
ip_address=ip_address,
|
ip_address=ip_address,
|
||||||
@ -361,6 +370,7 @@ class TeleBot:
|
|||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
secret_token=secret_token
|
secret_token=secret_token
|
||||||
)
|
)
|
||||||
|
if cert_file: cert_file.close()
|
||||||
|
|
||||||
ssl_context = (certificate, certificate_key) if certificate else None
|
ssl_context = (certificate, certificate_key) if certificate else None
|
||||||
self.webhook_listener = SyncWebhookListener(self, secret_token, listen, port, ssl_context, '/'+url_path, debug)
|
self.webhook_listener = SyncWebhookListener(self, secret_token, listen, port, ssl_context, '/'+url_path, debug)
|
||||||
|
Loading…
Reference in New Issue
Block a user