3
3
4
4
import json
5
5
from typing import Dict
6
- import requests
6
+ from logging import Logger
7
+ import aiohttp
7
8
8
9
from botbuilder .core import InvokeResponse
9
10
from botbuilder .schema import Activity
14
15
MicrosoftAppCredentials ,
15
16
)
16
17
17
- # from .referr_info import ReferrInfo
18
- from .skill_conversation import SkillConversation
19
-
20
18
21
19
class BotFrameworkHttpClient :
22
20
@@ -33,14 +31,15 @@ def __init__(
33
31
self ,
34
32
credential_provider : CredentialProvider ,
35
33
channel_provider : ChannelProvider = None ,
36
- logger : object = None ,
34
+ logger : Logger = None ,
37
35
):
38
36
if not credential_provider :
39
37
raise TypeError ("credential_provider can't be None" )
40
38
41
39
self ._credential_provider = credential_provider
42
40
self ._channel_provider = channel_provider
43
41
self ._logger = logger
42
+ self ._session = aiohttp .ClientSession ()
44
43
45
44
async def post_activity (
46
45
self ,
@@ -65,43 +64,23 @@ async def post_activity(
65
64
original_service_url = activity .service_url
66
65
67
66
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
75
68
activity .service_url = service_url
76
69
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
+ },
86
78
)
79
+ resp .raise_for_status ()
80
+ content = await resp .json ()
87
81
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 )
105
84
106
85
finally :
107
86
# Restore activity properties.
0 commit comments