refactor: pass session_key as explicit param instead of via metadata
This commit is contained in:
@@ -89,7 +89,8 @@ class BaseChannel(ABC):
|
|||||||
chat_id: str,
|
chat_id: str,
|
||||||
content: str,
|
content: str,
|
||||||
media: list[str] | None = None,
|
media: list[str] | None = None,
|
||||||
metadata: dict[str, Any] | None = None
|
metadata: dict[str, Any] | None = None,
|
||||||
|
session_key: str | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Handle an incoming message from the chat platform.
|
Handle an incoming message from the chat platform.
|
||||||
@@ -102,6 +103,7 @@ class BaseChannel(ABC):
|
|||||||
content: Message text content.
|
content: Message text content.
|
||||||
media: Optional list of media URLs.
|
media: Optional list of media URLs.
|
||||||
metadata: Optional channel-specific metadata.
|
metadata: Optional channel-specific metadata.
|
||||||
|
session_key: Optional session key override (e.g. thread-scoped sessions).
|
||||||
"""
|
"""
|
||||||
if not self.is_allowed(sender_id):
|
if not self.is_allowed(sender_id):
|
||||||
logger.warning(
|
logger.warning(
|
||||||
@@ -111,15 +113,14 @@ class BaseChannel(ABC):
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
meta = metadata or {}
|
|
||||||
msg = InboundMessage(
|
msg = InboundMessage(
|
||||||
channel=self.name,
|
channel=self.name,
|
||||||
sender_id=str(sender_id),
|
sender_id=str(sender_id),
|
||||||
chat_id=str(chat_id),
|
chat_id=str(chat_id),
|
||||||
content=content,
|
content=content,
|
||||||
media=media or [],
|
media=media or [],
|
||||||
metadata=meta,
|
metadata=metadata or {},
|
||||||
session_key_override=meta.get("session_key"),
|
session_key_override=session_key,
|
||||||
)
|
)
|
||||||
|
|
||||||
await self.bus.publish_inbound(msg)
|
await self.bus.publish_inbound(msg)
|
||||||
|
|||||||
@@ -193,8 +193,8 @@ class SlackChannel(BaseChannel):
|
|||||||
"thread_ts": thread_ts,
|
"thread_ts": thread_ts,
|
||||||
"channel_type": channel_type,
|
"channel_type": channel_type,
|
||||||
},
|
},
|
||||||
"session_key": session_key,
|
|
||||||
},
|
},
|
||||||
|
session_key=session_key,
|
||||||
)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.exception("Error handling Slack message from {}", sender_id)
|
logger.exception("Error handling Slack message from {}", sender_id)
|
||||||
|
|||||||
Reference in New Issue
Block a user