Skip to content

Commit

Permalink
Merge pull request #1 from telebotter/dev
Browse files Browse the repository at this point in the history
add context based handlers for ptb12
  • Loading branch information
lukruh authored Feb 12, 2020
2 parents 55aa268 + 332a828 commit 9bf5fce
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ And set your bots::
'BOTS' : [
{
'TOKEN': '123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11', #Your bot token.
#'CONTEXT': True, # Use context based handler functions

#'ALLOWED_UPDATES':(Optional[list[str]]), # List the types of
#updates you want your bot to receive. For example, specify
Expand Down
9 changes: 5 additions & 4 deletions django_telegrambot/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,16 @@ def ready(self):

for b in bots_list:
token = b.get('TOKEN', None)
context = b.get('CONTEXT', False)
if not token:
break

allowed_updates = b.get('ALLOWED_UPDATES', None)
timeout = b.get('TIMEOUT', None)
proxy = b.get('PROXY', None)

if self.mode == WEBHOOK_MODE:
try:
try:
if b.get('MESSAGEQUEUE_ENABLED',False):
q = mq.MessageQueue(all_burst_limit=b.get('MESSAGEQUEUE_ALL_BURST_LIMIT',29),
all_time_limit_ms=b.get('MESSAGEQUEUE_ALL_TIME_LIMIT_MS',1024))
Expand All @@ -184,7 +185,7 @@ def ready(self):
if proxy:
request = Request(proxy_url=proxy['proxy_url'], urllib3_proxy_kwargs=proxy['urllib3_proxy_kwargs'])
bot = telegram.Bot(token=token, request=request)

DjangoTelegramBot.dispatchers.append(Dispatcher(bot, None, workers=0))
hookurl = '{}/{}/{}/'.format(webhook_site, webhook_base, token)
max_connections = b.get('WEBHOOK_MAX_CONNECTIONS', 40)
Expand All @@ -204,7 +205,7 @@ def ready(self):

else:
try:
updater = Updater(token=token, request_kwargs=proxy)
updater = Updater(token=token, request_kwargs=proxy, use_context=context)
bot = updater.bot
bot.delete_webhook()
DjangoTelegramBot.updaters.append(updater)
Expand Down

0 comments on commit 9bf5fce

Please sign in to comment.