feat: enable direct messaging initiation from agent profiles via agentProfileId query parameter

This commit is contained in:
pradeepkumar
2026-03-29 17:40:06 +05:30
parent ada94f6b38
commit 86cacd9a5b
3 changed files with 29 additions and 3 deletions

View File

@@ -6,10 +6,11 @@ import { MessagingPage } from '@/components/message';
export default function UserMessagePage() { export default function UserMessagePage() {
const searchParams = useSearchParams(); const searchParams = useSearchParams();
const conversationId = searchParams.get('conversationId'); const conversationId = searchParams.get('conversationId');
const agentProfileId = searchParams.get('agentProfileId');
return ( return (
<div className="max-w-7xl mx-auto px-4 lg:px-8 py-6"> <div className="max-w-7xl mx-auto px-4 lg:px-8 py-6">
<MessagingPage initialConversationId={conversationId} /> <MessagingPage initialConversationId={conversationId} initialAgentProfileId={agentProfileId} />
</div> </div>
); );
} }

View File

@@ -342,7 +342,7 @@ export default function AgentProfileView() {
bio={profileCardData.bio || agentProfile.bio || ''} bio={profileCardData.bio || agentProfile.bio || ''}
expertise={profileCardData.expertise.length > 0 ? profileCardData.expertise : (agentProfile.specializations || [])} expertise={profileCardData.expertise.length > 0 ? profileCardData.expertise : (agentProfile.specializations || [])}
showEditButton={false} showEditButton={false}
messageHref="/user/message" messageHref={`/user/message?agentProfileId=${agentProfile.id}`}
connectionStatus={connectionStatus} connectionStatus={connectionStatus}
onConnectClick={() => setShowConnectModal(true)} onConnectClick={() => setShowConnectModal(true)}
onUnlinkClick={handleUnlink} onUnlinkClick={handleUnlink}

View File

@@ -127,7 +127,7 @@ interface ConnectedAgent {
state: string | null; 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 { data: session } = useSession();
const { const {
conversations, conversations,
@@ -318,6 +318,31 @@ export function MessagingPage({ initialConversationId }: { initialConversationId
} }
}, [initialConversationId, conversations, isLoading, selectConversation]); }, [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 // Convert current conversation avatar when selected
useEffect(() => { useEffect(() => {
const convertCurrentAvatar = async () => { const convertCurrentAvatar = async () => {