def main(): parse_command_line() # Create adapter. # See https://aka.ms/about-bot-adapter to learn more about how bots work. settings = BotFrameworkAdapterSettings(options.app_id, options.app_password) # Create MemoryStorage, UserState and ConversationState memory = MemoryStorage() user_state = UserState(memory) conversation_state = ConversationState(memory) # Create adapter. # See https://aka.ms/about-bot-adapter to learn more about how bots work. adapter = AdapterWithErrorHandler(settings, conversation_state) # Create dialogs and Bot recognizer = FlightBookingRecognizer(options) booking_dialog = BookingDialog() dialog = MainDialog(recognizer, booking_dialog) bot = DialogAndWelcomeBot(conversation_state, user_state, dialog) app = tornado.web.Application( [ (r"/api/messages", MessageHandler, dict(adapter=adapter, bot=bot)), ], debug=options.debug, ) app.listen(options.port) tornado.ioloop.IOLoop.current().start()
APP = Flask(__name__, instance_relative_config=True) APP.config.from_object("config.DefaultConfig") SETTINGS = BotFrameworkAdapterSettings(APP.config["APP_ID"], APP.config["APP_PASSWORD"]) # Create MemoryStorage, UserState and ConversationState MEMORY = MemoryStorage() USER_STATE = UserState(MEMORY) CONVERSATION_STATE = ConversationState(MEMORY) # Create adapter. # See https://aka.ms/about-bot-adapter to learn more about how bots work. ADAPTER = AdapterWithErrorHandler(SETTINGS, CONVERSATION_STATE) # Create dialogs and Bot RECOGNIZER = FlightBookingRecognizer(APP.config) BOOKING_DIALOG = BookingDialog() DIALOG = MainDialog(RECOGNIZER, BOOKING_DIALOG) BOT = DialogAndWelcomeBot(CONVERSATION_STATE, USER_STATE, DIALOG) # Listen for incoming requests on /api/messages. @APP.route("/api/messages", methods=["POST"]) def messages(): # Main bot message handler. if "application/json" in request.headers["Content-Type"]: body = request.json else: return Response(status=415) activity = Activity().deserialize(body)
# Create adapter. # See https://aka.ms/about-bot-adapter to learn more about how bots work. SETTINGS = BotFrameworkAdapterSettings(CONFIG.APP_ID, CONFIG.APP_PASSWORD) # Create MemoryStorage, UserState and ConversationState MEMORY = MemoryStorage() USER_STATE = UserState(MEMORY) CONVERSATION_STATE = ConversationState(MEMORY) # Create adapter. # See https://aka.ms/about-bot-adapter to learn more about how bots work. ADAPTER = AdapterWithErrorHandler(SETTINGS, CONVERSATION_STATE) # Create dialogs and Bot RECOGNIZER = FlightBookingRecognizer(CONFIG) LEHOI_DIALOG = LehoiDialog() DIADIEM_DIALOG = DiadiemDialog() DANTOC_DIALOG = DantocDialog() GOIYLEHOI_DIALOG = GoiyLehoiDialog() GOIYLEHOI2_DIALOG = GoiyLehoiDialog2() DIALOG = MainDialog(RECOGNIZER, LEHOI_DIALOG, DIADIEM_DIALOG, DANTOC_DIALOG, GOIYLEHOI_DIALOG, GOIYLEHOI2_DIALOG) BOT = DialogAndWelcomeBot(CONVERSATION_STATE, USER_STATE, DIALOG) # Listen for incoming requests on /api/messages. async def messages(req: Request) -> Response: # Main bot message handler.
path = os.path.join(relative_path, "config.yaml") with open(path, "r") as ymlfile: cfg = yaml.safe_load(ymlfile) PORT = cfg["Settings"]["Port"] SETTINGS = BotFrameworkAdapterSettings(cfg["Settings"]["AppId"], cfg["Settings"]["AppPassword"]) # Create MemoryStorage, UserState and ConversationState memory = MemoryStorage() user_state = UserState(memory) conversation_state = ConversationState(memory) ADAPTER = AdapterWithErrorHandler(SETTINGS, conversation_state) RECOGNIZER = FlightBookingRecognizer(cfg["Settings"]) BOOKING_DIALOG = BookingDialog() dialog = MainDialog(RECOGNIZER, BOOKING_DIALOG) bot = DialogAndWelcomeBot(conversation_state, user_state, dialog) async def messages(req: web.Request) -> web.Response: body = await req.json() activity = Activity().deserialize(body) auth_header = req.headers[ "Authorization"] if "Authorization" in req.headers else "" async def aux_func(turn_context): await bot.on_turn(turn_context)