8000 Updated generators to use CloudAdapter and latest version (#2094) · AogiWorld/botbuilder-python@2407c51 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2407c51

Browse files
tracyboehrerTracy Boehrer
and
Tracy Boehrer
authored
Updated generators to use CloudAdapter and latest version (microsoft#2094)
* Updated generators to use CloudAdapter and latest version * Updated version and added missing SingleTenant config items --------- Co-authored-by: Tracy Boehrer <trboehre@microsoft.com>
1 parent 48ba78e commit 2407c51

File tree

8 files changed

+32
-35
lines changed
  • generators/app/templates
    • core/{{cookiecutter.bot_name}}
      • < 8000 div class="PRIVATE_VisuallyHidden prc-TreeView-TreeViewVisuallyHidden-4-mPv" aria-hidden="true" id=":RmqrtddabH1:">
        adapter_with_error_handler.py
  • echo/{{cookiecutter.bot_name}}
  • empty/{{cookiecutter.bot_name}}
  • 8 files changed

    +32
    -35
    lines changed

    generators/app/templates/core/{{cookiecutter.bot_name}}/adapter_with_error_handler.py

    Lines changed: 3 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -5,18 +5,17 @@
    55
    from datetime import datetime
    66

    77
    from botbuilder.core import (
    8-
    BotFrameworkAdapter,
    9-
    BotFrameworkAdapterSettings,
    108
    ConversationState,
    119
    TurnContext,
    1210
    )
    11+
    from botbuilder.integration.aiohttp import CloudAdapter, ConfigurationBotFrameworkAuthentication
    1312
    from botbuilder.schema import ActivityTypes, Activity
    1413

    1514

    16-
    class AdapterWithErrorHandler(BotFrameworkAdapter):
    15+
    class AdapterWithErrorHandler(CloudAdapter):
    1716
    def __init__(
    1817
    self,
    19-
    settings: BotFrameworkAdapterSettings,
    18+
    settings: ConfigurationBotFrameworkAuthentication,
    2019
    conversation_state: ConversationState,
    2120
    ):
    2221
    super().__init__(settings)

    generators/app/templates/core/{{cookiecutter.bot_name}}/app.py

    Lines changed: 7 additions & 7 deletions
    Original file line numberDiff line numberDiff line change
    @@ -8,16 +8,16 @@
    88
    - Handle user interruptions for such things as `Help` or `Cancel`.
    99
    - Prompt for and validate requests for information from the user.
    1010
    """
    11-
    11+
    from http import HTTPStatus
    1212
    from aiohttp import web
    1313
    from aiohttp.web import Request, Response, json_response
    1414
    from botbuilder.core import (
    15-
    BotFrameworkAdapterSettings,
    1615
    ConversationState,
    1716
    MemoryStorage,
    1817
    UserState,
    1918
    )
    2019
    from botbuilder.core.integration import aiohttp_error_middleware
    20+
    from botbuilder.integration.aiohttp import ConfigurationBotFrameworkAuthentication
    2121
    from botbuilder.schema import Activity
    2222

    2323
    from config import DefaultConfig
    @@ -31,7 +31,7 @@
    3131

    3232
    # Create adapter.
    3333
    # See https://aka.ms/about-bot-adapter to learn more about how bots work.
    34-
    SETTINGS = BotFrameworkAdapterSettings(CONFIG.APP_ID, CONFIG.APP_PASSWORD)
    34+
    SETTINGS = ConfigurationBotFrameworkAuthentication(CONFIG)
    3535

    3636
    # Create MemoryStorage, UserState and ConversationState
    3737
    MEMORY = MemoryStorage()
    @@ -49,21 +49,21 @@
    4949
    BOT = DialogAndWelcomeBot(CONVERSATION_STATE, USER_STATE, DIALOG)
    5050

    5151

    52-
    # Listen for incoming requests on /api/messages.
    52+
    # Listen for incoming requests on /api/messages
    5353
    async def messages(req: Request) -> Response:
    5454
    # Main bot message handler.
    5555
    if "application/json" in req.headers["Content-Type"]:
    5656
    body = await req.json()
    5757
    else:
    58-
    return Response(status=415)
    58+
    return Response(status=HTTPStatus.UNSUPPORTED_MEDIA_TYPE)
    5959

    6060
    activity = Activity().deserialize(body)
    6161
    auth_header = req.headers["Authorization"] if "Authorization" in req.headers else ""
    6262

    63-
    response = await ADAPTER.process_activity(activity, auth_header, BOT.on_turn)
    63+
    response = await ADAPTER.process_activity(auth_header, activity, BOT.on_turn)
    6464
    if response:
    6565
    return json_response(data=response.body, status=response.status)
    66-
    return Response(status=201)
    66+
    return Response(status=HTTPStatus.OK)
    6767

    6868

    6969
    APP = web.Application(middlewares=[aiohttp_error_middleware])

    generators/app/templates/core/{{cookiecutter.bot_name}}/config.py

    Lines changed: 2 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -10,6 +10,8 @@ class DefaultConfig:
    1010
    PORT = 3978
    1111
    APP_ID = os.environ.get("MicrosoftAppId", "")
    1212
    APP_PASSWORD = os.environ.get("MicrosoftAppPassword", "")
    13+
    APP_TYPE = os.environ.get("MicrosoftAppType", "MultiTenant")
    14+
    APP_TENANTID = os.environ.get("MicrosoftAppTenantId", "")
    1315
    LUIS_APP_ID = os.environ.get("LuisAppId", "")
    1416
    LUIS_API_KEY = os.environ.get("LuisAPIKey", "")
    1517
    # LUIS endpoint host name, ie "westus.api.cognitive.microsoft.com"
    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1,4 +1,4 @@
    1-
    botbuilder-integration-aiohttp>=4.15.0
    1+
    botbuilder-integration-aiohttp>=4.14.8
    22
    botbuilder-dialogs>=4.15.0
    3-
    botbuilder-ai>=4.15.0
    3+
    botbuilder-ai>=4.14.8
    44
    datatypes-date-time>=1.0.0.a2

    generators/app/templates/echo/{{cookiecutter.bot_name}}/app.py

    Lines changed: 7 additions & 11 deletions
    Original file line numberDiff line numberDiff line change
    @@ -5,14 +5,12 @@
    55
    import traceback
    66
    from datetime import datetime
    77

    8+
    from http import HTTPStatus
    89
    from aiohttp import web
    910
    from aiohttp.web import Request, Response, json_response
    10-
    from botbuilder.core import (
    11-
    BotFrameworkAdapterSettings,
    12-
    TurnContext,
    13-
    BotFrameworkAdapter,
    14-
    )
    11+
    from botbuilder.core import TurnContext
    1512
    from botbuilder.core.integration import aiohttp_error_middleware
    13+
    from botbuilder.integration.aiohttp import CloudAdapter, ConfigurationBotFrameworkAuthentication
    1614
    from botbuilder.schema import Activity, ActivityTypes
    1715

    1816
    from bot import MyBot
    @@ -22,9 +20,7 @@
    2220

    2321
    # Create adapter.
    2422
    # See https://aka.ms/about-bot-adapter to learn more about how bots work.
    25-
    SETTINGS = BotFrameworkAdapterSettings(CONFIG.APP_ID, CONFIG.APP_PASSWORD)
    26-
    ADAPTER = BotFrameworkAdapter(SETTINGS)
    27-
    23+
    ADAPTER = CloudAdapter(ConfigurationBotFrameworkAuthentication(CONFIG))
    2824

    2925
    # Catch-all for errors.
    3026
    async def on_error(context: TurnContext, error: Exception):
    @@ -66,15 +62,15 @@ async def messages(req: Request) -> Response:
    6662
    if "application/json" in req.headers["Content-Type"]:
    6763
    body = await req.json()
    6864
    else:
    69-
    return Response(status=415)
    65+
    return Response(status=HTTPStatus.UNSUPPORTED_MEDIA_TYPE)
    7066

    7167
    activity = Activity().deserialize(body)
    7268
    auth_header = req.headers["Authorization"] if "Authorization" in req.headers else ""
    7369

    74-
    response = await ADAPTER.process_activity(activity, auth_header, BOT.on_turn)
    70+
    response = await ADAPTER.process_activity(auth_header, activity, BOT.on_turn)
    7571
    if response:
    7672
    return json_response(data=response.body, status=response.status)
    77-
    return Response(status=201)
    73+
    return Response(status=HTTPStatus.OK)
    7874

    7975

    8076
    APP = web.Application(middlewares=[aiohttp_error_middleware])

    generators/app/templates/echo/{{cookiecutter.bot_name}}/config.py

    Lines changed: 2 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -10,3 +10,5 @@ class DefaultConfig:
    1010
    PORT = 3978
    1111
    APP_ID = os.environ.get("MicrosoftAppId", "")
    1212
    APP_PASSWORD = os.environ.get("MicrosoftAppPassword", "")
    13+
    APP_TYPE = os.environ.get("MicrosoftAppType", "MultiTenant")
    14+
    APP_TENANTID = os.environ.get("MicrosoftAppTenantId", "")

    generators/app/templates/empty/{{cookiecutter.bot_name}}/app.py

    Lines changed: 7 additions & 11 deletions
    Original file line numberDiff line numberDiff line change
    @@ -5,14 +5,12 @@
    55
    import traceback
    66
    from datetime import datetime
    77

    8+
    from http import HTTPStatus
    89
    from aiohttp import web
    910
    from aiohttp.web import Request, Response, json_response
    10-
    from botbuilder.core import (
    11-
    BotFrameworkAdapterSettings,
    12-
    TurnContext,
    13-
    BotFrameworkAdapter,
    14-
    )
    11+
    from botbuilder.core import TurnContext
    1512
    from botbuilder.core.integration import aiohttp_error_middleware
    13+
    from botbuilder.integration.aiohttp import CloudAdapter, ConfigurationBotFrameworkAuthentication
    1614
    from botbuilder.schema import Activity, ActivityTypes
    1715

    1816
    from bot import MyBot
    @@ -22,9 +20,7 @@
    2220

    2321
    # Create adapter.
    2422
    # See https://aka.ms/about-bot-adapter to learn more about how bots work.
    25-
    SETTINGS = BotFrameworkAdapterSettings(CONFIG.APP_ID, CONFIG.APP_PASSWORD)
    26-
    ADAPTER = BotFrameworkAdapter(SETTINGS)
    27-
    23+
    ADAPTER = CloudAdapter(ConfigurationBotFrameworkAuthentication(CONFIG))
    2824

    2925
    # Catch-all for errors.
    3026
    async def on_error(context: TurnContext, error: Exception):
    @@ -66,15 +62,15 @@ async def messages(req: Request) -> Response:
    6662
    if "application/json" in req.headers["Content-Type"]:
    6763
    body = await req.json()
    6864
    else:
    69-
    return Response(status=415)
    65+
    return Response(status=HTTPStatus.UNSUPPORTED_MEDIA_TYPE)
    7066

    7167
    activity = Activity().deserialize(body)
    7268
    auth_header = req.headers["Authorization"] if "Authorization" in req.headers else ""
    7369

    74-
    response = await ADAPTER.process_activity(activity, auth_header, BOT.on_turn)
    70+
    response = await ADAPTER.process_activity(auth_header, activity, BOT.on_turn)
    7571
    if response:
    7672
    return json_response(data=response.body, status=response.status)
    77-
    return Response(status=201)
    73+
    return Response(status=HTTPStatus.OK)
    7874

    7975

    8076
    APP = web.Application(middlewares=[aiohttp_error_middleware])

    generators/app/templates/empty/{{cookiecutter.bot_name}}/config.py

    Lines changed: 2 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -10,3 +10,5 @@ class DefaultConfig:
    1010
    PORT = 3978
    1111
    APP_ID = os.environ.get("MicrosoftAppId", "")
    1212
    APP_PASSWORD = os.environ.get("MicrosoftAppPassword", "")
    13+
    APP_TYPE = os.environ.get("MicrosoftAppType", "MultiTenant")
    14+
    APP_TENANTID = os.environ.get("MicrosoftAppTenantId", "")

    0 commit comments

    Comments
     (0)
    0