def on_edited_chat_message(self, msg): content_type, chat_type, chat_id = telepot.glance(msg, flavor='edited_chat') self.sendMessage(chat_id, 'Add me to a group, please.') r = telepot.helper.Router(by_content_type(), make_content_type_routing_table(self)) self._router.routing_table['chat'] = r.route
def on_chat_message(self, msg): content_type, chat_type, chat_id = telepot.glance(msg) if 'edit_date' not in msg: self.sendMessage(chat_id, 'Edit the message, please.') else: self.sendMessage(chat_id, 'Add me to a group, please.') r = telepot.helper.Router(by_content_type(), make_content_type_routing_table(self)) self._router.routing_table['chat'] = r.route
def on_chat_message(self, msg): content_type, chat_type, chat_id = telepot.glance(msg) if 'edit_date' not in msg: self.sendMessage(chat_id, 'Edit the message, please.') else: self.sendMessage(chat_id, 'Add me to a group, please.') # Make a router to route `new_chat_member` and `left_chat_member` r = telepot.helper.Router(by_content_type(), make_content_type_routing_table(self)) # Replace current handler with that router self._router.routing_table['chat'] = r.route
class ContentTypeHandler(object): def on_text(self, msg, text): print('Text', msg, text) def on_photo(self, msg, photo): print('Photo', msg, photo) def make_message_like(mm): for d in mm: d.update({'chat': {'type': 'private', 'id': 1000}}) top_router.key_function = by_content_type() top_router.routing_table = make_content_type_routing_table( ContentTypeHandler()) del top_router.routing_table['video'] # let video fall to default handler top_router.routing_table[None] = none_of_above messages = [ { 'text': 'abc' }, { 'photo': 'some photo' }, { 'video': 'some video' }, ] make_message_like(messages)
print class ContentTypeHandler(object): def on_text(self, msg, text): print 'Text', msg, text def on_photo(self, msg, photo): print 'Photo', msg, photo def make_message_like(mm): for d in mm: d.update({'chat': {'type': 'private', 'id': 1000}}) top_router.key_function = by_content_type() top_router.routing_table = make_content_type_routing_table(ContentTypeHandler()) del top_router.routing_table['video'] # let video fall to default handler top_router.routing_table[None] = none_of_above messages = [{'text': 'abc'}, {'photo': 'some photo'}, {'video': 'some video'},] make_message_like(messages) for i in range(0,10): top_router.route(random.choice(messages)) print class CommandHandler(object): def on_start(self, msg):