mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-05-20 16:42:25 +00:00
fix(msteams): send threaded replies via replyToId
This commit is contained in:
parent
8a646d9aec
commit
d40ce81a3d
@ -220,7 +220,6 @@ class MSTeamsChannel(BaseChannel):
|
|||||||
token = await self._get_access_token()
|
token = await self._get_access_token()
|
||||||
base_url = f"{ref.service_url.rstrip('/')}/v3/conversations/{ref.conversation_id}/activities"
|
base_url = f"{ref.service_url.rstrip('/')}/v3/conversations/{ref.conversation_id}/activities"
|
||||||
use_thread_reply = self.config.reply_in_thread and bool(ref.activity_id)
|
use_thread_reply = self.config.reply_in_thread and bool(ref.activity_id)
|
||||||
url = f"{base_url}/{ref.activity_id}" if use_thread_reply else base_url
|
|
||||||
headers = {
|
headers = {
|
||||||
"Authorization": f"Bearer {token}",
|
"Authorization": f"Bearer {token}",
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@ -233,7 +232,7 @@ class MSTeamsChannel(BaseChannel):
|
|||||||
payload["replyToId"] = ref.activity_id
|
payload["replyToId"] = ref.activity_id
|
||||||
|
|
||||||
try:
|
try:
|
||||||
resp = await self._http.post(url, headers=headers, json=payload)
|
resp = await self._http.post(base_url, headers=headers, json=payload)
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
logger.info("MSTeams message sent to {}", ref.conversation_id)
|
logger.info("MSTeams message sent to {}", ref.conversation_id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@ -371,7 +371,7 @@ async def test_get_access_token_uses_configured_tenant(make_channel):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_send_replies_to_activity_when_reply_in_thread_enabled(make_channel):
|
async def test_send_posts_to_conversation_with_reply_to_id_when_reply_in_thread_enabled(make_channel):
|
||||||
ch = make_channel(replyInThread=True)
|
ch = make_channel(replyInThread=True)
|
||||||
fake_http = FakeHttpClient()
|
fake_http = FakeHttpClient()
|
||||||
ch._http = fake_http
|
ch._http = fake_http
|
||||||
@ -387,7 +387,7 @@ async def test_send_replies_to_activity_when_reply_in_thread_enabled(make_channe
|
|||||||
|
|
||||||
assert len(fake_http.calls) == 1
|
assert len(fake_http.calls) == 1
|
||||||
url, kwargs = fake_http.calls[0]
|
url, kwargs = fake_http.calls[0]
|
||||||
assert url == "https://smba.trafficmanager.net/amer/v3/conversations/conv-123/activities/activity-1"
|
assert url == "https://smba.trafficmanager.net/amer/v3/conversations/conv-123/activities"
|
||||||
assert kwargs["headers"]["Authorization"] == "Bearer tok"
|
assert kwargs["headers"]["Authorization"] == "Bearer tok"
|
||||||
assert kwargs["json"]["text"] == "Reply text"
|
assert kwargs["json"]["text"] == "Reply text"
|
||||||
assert kwargs["json"]["replyToId"] == "activity-1"
|
assert kwargs["json"]["replyToId"] == "activity-1"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user