Skip to content

Commit 02940ff

Browse files
committed
Merge pull request #77 from d-Rickyy-b/dev
Update Webhook config
2 parents 33b4865 + 3840ee4 commit 02940ff

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

config.sample.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
BOT_TOKEN = "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11"
2+
USE_WEBHOOK = False
3+
WEBHOOK_PORT = 9001
4+
WEBHOOK_URL = "https://domain.example.com/" + BOT_TOKEN
5+
CERTPATH = "/etc/certs/example.com/fullchain.cer"

main.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
2+
import json
33
import logging.handlers
44
import os
55
import re
@@ -12,7 +12,7 @@
1212
from telegram.inline.inlinekeyboardmarkup import InlineKeyboardMarkup
1313

1414
import own_filters
15-
from config import BOT_TOKEN
15+
from config import BOT_TOKEN, USE_WEBHOOK, WEBHOOK_PORT, WEBHOOK_URL, CERTPATH
1616
from database.db_wrapper import DBwrapper
1717
from database.statistics import get_user_stats
1818
from game.blackJackGame import BlackJackGame
@@ -35,7 +35,7 @@
3535
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO,
3636
handlers=[logfile_handler])
3737

38-
if not re.match("[0-9]+:[a-zA-Z0-9\-_]+", BOT_TOKEN):
38+
if not re.match(r"[0-9]+:[a-zA-Z0-9\-_]+", BOT_TOKEN):
3939
logging.error("Bot token not correct - please check.")
4040
exit(1)
4141

@@ -150,7 +150,7 @@ def error(bot, update, error):
150150

151151
db = DBwrapper.get_instance()
152152
for admin_id in db.get_admins():
153-
send_message(admin_id, "Update '{0}' caused error '{1}'".format(update, error))
153+
send_message(admin_id, "Update '{0}' caused error '{1}'".format(json.dumps(update.to_dict(), indent=2), error))
154154

155155

156156
def stop_and_restart():
@@ -477,6 +477,11 @@ def restart(bot, update):
477477

478478
dispatcher.add_error_handler(error)
479479

480-
updater.start_polling()
480+
if USE_WEBHOOK:
481+
updater.start_webhook(listen="127.0.0.1", port=WEBHOOK_PORT, url_path=BOT_TOKEN, cert=CERTPATH, webhook_url=WEBHOOK_URL)
482+
updater.bot.set_webhook(WEBHOOK_URL)
483+
else:
484+
updater.start_polling()
485+
481486
logger.info("Bot started as @{}".format(updater.bot.username))
482487
updater.idle()

0 commit comments

Comments
 (0)