'dest': 'end', 'conditions': 'is_going_to_end' }, { 'trigger': 'go_back', 'source': ['end'], 'dest': 'init' }, ], initial='init', auto_transitions=False, show_conditions=True, ) # draw the whole graph ... machine.get_graph().draw('my_state_diagram.png', prog='dot') # ... or just the region of interest # (previous state, active state and all reachable states) #machine.get_graph(show_roi=True).draw('my_state_diagram.png', prog='dot') def _set_webhook(): status = bot.set_webhook(WEBHOOK_URL) if not status: print('Webhook setup failed') sys.exit(1) else: print('Your webhook URL has been set to "{}"'.format(WEBHOOK_URL)) @app.route('/hook', methods=['POST'])
def show_fsm(): machine = TocMachine().machine machine.get_graph().draw("fsm.png", prog="dot", format="png") return send_file("fsm.png", mimetype="image/png")
}, { 'trigger': 'advance', 'source': 'ready', 'dest': 'intro', 'conditions': 'ready_to_intro' }, { 'trigger': 'go_back', 'source': ['get', 'beauty', 'money'], 'dest': 'ready' }], initial='initial', auto_transitions=False, show_conditions=True, ignore_invalid_triggers=True) machine.get_graph().draw('fsm.png', prog='dot', format='png') config.save_image() @route("/webhook", method="GET") def setup_webhook(): mode = request.GET.get("hub.mode") token = request.GET.get("hub.verify_token") challenge = request.GET.get("hub.challenge") if mode == "subscribe" and token == VERIFY_TOKEN: print("WEBHOOK_VERIFIED") return challenge else: abort(403)
"trigger": "go_back", "source": [ "fsm", "start", "index", "search", "USA_index", "index_search", "index_chart", "TW_index", "TW_history", "TW_now", "stock_list", "stock_now", "stock_history", "stock_recommend" ], "dest": "begin" }, ], initial="user", auto_transitions=False, show_conditions=True, ) machine.get_graph().draw("./img/fsm.png", prog="dot", format="png") app = Flask(__name__, static_url_path="") # get channel_secret and channel_access_token from your environment variable channel_secret = os.getenv("LINE_CHANNEL_SECRET", None) channel_access_token = os.getenv("LINE_CHANNEL_ACCESS_TOKEN", None) if channel_secret is None: print("Specify LINE_CHANNEL_SECRET as environment variable.") sys.exit(1) if channel_access_token is None: print("Specify LINE_CHANNEL_ACCESS_TOKEN as environment variable.") sys.exit(1) line_bot_api = LineBotApi(channel_access_token) parser = WebhookParser(channel_secret)
def _set_webhook(): status = bot.set_webhook(WEBHOOK_URL) if not status: print('Webhook setup failed') sys.exit(1) else: print('Your webhook URL has been set to "{}"'.format(WEBHOOK_URL)) @app.route('/hook', methods=['POST']) def webhook_handler(): update = telegram.Update.de_json(request.get_json(force=True), bot) machine.advance(update) return 'ok' @app.route('/show-fsm', methods=['GET']) def show_fsm(): byte_io = BytesIO() machine.graph.draw(byte_io, prog='dot', format='png') byte_io.seek(0) return send_file(byte_io, attachment_filename='fsm.png', mimetype='image/png') if __name__ == "__main__": _set_webhook() machine.get_graph().draw("state.png", prog="dot") app.run()