Skip to content

Commit

Permalink
slack chat
Browse files Browse the repository at this point in the history
  • Loading branch information
pablonyx committed Dec 1, 2024
1 parent 897ed03 commit bdfa29d
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion web/src/app/chat/ChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export function ChatPage({
);

const { user, isAdmin, isLoadingUser } = useUser();

const slackChatId = searchParams.get("slackChatId");
const existingChatIdRaw = searchParams.get("chatId");
const [sendOnLoad, setSendOnLoad] = useState<string | null>(
searchParams.get(SEARCH_PARAM_NAMES.SEND_ON_LOAD)
Expand Down Expand Up @@ -440,6 +440,7 @@ export function ChatPage({
}
return;
}
setIsReady(true);
const shouldScrollToBottom =
visibleRange.get(existingChatSessionId) === undefined ||
visibleRange.get(existingChatSessionId)?.end == 0;
Expand Down Expand Up @@ -508,6 +509,9 @@ export function ChatPage({
await nameChatSession(existingChatSessionId);
refreshChatSessions();
}
} else if (newMessageHistory.length === 2 && !chatSession.description) {
await nameChatSession(existingChatSessionId);
refreshChatSessions();
}
}

Expand Down Expand Up @@ -1812,7 +1816,41 @@ export function ChatPage({
const [settingsToggled, setSettingsToggled] = useState(false);

const currentPersona = alternativeAssistant || liveAssistant;
useEffect(() => {
const handleSlackChatRedirect = async () => {
if (!slackChatId) return;

// Set isReady to false before starting retrieval to display loading text
setIsReady(false);

try {
const response = await fetch("/api/chat/seed-chat-session-from-slack", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
chat_session_id: slackChatId,
}),
});

if (!response.ok) {
throw new Error("Failed to seed chat from Slack");
}

const data = await response.json();
router.push(data.redirect_url);
} catch (error) {
console.error("Error seeding chat from Slack:", error);
setPopup({
message: "Failed to load chat from Slack",
type: "error",
});
}
};

handleSlackChatRedirect();
}, [searchParams, router]);
useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
if (event.metaKey || event.ctrlKey) {
Expand Down

0 comments on commit bdfa29d

Please sign in to comment.