feat: Enable agents to initiate conversations with connected users and refactor the conversation start flow to be role-aware.

This commit is contained in:
pradeepkumar
2026-03-15 00:29:25 +05:30
parent 9acb0063fa
commit 50640a5828
6 changed files with 289 additions and 23 deletions

View File

@@ -34,7 +34,7 @@ interface UseMessagingReturn {
disconnect: () => void;
loadConversations: () => Promise<void>;
selectConversation: (conversationId: string) => Promise<void>;
startConversation: (agentProfileId: string) => Promise<Conversation>;
startConversation: (body: { agentProfileId?: string; userId?: string }) => Promise<Conversation>;
sendMessage: (content: string, messageType?: MessageType, fileFields?: { fileUrl?: string; mimeType?: string; fileName?: string; fileSize?: number }) => Promise<void>;
loadMoreMessages: () => Promise<void>;
startTyping: () => void;
@@ -163,10 +163,10 @@ export function useMessaging(options: UseMessagingOptions = {}): UseMessagingRet
[isConnected]
);
// Start a new conversation with an agent
// Start a new conversation with an agent (for users) or a user (for agents)
const startConversation = useCallback(
async (agentProfileId: string): Promise<Conversation> => {
const conversation = await messagesService.startConversation(agentProfileId);
async (body: { agentProfileId?: string; userId?: string }): Promise<Conversation> => {
const conversation = await messagesService.startConversation(body);
// Add to conversations list if not exists
setConversations((prev) => {