Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

feat(backend/copilot-bot): DM delivery for proactive posts (#13597)

Bentlyb5d46191df66
diff --git a/autogpt_platform/backend/backend/copilot/bot/adapters/base.py b/autogpt_platform/backend/backend/copilot/bot/adapters/base.py
index 3a2301e6f7..71a0090be9 100644
--- a/autogpt_platform/backend/backend/copilot/bot/adapters/base.py
+++ b/autogpt_platform/backend/backend/copilot/bot/adapters/base.py
@@ -362,6 +362,16 @@ class PlatformAdapter(ABC):
"""
...
+ async def open_dm_channel(self, platform_user_id: str) -> Optional[str]:
+ """Open (or fetch) the bot's 1:1 DM channel with ``platform_user_id``.
+
+ Returns a channel ID usable with ``post_channel_message``, or ``None``
+ when the platform/configuration can't DM this user. Default:
+ unsupported — the proactive DM path then reports the platform can't
+ deliver DMs rather than attempting a send.
+ """
+ return None
+
@abstractmethod
async def post_channel_message(
self, channel_id: str, text: str
diff --git a/autogpt_platform/backend/backend/copilot/bot/adapters/discord/adapter.py b/autogpt_platform/backend/backend/copilot/bot/adapters/discord/adapter.py
index 29019ea1d1..6141293f4f 100644
--- a/autogpt_platform/backend/backend/copilot/bot/adapters/discord/adapter.py
+++ b/autogpt_platform/backend/backend/copilot/bot/adapters/discord/adapter.py
@@ -280,6 +280,17 @@ class DiscordAdapter(SocketAdapter):
return str(channel.guild.id)
return None
+ async def open_dm_channel(self, platform_user_id: str) -> Optional[str]:
+ try:
+ user = self._client.get_user(
+ int(platform_user_id)
+ ) or await self._client.fetch_user(int(platform_user_id))
+ dm = user.dm_channel or await user.create_dm()
+ except (ValueError, discord.NotFound, discord.HTTPException):
+ logger.warning(f"Cannot open DM with user {platform_user_id}")
+ return None
+ return str(dm.id)
+
async def post_channel_message(
self, channel_id: str, text: str
) -> Optional[PostedRef]:
diff --git a/autogpt_platform/backend/backend/copilot/bot/adapters/slack/adapter.py b/autogpt_platform/backend/backend/copilot/bot/adapters/slack/adapter.py
index 1a12167a5b..330fb523db 100644
--- a/autogpt_platform/backend/backend/copilot/bot/adapters/slack/adapter.py
+++ b/autogpt_platform/backend/backend/copilot/bot/adapters/slack/adapter.py
@@ -466,6 +466,20 @@ class SlackAdapter(WebhookAdapter):
except Exception:
return None
+ async def open_dm_channel(self, platform_user_id: str) -> Optional[str]:
+ # A DM link carries no workspace, so this resolves via the static
+ # single-workspace token — multi-workspace installs can't be picked
+ # without a team id on the user link.
+ client = await self._client_for("")
+ if client is None:
+ return None
+ try:
+ resp = await client.conversations_open(users=platform_user_id)
+ except Exception:
+ logger.warning(f"Cannot open Slack DM with user {platform_user_id}")
+ return None
+ return (resp.get("channel") or {}).get("id") or None
+
async def post_channel_message(
self, channel_id: str, text: str
) -> Optional[PostedRef]:
diff --git a/autogpt_platform/backend/backend/copilot/bot/adapters/telegram/adapter.py b/autogpt_platform/backend/backend/copilot/bot/adapters/telegram/adapter.py
index 92a43e9c8c..58a6ad91d9 100644
--- a/autogpt_platform/backend/backend/copilot/bot/adapters/telegram/adapter.py
+++ b/autogpt_platform/backend/backend/copilot/bot/adapters/telegram/adapter.py
@@ -478,6 +478,11 @@ class TelegramAdapter(WebhookAdapter):
return str(chat.get("id"))
return None
+ async def open_dm_channel(self, platform_user_id: str) -> Optional[str]:
+ # A Telegram private chat's ID is the user's own numeric ID — no open
+ # call exists or is needed.
+ return platform_user_id
+
async def post_channel_message(
self, channel_id: str, text: str
) -> Optional[PostedRef]:
diff --git a/autogpt_platform/backend/backend/copilot/bot/app.py b/autogpt_platform/backend/backend/copilot/bot/app.py
index 6b35867341..d978e41fc1 100644
--- a/autogpt_platform/backend/backend/copilot/bot/app.py
+++ b/autogpt_platform/backend/backend/copilot/bot/app.py
@@ -170,6 +170,21 @@ class CoPilotChatBridge(AppService):
adapter, api, platform.value, user_id, channel, content
)
+ @expose
+ async def send_dm_to_user(
+ self,
+ platform: Platform,
+ user_id: str,
+ content: str,
+ ) -> DeliveryResult:
+ """Send ``content`` to ``user_id``'s own DM with the bot.
+
+ The target is resolved from the user's DM link — never a
+ caller-supplied recipient — so a user can only DM themself.
+ """
+ adapter, api = self._require(platform)
+ return await outbound.deliver_dm(adapter, api, platform.value, user_id, content)
+
@expose
async def create_thread_in_channel(
self,
@@ -195,6 +210,7 @@ class CoPilotChatBridgeClient(AppServiceClient):
send_message_to_channel = endpoint_to_async(
CoPilotChatBridge.send_message_to_channel
)
+ send_dm_to_user = endpoint_to_async(CoPilotChatBridge.send_dm_to_user)
create_thread_in_channel = endpoint_to_async(
CoPilotChatBridge.create_thread_in_channel
)
diff --git a/autogpt_platform/backend/backend/copilot/bot/bot_backend.py b/autogpt_platform/backend/backend/copilot/bot/bot_backend.py
index da162815eb..fc1be08c2a 100644
--- a/autogpt_platform/backend/backend/copilot/bot/bot_backend.py
+++ b/autogpt_platform/backend/backend/copilot/bot/bot_backend.py
@@ -254,6 +254,17 @@ class BotBackend:
user_id=user_id,
)
+ async def get_dm_user_id(self, platform: str, user_id: str) -> str | None:
+ """Return the platform user ID behind ``user_id``'s DM link, or None.
+
+ Backs proactive DM delivery: the target is always the caller's own
+ linked account, so authorization is the link itself.
+ """
+ return await self._client.get_user_dm_id(
+ platform=Platform(platform.upper()),
+ user_id=user_id,
+ )
+
async def refresh_server_name(
self, platform: str, platform_server_id: str, server_name: str
) -> None:
diff --git a/autogpt_platform/backend/backend/copilot/bot/outbound.py b/autogpt_platform/backend/backend/copilot/bot/outbound.py
index a97aa5aca4..b0d5713dbf 100644
--- a/autogpt_platform/backend/backend/copilot/bot/outbound.py
+++ b/autogpt_platform/backend/backend/copilot/bot/outbound.py
@@ -34,7 +34,7 @@ class DeliveryResult(BaseModel):
"""
ok: bool
- kind: Literal["message", "thread"]
+ kind: Literal["message", "thread", "dm"]
channel_id: Optional[str] = None
ref_id: Optional[str] = None
url: Optional[str] = None
@@ -86,6 +86,37 @@ async def deliver_message(
)
+async def deliver_dm(
+ adapter: PlatformAdapter,
+ api: BotBackend,
+ platform: str,
+ user_id: str,
+ content: str,
+) -> DeliveryResult:
+ """Send ``content`` to ``user_id``'s own DM with the bot.
+
+ Authorization is the DM link itself: the target is always the calling
+ user's linked platform account, never a caller-supplied recipient — so a
+ user can only ever DM themself.
+ """
+ if not content or not content.strip():
+ return DeliveryResult(ok=False, kind="dm", error="empty_content")
+ platform_user_id = await api.get_dm_user_id(platform, user_id)
+ if platform_user_id is None:
+ return DeliveryResult(ok=False, kind="dm", error="no_dm_link")
+ channel_id = await adapter.open_dm_channel(platform_user_id)
+ if channel_id is None:
+ return DeliveryResult(ok=False, kind="dm", error="dm_unavailable")
+ ref = await adapter.post_channel_message(channel_id, content)
+ if ref is None:
+ return DeliveryResult(
+ ok=False, kind="dm", channel_id=channel_id, error="send_failed"
+ )
+ return DeliveryResult(
+ ok=True, kind="dm", channel_id=channel_id, ref_id=ref.id, url=ref.url
+ )
+
+
async def create_thread(
adapter: PlatformAdapter,
api: BotBackend,
diff --git a/autogpt_platform/backend/backend/copilot/bot/outbound_test.py b/autogpt_platform/backend/backend/copilot/bot/outbound_test.py
index 26b8969a50..86f33da73f 100644
--- a/autogpt_platform/backend/backend/copilot/bot/outbound_test.py
+++ b/autogpt_platform/backend/backend/copilot/bot/outbound_test.py
@@ -21,6 +21,7 @@ def _adapter(
channel_server: str | None = None,
posted: PostedRef | None = None,
thread: PostedRef | None = None,
+ dm_channel: str | None = None,
) -> AsyncMock:
adapter = AsyncMock()
# Sync classifier — mirrors Discord's numeric-snowflake grammar so
@@ -32,6 +33,7 @@ def _adapter(
adapter.get_channel_server_id.return_value = channel_server
adapter.post_channel_message.return_value = posted
adapter.create_channel_thread.return_value = thread
+ adapter.open_dm_channel.return_value = dm_channel
return adapter
@@ -187,6 +189,63 @@ async def test_create_thread_failure():
assert result.error == "thread_failed"
+def _dm_api(dm_user_id: str | None) -> AsyncMock:
+ api = AsyncMock()
+ api.get_dm_user_id.return_value = dm_user_id
+ return api
+
+
+async def test_deliver_dm_happy_path():
+ adapter = _adapter(dm_channel="dm-42", posted=PostedRef(id="100", url="https://x"))
+ result = await outbound.deliver_dm(adapter, _dm_api("pu1"), "discord", "u1", "hi")
+ assert result.ok is True
+ assert result.kind == "dm"
+ assert result.channel_id == "dm-42"
+ assert result.ref_id == "100"
+ adapter.open_dm_channel.assert_awaited_once_with("pu1")
+ adapter.post_channel_message.assert_awaited_once_with("dm-42", "hi")
+
+
+async def test_deliver_dm_without_link_is_rejected():
+ adapter = _adapter(dm_channel="dm-42", posted=PostedRef(id="100"))
+ result = await outbound.deliver_dm(adapter, _dm_api(None), "discord", "u1", "hi")
+ assert result.ok is False
+ assert result.error == "no_dm_link"
+ adapter.open_dm_channel.assert_not_awaited()
+ adapter.post_channel_message.assert_not_awaited()
+
+
+async def test_deliver_dm_unopenable_channel():
+ adapter = _adapter(dm_channel=None, posted=PostedRef(id="100"))
+ result = await outbound.deliver_dm(adapter, _dm_api("pu1"), "discord", "u1", "hi")
+ assert result.ok is False
+ assert result.error == "dm_unavailable"
+ adapter.post_channel_message.assert_not_awaited()
+
+
+async def test_deliver_dm_send_failure():
+ adapter = _adapter(dm_channel="dm-42", posted=None)
+ result = await outbound.deliver_dm(adapter, _dm_api("pu1"), "discord", "u1", "hi")
+ assert result.ok is False
+ assert result.error == "send_failed"
+ assert result.channel_id == "dm-42"
+
+
+async def test_deliver_dm_empty_content_is_distinct_error():
+ adapter = _adapter(dm_channel="dm-42")
+ api = _dm_api("pu1")
+ result = await outbound.deliver_dm(adapter, api, "discord", "u1", " ")
+ assert result.ok is False
+ assert result.error == "empty_content"
+ api.get_dm_user_id.assert_not_awaited()
+ adapter.post_channel_message.assert_not_awaited()
+
+
@pytest.mark.asyncio
async def test_list_channels_empty_without_links():
adapter = _adapter(channels=[ChannelInfo(id="42", name="x", server_id="g1")])
diff --git a/autogpt_platform/backend/backend/copilot/tools/chat_platform.py b/autogpt_platform/backend/backend/copilot/tools/chat_platform.py
index b64099c0a3..2abe5d587e 100644
--- a/autogpt_platform/backend/backend/copilot/tools/chat_platform.py
+++ b/autogpt_platform/backend/backend/copilot/tools/chat_platform.py
@@ -11,7 +11,8 @@ A single ``platform`` enum keeps the tool surface flat as platforms are added,
instead of one ``post_to_<platform>`` tool per platform. Delivery and
authorization live in the bot bridge (``CoPilotChatBridge``): the tool only
forwards over RPC, and a post is only allowed into channels of a server the
-calling user has linked — enforced bridge-side.
+calling user has linked, or (``target='dm'``) into the user's own DM with the
+bot via their DM link — enforced bridge-side.
``list_chat_platform_channels`` backs channel-name disambiguation and the
"pick a channel" flow.
@@ -76,6 +77,13 @@ _ERROR_MESSAGES: dict[str, str] = {
"Couldn't create the thread — the bot likely lacks permission to "
"create public threads in that channel."
),
+ "no_dm_link": (
+ "The user's DMs aren't linked on that platform yet. They can link "
+ "them by DMing the bot and running its setup command."
+ ),
+ "dm_unavailable": (
+ "The bot couldn't open a DM with the user's linked account on that " "platform."
+ ),
}
@@ -131,11 +139,7 @@ def _platform_param() -> dict[str, Any]:
return {
"type": "string",
"enum": list(SUPPORTED_PLATFORMS),
- "description": (
- "Chat platform to post to: 'discord' (default), 'slack', or "
- "'telegram'. On Telegram, 'channel' must be the numeric chat ID "
- "of a linked group (names can't be listed there)."
- ),
+ "description": "Chat platform to post to; defaults to 'discord'.",
}
@@ -157,13 +161,14 @@ class PostToChatPlatformTool(BaseTool):
@property
def description(self) -> str:
return (
- "Post to a linked chat platform (Discord, Slack, or Telegram) for "
- "the user. mode='message' sends a message; mode='thread' opens a "
- "new thread (needs thread_name). 'channel' is a name (#standup) or "
- "numeric ID — on Telegram it must be a linked group's numeric chat "
- "ID. Pair with schedule_followup for recurring posts. On Discord "
- "or Slack, if the channel can't be resolved, call "
- "list_chat_platform_channels first."
+ "Post to a linked chat platform (Discord, Slack, or Telegram). "
+ "target='dm' sends to the user's own DMs with the bot. "
+ "mode='thread' opens a thread (needs thread_name; "
+ "channels only). 'channel' is a name (#standup) or numeric ID — "
+ "on Telegram, a linked group's numeric chat ID. Pair with "
+ "schedule_followup for recurring posts; call "
+ "list_chat_platform_channels if a Discord/Slack channel won't "
+ "resolve."
)
@property
@@ -180,9 +185,21 @@ class PostToChatPlatformTool(BaseTool):
"type": "object",
"properties": {
"platform": _platform_param(),
+ "target": {
+ "type": "string",
+ "enum": ["channel", "dm"],
+ "description": (
+ "'channel' (default) posts to a server channel; 'dm' "
+ "goes to the user's own DMs with the bot (needs their "
+ "DM link, no channel)."
+ ),
+ },
"channel": {
"type": "string",
- "description": "Channel name (#standup) or numeric ID.",
+ "description": (
+ "Channel name (#standup) or numeric ID. Required "
+ "unless target='dm'."
+ ),
},
"content": {
"type": "string",
@@ -198,7 +215,7 @@ class PostToChatPlatformTool(BaseTool):
"description": "Thread title; required when mode='thread'.",
},
},
- "required": ["channel", "content"],
+ "required": ["content"],
}
@staticmethod
@@ -211,10 +228,23 @@ class PostToChatPlatformTool(BaseTool):
error="unsupported_platform",
session_id=session_id,
)
+ target: str = kwargs.get("target") or "channel"
+ if target not in ("channel", "dm"):
+ return ErrorResponse(
+ message="`target` must be 'channel' or 'dm'.",
+ error="invalid_target",
+ session_id=session_id,
+ )
channel: str | None = kwargs.get("channel")
content: str | None = kwargs.get("content")
mode: str = kwargs.get("mode") or "message"
- if not channel or not channel.strip():
+ if target == "dm" and mode == "thread":
+ return ErrorResponse(
+ message="Threads can't be created in a DM — use mode='message'.",
+ error="invalid_mode",
+ session_id=session_id,
+ )
+ if target == "channel" and (not channel or not channel.strip()):
return ErrorResponse(
message="`channel` is required.",
error="missing_channel",
@@ -266,12 +296,19 @@ class PostToChatPlatformTool(BaseTool):
error="unsupported_platform",
session_id=session_id,
)
- channel: str = kwargs["channel"]
+ target: str = kwargs.get("target") or "channel"
+ channel: str = kwargs.get("channel") or ""
content: str = kwargs["content"]
mode: str = kwargs.get("mode") or "message"
client = get_copilot_chat_bridge_client()
- if mode == "thread":
+ if target == "dm":
+ result = await client.send_dm_to_user(
+ platform=platform,
+ user_id=user_id,
+ content=content,
+ )
+ elif mode == "thread":
result = await client.create_thread_in_channel(
platform=platform,
user_id=user_id,
@@ -294,7 +331,7 @@ class PostToChatPlatformTool(BaseTool):
session_id=session_id,
)
- where = "thread" if result.kind == "thread" else "message"
+ where = {"thread": "thread", "dm": "DM"}.get(result.kind, "message")
link_note = f" ({result.url})" if result.url else ""
return ChatPlatformPostedResponse(
message=f"Posted {where} to {platform_name}{link_note}.",
@@ -317,10 +354,11 @@ class ListChatPlatformChannelsTool(BaseTool):
@property
def description(self) -> str:
return (
- "List channels the bot can post to on a linked chat platform "
- "(Discord or Slack). Use to resolve a channel name to an ID or "
- "pick one before post_to_chat_platform. Telegram can't list "
- "channels — post there with a linked group's numeric chat ID."
+ "List server channels the bot can post to on Discord or Slack — "
+ "use to resolve a channel name to an ID before "
+ "post_to_chat_platform. Telegram can't list channels (use a "
+ "linked group's numeric chat ID). The user's own DMs never "
+ "appear here — use target='dm' instead."
)
@property
diff --git a/autogpt_platform/backend/backend/copilot/tools/chat_platform_test.py b/autogpt_platform/backend/backend/copilot/tools/chat_platform_test.py
index 624a29b57a..4c0f81f897 100644
--- a/autogpt_platform/backend/backend/copilot/tools/chat_platform_test.py
+++ b/autogpt_platform/backend/backend/copilot/tools/chat_platform_test.py
@@ -32,6 +32,7 @@ def _bridge() -> MagicMock:
bridge = MagicMock()
bridge.send_message_to_channel = AsyncMock()
bridge.create_thread_in_channel = AsyncMock()
+ bridge.send_dm_to_user = AsyncMock()
bridge.list_channels = AsyncMock()
return bridge
@@ -194,6 +195,70 @@ async def test_post_thread_failed_maps_error(session):
assert result.error == "thread_failed"
+async def test_post_dm_happy_path_needs_no_channel(session):
+ bridge = _bridge()
+ bridge.send_dm_to_user.return_value = DeliveryResult(
+ ok=True, kind="dm", channel_id="dm-1", ref_id="m1"
+ )
+ with patch(f"{_PATH}.get_copilot_chat_bridge_client", return_value=bridge):
+ result = await PostToChatPlatformTool()._execute(
+ user_id=_USER, session=session, target="dm", content="morning brief"
+ )
+ assert isinstance(result, ChatPlatformPostedResponse)
+ assert result.kind == "dm"
+ assert "DM" in result.message
+ bridge.send_dm_to_user.assert_awaited_once()
+ bridge.send_message_to_channel.assert_not_awaited()
+
+
+async def test_post_dm_without_link_maps_error(session):
+ bridge = _bridge()
+ bridge.send_dm_to_user.return_value = DeliveryResult(
+ ok=False, kind="dm", error="no_dm_link"
+ )
+ with patch(f"{_PATH}.get_copilot_chat_bridge_client", return_value=bridge):
+ result = await PostToChatPlatformTool()._execute(
+ user_id=_USER, session=session, target="dm", content="hi"
+ )
+ assert isinstance(result, ErrorResponse)
+ assert result.error == "no_dm_link"
+ assert "aren't linked" in result.message
+
+
+async def test_post_dm_rejects_thread_mode(session):
+ result = await PostToChatPlatformTool()._execute(
+ user_id=_USER,
+ session=session,
+ target="dm",
+ content="hi",
+ mode="thread",
+ thread_name="Nope",
+ )
+ assert isinstance(result, ErrorResponse)
+ assert result.error == "invalid_mode"
+
+
+async def test_post_invalid_target(session):
+ result = await PostToChatPlatformTool()._execute(
+ user_id=_USER, session=session, target="carrier-pigeon", content="hi"
+ )
+ assert isinstance(result, ErrorResponse)
+ assert result.error == "invalid_target"
+
+
+async def test_post_channel_target_still_requires_channel(session):
+ result = await PostToChatPlatformTool()._execute(
+ user_id=_USER, session=session, content="hi"
+ )
+ assert isinstance(result, ErrorResponse)
+ assert result.error == "missing_channel"
+
+
@pytest.mark.asyncio
async def test_post_unavailable_without_token():
with patch(f"{_PATH}._any_chat_platform_configured", return_value=False):
diff --git a/autogpt_platform/backend/backend/copilot/tools/models.py b/autogpt_platform/backend/backend/copilot/tools/models.py
index 9a977beead..ebd9a2de57 100644
--- a/autogpt_platform/backend/backend/copilot/tools/models.py
+++ b/autogpt_platform/backend/backend/copilot/tools/models.py
@@ -1056,11 +1056,11 @@ class ChatPlatformChannelListResponse(ToolResponseBase):
class ChatPlatformPostedResponse(ToolResponseBase):
- """Response after the bot posts a message or creates a thread."""
+ """Response after the bot posts a message, creates a thread, or DMs."""
type: ResponseType = ResponseType.CHAT_PLATFORM_POSTED
platform: str
- kind: Literal["message", "thread"]
+ kind: Literal["message", "thread", "dm"]
channel_id: str
ref_id: str | None = None
url: str | None = None
diff --git a/autogpt_platform/backend/backend/platform_linking/manager.py b/autogpt_platform/backend/backend/platform_linking/manager.py
index 0522f74ea6..4cc64b110b 100644
--- a/autogpt_platform/backend/backend/platform_linking/manager.py
+++ b/autogpt_platform/backend/backend/platform_linking/manager.py
@@ -83,6 +83,19 @@ class PlatformLinkingManager(AppService):
link.platform_server_id for link in links if link.platform == platform.value
]
+ @expose
+ async def get_user_dm_id(self, platform: Platform, user_id: str) -> str | None:
+ """Bot-scoped: the platform user ID behind ``user_id``'s DM link, if any.
+
+ Backs proactive DM delivery — the returned ID is always the calling
+ user's own linked account, so a DM post can never target anyone else.
+ """
+ links = await platform_linking_db().list_user_links(user_id)
+ for link in links:
+ if link.platform == platform.value:
+ return link.platform_user_id
+ return None
+
@expose
async def ensure_chat_session(
self,
@@ -169,6 +182,7 @@ class PlatformLinkingManagerClient(AppServiceClient):
list_user_server_ids = endpoint_to_async(
PlatformLinkingManager.list_user_server_ids
)
+ get_user_dm_id = endpoint_to_async(PlatformLinkingManager.get_user_dm_id)
ensure_chat_session = endpoint_to_async(PlatformLinkingManager.ensure_chat_session)
start_chat_turn = endpoint_to_async(PlatformLinkingManager.start_chat_turn)
upload_workspace_file = endpoint_to_async(
diff --git a/autogpt_platform/backend/backend/platform_linking/manager_test.py b/autogpt_platform/backend/backend/platform_linking/manager_test.py
index b33b33729b..16b7415831 100644
--- a/autogpt_platform/backend/backend/platform_linking/manager_test.py
+++ b/autogpt_platform/backend/backend/platform_linking/manager_test.py
@@ -42,6 +42,7 @@ class TestManagerWiring:
"get_link_token_status",
"start_chat_turn",
"list_user_server_ids",
+ "get_user_dm_id",
}
for name in expected:
assert hasattr(
@@ -90,6 +91,24 @@ class TestManagerWiring:
db_mock.resolve_user_link.assert_awaited_once_with("DISCORD", "pu1")
assert result.linked is False
+ @pytest.mark.asyncio
+ async def test_get_user_dm_id_returns_matching_platform_link(self):
+ manager = PlatformLinkingManager()
+ db_mock = MagicMock()
+ db_mock.list_user_links = AsyncMock(
+ return_value=[
+ MagicMock(platform="TELEGRAM", platform_user_id="tg-9"),
+ MagicMock(platform="DISCORD", platform_user_id="dc-7"),
+ ]
+ )
+ with patch(
+ "backend.platform_linking.manager.platform_linking_db",
+ return_value=db_mock,
+ ):
+ assert await manager.get_user_dm_id(Platform.DISCORD, "u1") == "dc-7"
+ assert await manager.get_user_dm_id(Platform.SLACK, "u1") is None
+ db_mock.list_user_links.assert_awaited_with("u1")
+
@pytest.mark.asyncio
async def test_create_server_link_token_delegates(self):
manager = PlatformLinkingManager()