{"slug": "i-built-a-research-mode-toggle-for-my-line-bot-that-actually", "title": "I built a research-mode toggle for my LINE bot that actually", "summary": "A developer built a research-mode toggle for a LINE bot that uses the Gemini API to turn a three-line summary into a cited, sectioned brief. The prompt instructs the model to fetch 8–12 authoritative sources from the last 18 months via Google Search Grounding and output a structured report with inline citations. The implementation costs about $0.018 per report and adds 3 seconds of latency, with a filter to drop paywalled PDFs except from arxiv.org or pubmed.ncbi.nlm.nih.gov.", "body_md": "# I built a research-mode toggle for my LINE bot that actually\n\n[Gemini](/en/tags/gemini/)API turned a three-line summary into a cited, sectioned brief you can actually trust. Below is the exact prompt I ship to the model, plus the wiring notes so you can drop it into your own webhook.\n\n## The prompt (copy-paste ready)\n\n```\nYou are a research analyst. The user provides a URL or topic.\n1. Use Google Search Grounding to fetch 8–12 authoritative sources published within the last 18 months.\n2. Synthesize a structured report with these sections:\n   • Executive Summary (3 bullets)\n   • Key Findings (numbered, each with inline citation like [1], [2])\n   • Contrasting Viewpoints (if sources disagree)\n   • Data Points & Metrics (table-friendly numbers with units)\n   • Open Questions / Gaps\n   • Source List (full title, publication, date, URL)\n3. Tone: professional, neutral, no fluff.\n4. Output language: match the user's input language.\n5. If grounding returns <4 usable sources, reply: \"Insufficient recent coverage — try a broader query.\"\n```\n\n## Why this prompt works\n\n**Explicit source count & recency** — \"8–12 sources, last 18 months\" stops the model from hallucinating old blog posts. **Section schema** — numbering the sections forces consistent structure; the frontend can render each as a collapsible card. **Inline citation contract** — `[1]`\n\nstyle tags map 1:1 to the Source List, so the LINE flex message can make them tap-to-open. **Failure guardrail** — the \"insufficient coverage\" line prevents confident-sounding nonsense when the topic is too niche.\n\n## Wiring it into the LINE webhook (Node sketch)\n\n```\n// webhook handler (express)\napp.post('/webhook', line.middleware(config), async (req, res) => {\n  await Promise.all(req.body.events.map(handleEvent));\n  res.sendStatus(200);\n});\n\nasync function handleEvent(event) {\n  if (event.type !== 'message' || event.message.type !== 'text') return;\n  const text = event.message.text.trim();\n\n  // user taps the \"Research Report\" quick-reply button → payload starts with \"research:\"\n  if (text.startsWith('research:')) {\n    const query = text.slice(9);\n    const report = await callGeminiWithGrounding(query);\n    await pushFlexReport(event.source.userId, report);\n  }\n}\n```\n\n`callGeminiWithGrounding`\n\nhits `generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro:generateContent`\n\nwith `tools: [{ googleSearchRetrieval: {} }]`\n\nand the prompt above in `systemInstruction`\n\n. The response's `groundingMetadata.groundingChunks`\n\ngives you the citation URLs — map those to the `[n]`\n\nmarkers before you build the flex JSON.\n\n## Cost & latency reality check\n\n**Tokens**: ~2.2k input / 1.8k output per report (Gemini 1.5 Pro)** Latency**: 6–9 s end-to-end (grounding adds ~3 s)** Bill**: ~$0.018 per report at current pricing — cheap enough for a freemium bot tier\n\n## One gotcha\n\nGrounding sometimes returns paywalled PDFs. I filter `groundingChunks`\n\nfor `web.uri`\n\ncontaining `.pdf`\n\nand drop them unless the domain is `arxiv.org`\n\nor `pubmed.ncbi.nlm.nih.gov`\n\n. Keeps the \"tap to open\" experience honest.\n\nShip the prompt, wire the webhook, and your users get a citeable brief instead of a paragraph guess.\n\n[Next Built a Reasoning Ledger prompt that captures why decisions →](/en/threads/7068/)\n\n## All Replies （4）\n\n[@NovaGuru](/en/users/NovaGuru/)URL hallucinations persist — tried a post-retrieval validator against a known domain list?", "url": "https://wpnews.pro/news/i-built-a-research-mode-toggle-for-my-line-bot-that-actually", "canonical_source": "https://promptcube3.com/en/threads/7069/", "published_at": "2026-08-20 16:47:54+00:00", "updated_at": "2026-08-20 17:15:31.765864+00:00", "lang": "en", "topics": ["artificial-intelligence", "large-language-models", "ai-tools", "generative-ai"], "entities": ["LINE", "Gemini", "Google Search Grounding", "Gemini 1.5 Pro", "arxiv.org", "pubmed.ncbi.nlm.nih.gov"], "alternates": {"html": "https://wpnews.pro/news/i-built-a-research-mode-toggle-for-my-line-bot-that-actually", "markdown": "https://wpnews.pro/news/i-built-a-research-mode-toggle-for-my-line-bot-that-actually.md", "text": "https://wpnews.pro/news/i-built-a-research-mode-toggle-for-my-line-bot-that-actually.txt", "jsonld": "https://wpnews.pro/news/i-built-a-research-mode-toggle-for-my-line-bot-that-actually.jsonld"}}