-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_bot_web.py
More file actions
46 lines (31 loc) · 1.11 KB
/
start_bot_web.py
File metadata and controls
46 lines (31 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""
start_bot_web.py
Starts the bot process hosted on a remote server, after initialising and registering handlers.
"""
from telegram.ext import Updater, PicklePersistence
import logging
import os
# Local imports
from modules.handlers import handlers
from modules.generic_logic import error as error_handler
# Globals
BOT_TOKEN = "your_bot_token"
HEROKU_APP = "your_heroku_app_handle"
def initialise(bot_token, persistence_pickle):
persistence = PicklePersistence(filename=persistence_pickle)
up = Updater(token=bot_token, persistence=persistence, use_context=True)
dp = up.dispatcher
return up, dp
def add_handlers_to_dp(dp, handlers, error_handler):
for h in handlers:
dp.add_handler(handlers[h])
dp.add_error_handler(error_handler)
def start():
port = os.environ.get('PORT')
up, dp = initialise(BOT_TOKEN, "undercast.pickle")
add_handlers_to_dp(dp, handlers, error_handler)
up.start_webhook(listen="0.0.0.0", port=int(port), url_path=BOT_TOKEN)
up.bot.setWebhook(f"https://{HEROKU_APP}.herokuapp.com/{BOT_TOKEN}")
up.idle()
if __name__ == "__main__":
start()