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()
def test_is_ambiguous(self): bd = bd = BookingDialog() ret = bd.is_ambiguous("what") assert ret ret = bd.is_ambiguous("2020-01-01") assert not ret
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) auth_header = (
def test_set_logger(self): bd = BookingDialog() bd.set_logger("a") assert bd.logger == "a"
def test_set_metrics_exporter(self): bd = bd = BookingDialog() bd.set_metrics_exporter("something") assert bd.metrics_exporter == "something"
# 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) BOOKING_DIALOG = BookingDialog() DIALOG = MainDialog(RECOGNIZER, BOOKING_DIALOG) BOT = DialogAndWelcomeBot(CONVERSATION_STATE, USER_STATE, DIALOG) BOOKING_DIALOG.set_logger(logger) BOOKING_DIALOG.set_metrics_exporter(exporter) # Listen for incoming requests on /api/messages. async def messages(req: Request) -> Response: # Main bot message handler. if "application/json" in req.headers["Content-Type"]: body = await req.json() else: return Response(status=HTTPStatus.UNSUPPORTED_MEDIA_TYPE)