8000 Message reactions with aiohttp · yosshy/botbuilder-python@cc03ce8 · GitHub
[go: up one dir, main page]

Skip to content

Commit cc03ce8

Browse files
committed
Message reactions with aiohttp
1 parent ebbb4f7 commit cc03ce8

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

libraries/botbuilder-core/tests/teams/message-reactions/app.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from datetime import datetime
66
from types import MethodType
77

8-
from flask import Flask, request, Response
8+
from aiohttp import web
99
from botbuilder.core import (
1010
BotFrameworkAdapterSettings,
1111
TurnContext,
@@ -15,15 +15,16 @@
1515
from botbuilder.schema import Activity, ActivityTypes
1616
from activity_log import ActivityLog
1717
from bots import MessageReactionBot
18-
from threading_helper import run_coroutine
18+
# from threading_helper import run_coroutine
19+
from config import DefaultConfig
1920

2021
# Create the Flask app
21-
APP = Flask(__name__, instance_relative_config=True)
22-
APP.config.from_object("config.DefaultConfig")
22+
CONFIG = DefaultConfig()
23+
PORT = CONFIG.PORT
2324

2425
# Create adapter.
2526
# See https://aka.ms/about-bot-adapter to learn more about how bots work.
26-
SETTINGS = BotFrameworkAdapterSettings(APP.config["APP_ID"], APP.config["APP_PASSWORD"])
27+
SETTINGS = BotFrameworkAdapterSettings(CONFIG.APP_ID, CONFIG.APP_PASSWORD)
2728
ADAPTER = BotFrameworkAdapter(SETTINGS)
2829

2930

@@ -64,31 +65,29 @@ async def on_error( # pylint: disable=unused-argument
6465
BOT = MessageReactionBot(ACTIVITY_LOG)
6566

6667
# Listen for incoming requests on /api/messages.s
67-
@APP.route("/api/messages", methods=["POST"])
68-
def messages():
68+
async def messages(req: web.Request) -> web.Response:
6969
# Main bot message handler.
70-
if "application/json" in request.headers["Content-Type"]:
71-
body = request.json
70+
if "application/json" in req.headers["Content-Type"]:
71+
body = await req.json()
7272
else:
73-
return Response(status=415)
73+
return web.Response(status=415)
7474

7575
activity = Activity().deserialize(body)
7676
auth_header = (
77-
request.headers["Authorization"] if "Authorization" in request.headers else ""
77+
req.headers["Authorization"] if "Authorization" in req.headers else ""
7878
)
7979

8080
try:
81-
print("about to create task")
82-
print("about to run until complete")
83-
run_coroutine(ADAPTER.process_activity(activity, auth_header, BOT.on_turn))
84-
print("is now complete")
85-
return Response(status=201)
81+
await ADAPTER.process_activity(activity, auth_header, BOT.on_turn)
82+
return web.Response(status=201)
8683
except Exception as exception:
8784
raise exception
8885

8986

90-
if __name__ == "__main__":
91-
try:
92-
APP.run(debug=False, port=APP.config["PORT"]) # nosec debug
93-
except Exception as exception:
94-
raise exception
87+
APP = web.Application()
88+
APP.router.add_post("/api/messages", messages)
89+
90+
try:
91+
web.run_app(APP, host="localhost", port=PORT)
92+
except Exception as error:
93+
raise error

libraries/botbuilder-core/tests/teams/message-reactions/threading_helper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22
import itertools
33
import logging
4+
import time
45
import threading
56

67
# pylint: disable=invalid-name

0 commit comments

Comments
 (0)
0