diff --git a/README.rst b/README.rst index ec94640..fdde76d 100644 --- a/README.rst +++ b/README.rst @@ -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 diff --git a/django_telegrambot/apps.py b/django_telegrambot/apps.py index 653ce91..357620e 100644 --- a/django_telegrambot/apps.py +++ b/django_telegrambot/apps.py @@ -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)) @@ -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) @@ -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)