feat: enable direct messaging initiation from agent profiles via agentProfileId query parameter
This commit is contained in:
@@ -127,7 +127,7 @@ interface ConnectedAgent {
|
||||
state: string | null;
|
||||
}
|
||||
|
||||
export function MessagingPage({ initialConversationId }: { initialConversationId?: string | null }) {
|
||||
export function MessagingPage({ initialConversationId, initialAgentProfileId }: { initialConversationId?: string | null; initialAgentProfileId?: string | null }) {
|
||||
const { data: session } = useSession();
|
||||
const {
|
||||
conversations,
|
||||
@@ -318,6 +318,31 @@ export function MessagingPage({ initialConversationId }: { initialConversationId
|
||||
}
|
||||
}, [initialConversationId, conversations, isLoading, selectConversation]);
|
||||
|
||||
// Auto-select or create conversation when navigated with initialAgentProfileId
|
||||
const initialAgentHandledRef = useRef<string | null>(null);
|
||||
useEffect(() => {
|
||||
if (
|
||||
initialAgentProfileId &&
|
||||
initialAgentHandledRef.current !== initialAgentProfileId &&
|
||||
conversations.length > 0 &&
|
||||
!isLoading
|
||||
) {
|
||||
initialAgentHandledRef.current = initialAgentProfileId;
|
||||
// Find existing conversation with this agent
|
||||
const existing = conversations.find(
|
||||
(c) => c.agentProfileId === initialAgentProfileId || c.otherParty?.id === initialAgentProfileId
|
||||
);
|
||||
if (existing) {
|
||||
selectConversation(existing.id);
|
||||
setShowMobileChat(true);
|
||||
} else {
|
||||
// Start a new conversation
|
||||
startConversation({ agentProfileId: initialAgentProfileId });
|
||||
setShowMobileChat(true);
|
||||
}
|
||||
}
|
||||
}, [initialAgentProfileId, conversations, isLoading, selectConversation, startConversation]);
|
||||
|
||||
// Convert current conversation avatar when selected
|
||||
useEffect(() => {
|
||||
const convertCurrentAvatar = async () => {
|
||||
|
||||
Reference in New Issue
Block a user