value_type="https://www.botframework.com/schemas/error", ) # Send a trace activity, which will be displayed in Bot Framework Emulator await context.send_activity(trace_activity) ADAPTER.on_turn_error = on_error # Create MemoryStorage and state MEMORY = MemoryStorage() USER_STATE = UserState(MEMORY) CONVERSATION_STATE = ConversationState(MEMORY) # Create Dialog and Bot DIALOG = RootDialog(USER_STATE) BOT = DialogBot(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 = (request.headers["Authorization"] if "Authorization" in request.headers else "")
# Set the error handler on the Adapter. # In this case, we want an unbound method, so MethodType is not needed. ADAPTER.on_turn_error = on_error # Create a shared dictionary. The Bot will add conversation references when users # join the conversation and send messages. CONVERSATION_REFERENCES: Dict[str, ConversationReference] = dict() # Create MemoryStorage, UserState and ConversationState MEMORY = MemoryStorage() CONVERSATION_STATE = ConversationState(MEMORY) USER_STATE = UserState(MEMORY) # create main dialog and bot DIALOG = WaterfallMain(USER_STATE) BOT = DialogBot(CONVERSATION_STATE, USER_STATE, DIALOG, CONVERSATION_REFERENCES) # If the channel is the Emulator, and authentication is not in use, the AppId will be null. # We generate a random AppId for this case only. This is not required for production, since # the AppId will have a value. APP_ID = SETTINGS.app_id if SETTINGS.app_id else uuid.uuid4() # Listen for incoming requests on /api/messages. async def messages(req: Request) -> Response: if "application/json" in req.headers["Content-Type"]: body = await req.json() else: return Response(status=HTTPStatus.UNSUPPORTED_MEDIA_TYPE)