force.add_keyboard(["Next", "Go to a random state"]) force.add_operation_buttons({1: go_to_random}) end = State("end", "This is the *end*.") # ---- CONVERSATION conv = Conversation(simple, end_state=end) conv.set_defaults(params={"parse_mode": "Markdown"}, back_button="Back") conv.add_routes(simple, default=riddle) conv.add_routes(riddle, default=dynamic, back=simple) conv.add_routes(dynamic, default=log, back=riddle) conv.add_routes(log, default=force, back=dynamic) conv.add_routes(force, default=end, back=log) # ---- HANDLER autoconv = AutoConvHandler(conv, STATE) def autoconv_command(update, context): return autoconv.manage_conversation(update, context) # MAIN -------------------------------------------------------------------------------- def main(): """Bot instance""" updater = Updater("BOT-TOKEN") dp = updater.dispatcher # -----------------------------------------------------------------------
end = State('end', '@@@', parse_mode=MARKDOWN) end.add_action(recap) # Conversation example = Conversation(name, end_state=end) example.add_state([gender, age, underage, comment]) example.add_routes(name, default=gender) example.add_routes(gender, default=age, back=name) example.add_routes(age, routes={i: underage for i in range(19)}, default=comment, back=gender) example.add_routes(underage, routes={0: comment, 1: end}, back=age) example.add_routes(comment, default=end, back=age) # Handler autoconv = AutoConvHandler(example, STATE, back_button='Back') def autoconv_command(update, context): return autoconv.manage_conversation(update, context) # MAIN -------------------------------------------------------------------------------- def main(): '''Bot instance''' updater = Updater(BOT_TOKEN, use_context=True) dp = updater.dispatcher # -----------------------------------------------------------------------