# Display message counts separated by flavors print(self.id, ':', flavor, '+1', ':', ', '.join([str(self._counts[f]) for f in ['chat', 'inline_query', 'chosen_inline_result']])) # Have to answer inline query to receive chosen result if flavor == 'inline_query': def compute_answer(): query_id, from_id, query_string = telepot.glance(msg, flavor=flavor) articles = [{'type': 'article', 'id': 'abc', 'title': query_string, 'message_text': query_string}] return articles self._answerer.answer(msg, compute_answer) TOKEN = sys.argv[1] bot = telepot.async.DelegatorBot(TOKEN, [ (per_from_id(), create_open(UserTracker, timeout=20)), ]) loop = asyncio.get_event_loop() loop.create_task(bot.message_loop()) print('Listening ...') loop.run_forever()
# Display message counts separated by flavors print(self.id, ':', flavor, '+1', ':', ', '.join([str(self._counts[f]) for f in ['normal', 'inline_query', 'chosen_inline_result']])) # Have to answer inline query to receive chosen result if flavor == 'inline_query': def compute_answer(): query_id, from_id, query_string = telepot.glance(msg, flavor=flavor) articles = [{'type': 'article', 'id': 'abc', 'title': query_string, 'message_text': query_string}] return articles self._answerer.answer(msg, compute_answer) TOKEN = sys.argv[1] bot = telepot.async.DelegatorBot(TOKEN, [ (per_from_id(), create_open(UserTracker, timeout=20)), ]) loop = asyncio.get_event_loop() loop.create_task(bot.messageLoop()) print('Listening ...') loop.run_forever()
flavors=['inline_query', 'chosen_inline_result']) self._count = 0 def on_message(self, msg): self._count += 1 flavor = telepot.flavor(msg) print('%s %d: %d: %s: %s' % (type(self).__name__, self.id, self._count, flavor, telepot.glance(msg, flavor=flavor))) def on_close(self, exception): print('%s %d: closed' % (type(self).__name__, self.id)) TOKEN = sys.argv[1] bot = telepot. async .DelegatorBot(TOKEN, [ (per_chat_id(), create_open(ChatHandlerSubclass, timeout=10)), (per_from_id(), create_open(UserHandlerSubclass, timeout=20)), (per_inline_from_id(), create_open(UserHandlerSubclassInlineOnly, timeout=10)), ]) loop = asyncio.get_event_loop() loop.create_task(bot.messageLoop()) print('Listening ...') loop.run_forever()
flavor = telepot.flavor(msg) print('%s %d: %d: %s: %s' % (type(self).__name__, self.id, self._count, flavor, telepot.glance(msg, flavor=flavor))) # Do some simple stuff for every message, to be paired with per_message() def simple_function(seed_tuple): bot, msg, id = seed_tuple print('Simply print:', msg) TOKEN = sys.argv[1] bot = telepot.async.DelegatorBot(TOKEN, [ (per_chat_id(), create_open(ChatHandlerSubclass, timeout=10)), (per_from_id(), create_open(UserHandlerSubclass, timeout=20)), (per_inline_from_id(), create_open(InlineUserHandlerSubclass, timeout=10)), (per_application(), create_open(OneInstanceOnly)), (per_message(), call(simple_function)), ]) loop = asyncio.get_event_loop() loop.create_task(bot.message_loop()) print('Listening ...') loop.run_forever()