generated from SergeyMi37/django-telegram-bot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_polling.py
33 lines (22 loc) · 848 Bytes
/
run_polling.py
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
import os, django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dtb.settings')
django.setup()
from telegram import Bot
from telegram.ext import Updater
from dtb.settings import TELEGRAM_TOKEN
from tgbot.dispatcher import setup_dispatcher
def run_polling(tg_token: str = TELEGRAM_TOKEN):
""" Run bot in polling mode """
updater = Updater(tg_token, use_context=True)
dp = updater.dispatcher
dp = setup_dispatcher(dp)
bot_info = Bot(tg_token).get_me()
bot_link = f"https://t.me/{bot_info['username']}"
print(f"Polling of '{bot_link}' has started")
# it is really useful to send '👋' emoji to developer
# when you run local test
# bot.send_message(text='👋', chat_id=<YOUR TELEGRAM ID>)
updater.start_polling(poll_interval=2)
updater.idle()
if __name__ == "__main__":
run_polling()