diff --git a/generators/app/templates/core/{{cookiecutter.bot_name}}/adapter_with_error_handler.py b/generators/app/templates/core/{{cookiecutter.bot_name}}/adapter_with_error_handler.py index af1f81d98..7959968ce 100644 --- a/generators/app/templates/core/{{cookiecutter.bot_name}}/adapter_with_error_handler.py +++ b/generators/app/templates/core/{{cookiecutter.bot_name}}/adapter_with_error_handler.py @@ -5,18 +5,17 @@ from datetime import datetime from botbuilder.core import ( - BotFrameworkAdapter, - BotFrameworkAdapterSettings, ConversationState, TurnContext, ) +from botbuilder.integration.aiohttp import CloudAdapter, ConfigurationBotFrameworkAuthentication from botbuilder.schema import ActivityTypes, Activity -class AdapterWithErrorHandler(BotFrameworkAdapter): +class AdapterWithErrorHandler(CloudAdapter): def __init__( self, - settings: BotFrameworkAdapterSettings, + settings: ConfigurationBotFrameworkAuthentication, conversation_state: ConversationState, ): super().__init__(settings) diff --git a/generators/app/templates/core/{{cookiecutter.bot_name}}/app.py b/generators/app/templates/core/{{cookiecutter.bot_name}}/app.py index 8d2e9fc5d..c19ea27e2 100644 --- a/generators/app/templates/core/{{cookiecutter.bot_name}}/app.py +++ b/generators/app/templates/core/{{cookiecutter.bot_name}}/app.py @@ -8,16 +8,16 @@ - Handle user interruptions for such things as `Help` or `Cancel`. - Prompt for and validate requests for information from the user. """ - +from http import HTTPStatus from aiohttp import web from aiohttp.web import Request, Response, json_response from botbuilder.core import ( - BotFrameworkAdapterSettings, ConversationState, MemoryStorage, UserState, ) from botbuilder.core.integration import aiohttp_error_middleware +from botbuilder.integration.aiohttp import ConfigurationBotFrameworkAuthentication from botbuilder.schema import Activity from config import DefaultConfig @@ -31,7 +31,7 @@ # Create adapter. # See https://aka.ms/about-bot-adapter to learn more about how bots work. -SETTINGS = BotFrameworkAdapterSettings(CONFIG.APP_ID, CONFIG.APP_PASSWORD) +SETTINGS = ConfigurationBotFrameworkAuthentication(CONFIG) # Create MemoryStorage, UserState and ConversationState MEMORY = MemoryStorage() @@ -49,21 +49,21 @@ BOT = DialogAndWelcomeBot(CONVERSATION_STATE, USER_STATE, DIALOG) -# Listen for incoming requests on /api/messages. +# 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=415) + return Response(status=HTTPStatus.UNSUPPORTED_MEDIA_TYPE) activity = Activity().deserialize(body) auth_header = req.headers["Authorization"] if "Authorization" in req.headers else "" - response = await ADAPTER.process_activity(activity, auth_header, BOT.on_turn) + response = await ADAPTER.process_activity(auth_header, activity, BOT.on_turn) if response: return json_response(data=response.body, status=response.status) - return Response(status=201) + return Response(status=HTTPStatus.OK) APP = web.Application(middlewares=[aiohttp_error_middleware]) diff --git a/generators/app/templates/core/{{cookiecutter.bot_name}}/config.py b/generators/app/templates/core/{{cookiecutter.bot_name}}/config.py index 46973c345..f2d31d7ad 100644 --- a/generators/app/templates/core/{{cookiecutter.bot_name}}/config.py +++ b/generators/app/templates/core/{{cookiecutter.bot_name}}/config.py @@ -10,6 +10,8 @@ class DefaultConfig: PORT = 3978 APP_ID = os.environ.get("MicrosoftAppId", "") APP_PASSWORD = os.environ.get("MicrosoftAppPassword", "") + APP_TYPE = os.environ.get("MicrosoftAppType", "MultiTenant") + APP_TENANTID = os.environ.get("MicrosoftAppTenantId", "") LUIS_APP_ID = os.environ.get("LuisAppId", "") LUIS_API_KEY = os.environ.get("LuisAPIKey", "") # LUIS endpoint host name, ie "westus.api.cognitive.microsoft.com" diff --git a/generators/app/templates/core/{{cookiecutter.bot_name}}/requirements.txt b/generators/app/templates/core/{{cookiecutter.bot_name}}/requirements.txt index 26674db81..0c93ce564 100644 --- a/generators/app/templates/core/{{cookiecutter.bot_name}}/requirements.txt +++ b/generators/app/templates/core/{{cookiecutter.bot_name}}/requirements.txt @@ -1,4 +1,4 @@ -botbuilder-integration-aiohttp>=4.15.0 +botbuilder-integration-aiohttp>=4.14.8 botbuilder-dialogs>=4.15.0 -botbuilder-ai>=4.15.0 +botbuilder-ai>=4.14.8 datatypes-date-time>=1.0.0.a2 diff --git a/generators/app/templates/echo/{{cookiecutter.bot_name}}/app.py b/generators/app/templates/echo/{{cookiecutter.bot_name}}/app.py index 6a21648d0..8dc9fbecb 100644 --- a/generators/app/templates/echo/{{cookiecutter.bot_name}}/app.py +++ b/generators/app/templates/echo/{{cookiecutter.bot_name}}/app.py @@ -5,14 +5,12 @@ import traceback from datetime import datetime +from http import HTTPStatus from aiohttp import web from aiohttp.web import Request, Response, json_response -from botbuilder.core import ( - BotFrameworkAdapterSettings, - TurnContext, - BotFrameworkAdapter, -) +from botbuilder.core import TurnContext from botbuilder.core.integration import aiohttp_error_middleware +from botbuilder.integration.aiohttp import CloudAdapter, ConfigurationBotFrameworkAuthentication from botbuilder.schema import Activity, ActivityTypes from bot import MyBot @@ -22,9 +20,7 @@ # Create adapter. # See https://aka.ms/about-bot-adapter to learn more about how bots work. -SETTINGS = BotFrameworkAdapterSettings(CONFIG.APP_ID, CONFIG.APP_PASSWORD) -ADAPTER = BotFrameworkAdapter(SETTINGS) - +ADAPTER = CloudAdapter(ConfigurationBotFrameworkAuthentication(CONFIG)) # Catch-all for errors. async def on_error(context: TurnContext, error: Exception): @@ -66,15 +62,15 @@ async def messages(req: Request) -> Response: if "application/json" in req.headers["Content-Type"]: body = await req.json() else: - return Response(status=415) + return Response(status=HTTPStatus.UNSUPPORTED_MEDIA_TYPE) activity = Activity().deserialize(body) auth_header = req.headers["Authorization"] if "Authorization" in req.headers else "" - response = await ADAPTER.process_activity(activity, auth_header, BOT.on_turn) + response = await ADAPTER.process_activity(auth_header, activity, BOT.on_turn) if response: return json_response(data=response.body, status=response.status) - return Response(status=201) + return Response(status=HTTPStatus.OK) APP = web.Application(middlewares=[aiohttp_error_middleware]) diff --git a/generators/app/templates/echo/{{cookiecutter.bot_name}}/config.py b/generators/app/templates/echo/{{cookiecutter.bot_name}}/config.py index 51e0988ed..aad3896f4 100644 --- a/generators/app/templates/echo/{{cookiecutter.bot_name}}/config.py +++ b/generators/app/templates/echo/{{cookiecutter.bot_name}}/config.py @@ -10,3 +10,5 @@ class DefaultConfig: PORT = 3978 APP_ID = os.environ.get("MicrosoftAppId", "") APP_PASSWORD = os.environ.get("MicrosoftAppPassword", "") + APP_TYPE = os.environ.get("MicrosoftAppType", "MultiTenant") + APP_TENANTID = os.environ.get("MicrosoftAppTenantId", "") diff --git a/generators/app/templates/empty/{{cookiecutter.bot_name}}/app.py b/generators/app/templates/empty/{{cookiecutter.bot_name}}/app.py index a6aa1bcd1..29f91ab47 100644 --- a/generators/app/templates/empty/{{cookiecutter.bot_name}}/app.py +++ b/generators/app/templates/empty/{{cookiecutter.bot_name}}/app.py @@ -5,14 +5,12 @@ import traceback from datetime import datetime +from http import HTTPStatus from aiohttp import web from aiohttp.web import Request, Response, json_response -from botbuilder.core import ( - BotFrameworkAdapterSettings, - TurnContext, - BotFrameworkAdapter, -) +from botbuilder.core import TurnContext from botbuilder.core.integration import aiohttp_error_middleware +from botbuilder.integration.aiohttp import CloudAdapter, ConfigurationBotFrameworkAuthentication from botbuilder.schema import Activity, ActivityTypes from bot import MyBot @@ -22,9 +20,7 @@ # Create adapter. # See https://aka.ms/about-bot-adapter to learn more about how bots work. -SETTINGS = BotFrameworkAdapterSettings(CONFIG.APP_ID, CONFIG.APP_PASSWORD) -ADAPTER = BotFrameworkAdapter(SETTINGS) - +ADAPTER = CloudAdapter(ConfigurationBotFrameworkAuthentication(CONFIG)) # Catch-all for errors. async def on_error(context: TurnContext, error: Exception): @@ -66,15 +62,15 @@ async def messages(req: Request) -> Response: if "application/json" in req.headers["Content-Type"]: body = await req.json() else: - return Response(status=415) + return Response(status=HTTPStatus.UNSUPPORTED_MEDIA_TYPE) activity = Activity().deserialize(body) auth_header = req.headers["Authorization"] if "Authorization" in req.headers else "" - response = await ADAPTER.process_activity(activity, auth_header, BOT.on_turn) + response = await ADAPTER.process_activity(auth_header, activity, BOT.on_turn) if response: return json_response(data=response.body, status=response.status) - return Response(status=201) + return Response(status=HTTPStatus.OK) APP = web.Application(middlewares=[aiohttp_error_middleware]) diff --git a/generators/app/templates/empty/{{cookiecutter.bot_name}}/config.py b/generators/app/templates/empty/{{cookiecutter.bot_name}}/config.py index 51e0988ed..aad3896f4 100644 --- a/generators/app/templates/empty/{{cookiecutter.bot_name}}/config.py +++ b/generators/app/templates/empty/{{cookiecutter.bot_name}}/config.py @@ -10,3 +10,5 @@ class DefaultConfig: PORT = 3978 APP_ID = os.environ.get("MicrosoftAppId", "") APP_PASSWORD = os.environ.get("MicrosoftAppPassword", "") + APP_TYPE = os.environ.get("MicrosoftAppType", "MultiTenant") + APP_TENANTID = os.environ.get("MicrosoftAppTenantId", "")