8000 working on integration layer · itsmokha/botbuilder-python@db6066d · GitHub
[go: up one dir, main page]

Skip to content

Commit db6066d

Browse files
committed
working on integration layer
1 parent a35f565 commit db6066d

File tree

3 files changed

+474
-40
lines changed

3 files changed

+474
-40
lines changed

libraries/botbuilder-skills/botbuilder/skills/bot_framework_http_client.py renamed to libraries/botbuilder-core/botbuilder/core/integration/bot_framework_http_client.py

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
import json
55
from typing import Dict
6-
import requests
6+
from logging import Logger
7+
import aiohttp
78

89
from botbuilder.core import InvokeResponse
910
from botbuilder.schema import Activity
@@ -14,9 +15,6 @@
1415
MicrosoftAppCredentials,
1516
)
1617

17-
# from .referr_info import ReferrInfo
18-
from .skill_conversation import SkillConversation
19-
2018

2119
class BotFrameworkHttpClient:
2220

@@ -33,14 +31,15 @@ def __init__(
3331
self,
3432
credential_provider: CredentialProvider,
3533
channel_provider: ChannelProvider = None,
36-
logger: object = None,
34+
logger: Logger = None,
3735
):
3836
if not credential_provider:
3937
raise TypeError("credential_provider can't be None")
4038

4139
self._credential_provider = credential_provider
4240
self._channel_provider = channel_provider
4341
self._logger = logger
42+
self._session = aiohttp.ClientSession()
4443

4544
async def post_activity(
4645
self,
@@ -65,43 +64,23 @@ async def post_activity(
6564
original_service_url = activity.service_url
6665

6766
try:
68-
# TODO: figure out a better way of passing the original ServiceUrl when calling
69-
# the skill so we don't have to encode it in the conversation ID.
70-
# Encode original bot service URL and ConversationId in the new conversation ID so we can unpack it later.
71-
skill_conversation = SkillConversation(
72-
service_url=activity.service_url, conversation_id=conversation_id
73-
)
74-
activity.conversation.id = skill_conversation.get_skill_conversation_id()
67+
activity.conversation.id = conversation_id
7568
activity.service_url = service_url
7669

77-
# TODO: Review the rest of the code and see if we can remove this. Gabo
78-
# TODO: can we use this property back to store the source conversation ID and the ServiceUrl?
79-
"""
80-
activity.recipient.properties["skillId"] = to_bot_id
81-
referr = ReferrInfo(
82-
from_bot_id=from_bot_id,
83-
to_bot_id=to_bot_id,
84-
conversation_id=original_conversation_id,
85-
service_url=original_service_url
70+
json_content = json.dumps(activity.serialize())
71+
resp = await self._session.post(
72+
to_url,
73+
data=json_content.encode("utf-8"),
74+
headers={
75+
"Authorization": f"Bearer:{token}",
76+
"Content-type": "application/json; charset=utf-8",
77+
},
8678
)
79+
resp.raise_for_status()
80+
content = await resp.json()
8781

88-
activity.recipient.properties[ReferrInfo.KEY] = referr.serialize()
89-
"""
90-
json_content = json.dumps(activity.serialize())
91-
with requests.Session() as session:
92-
resp = session.post(
93-
to_url,
94-
data=json_content.encode("utf-8"),
95-
headers={
96-
"Authorization": f"Bearer:{token}",
97-
"Content-type": "application/json; charset=utf-8",
98-
},
99-
)
100-
resp.raise_for_status()
101-
content = resp.json
102-
103-
if content:
104-
return InvokeResponse(status=resp.status_code, body=content)
82+
if content:
83+
return InvokeResponse(status=resp.status_code, body=content)
10584

10685
finally:
10786
# Restore activity properties.

0 commit comments

Comments
 (0)
0