Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion crates/chat/src/channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ use crate::{
agent_loop::ChannelReplyTargetKey, compaction_run, error, runtime::ChatRuntime, types::*,
};

/// Build the SPA URL for a push notification click-through.
///
/// Must match the frontend `sessionPath()` in `router.ts`:
/// `/chats/${key.replace(/:/g, "/")}`.
pub(crate) fn push_notification_url(session_key: &str) -> String {
format!("/chats/{}", session_key.replace(':', "/"))
}
Comment thread
penso marked this conversation as resolved.

#[cfg(feature = "push-notifications")]
pub(crate) async fn send_chat_push_notification(
state: &Arc<dyn ChatRuntime>,
Expand All @@ -28,7 +36,7 @@ pub(crate) async fn send_chat_push_notification(
};

let title = "Message received";
let url = format!("/chat/{session_key}");
let url = push_notification_url(session_key);

match state
.send_push_notification(title, &summary, Some(&url), Some(session_key))
Expand Down Expand Up @@ -1304,3 +1312,27 @@ pub(crate) async fn send_location_to_channels(
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn push_notification_url_uses_chats_prefix_and_replaces_colons() {
// Must match frontend sessionPath(): `/chats/${key.replace(/:/g, "/")}`
assert_eq!(push_notification_url("session:42"), "/chats/session/42");
}

#[test]
fn push_notification_url_handles_nested_session_keys() {
assert_eq!(
push_notification_url("telegram:bot123:chat456"),
"/chats/telegram/bot123/chat456"
);
}

#[test]
fn push_notification_url_handles_key_without_colons() {
assert_eq!(push_notification_url("main"), "/chats/main");
}
}
Loading