From bb2bd77a64d8a41afd8c8f9a86f22990f00af39e Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Sun, 15 Sep 2024 18:54:58 -0700 Subject: [PATCH] Send chat message to Khoj web app via url query param - This allows triggering khoj chat from the browser addressbar - So now if you add Khoj to your browser bookmark with - URL: https://app.khoj.dev/?q=%s - Keyword: khoj - Then you can type "khoj what is the news today" to trigger Khoj to quickly respond to your query. This avoids having to open the Khoj web app before asking your question --- src/interface/web/app/page.tsx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/interface/web/app/page.tsx b/src/interface/web/app/page.tsx index a20e09c15..e6627c285 100644 --- a/src/interface/web/app/page.tsx +++ b/src/interface/web/app/page.tsx @@ -22,6 +22,7 @@ import { getIconFromIconName } from "@/app/common/iconUtils"; import { AgentData } from "@/app/agents/page"; import { createNewConversation } from "./common/chatFunctions"; import { useIsMobileWidth } from "./common/utils"; +import { useSearchParams } from "next/navigation"; interface ChatBodyDataProps { chatOptionsData: ChatOptions | null; @@ -51,6 +52,14 @@ function ChatBodyData(props: ChatBodyDataProps) { const [agentIcons, setAgentIcons] = useState([]); const [agents, setAgents] = useState([]); const [showLoginPrompt, setShowLoginPrompt] = useState(false); + const searchParams = useSearchParams(); + const queryParam = searchParams.get("q"); + + useEffect(() => { + if (queryParam) { + setMessage(decodeURIComponent(queryParam)); + } + }, [queryParam]); const onConversationIdChange = props.onConversationIdChange;