feat: Naver Search API + multi-account Instagram + button UX fix

- Naver Blog search: collect blog post results for clinic name (total count + top 10 posts)
- Naver Place search: collect place info (name, category, address, telephone)
- Multi-account Instagram: AI prompt requests all IG accounts (국내/해외)
- enrich-channels: process multiple IG handles with fallback per handle
- transformReport: merge multiple IG accounts into instagramAudit.accounts[]
- generate-report: socialHandles.instagram now array of handles
- Hero/CTA: transition-all → transition-shadow for instant click response
- Hero/CTA: disabled state when URL is empty (opacity-50 + cursor-not-allowed)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Haewon KamandClaude Opus 4.6 committed 2026-04-03 15:34:10 +09:00
1 parent cf482d1bd7
commit 72ea8f4a2d
8 files changed
+240 -68

No files matched your search

+125 -43
View File
@@ -14,6 +14,7 @@ interface EnrichRequest {
reportId: string;
clinicName: string;
instagramHandle?: string;
instagramHandles?: string[];
youtubeChannelId?: string;
address?: string;
}
@@ -47,9 +48,14 @@ Deno.serve(async (req) => {
}
try {
const { reportId, clinicName, instagramHandle, youtubeChannelId, address } =
const { reportId, clinicName, instagramHandle, instagramHandles, youtubeChannelId, address } =
(await req.json()) as EnrichRequest;
// Build list of IG handles to try: explicit array > single handle > empty
const igHandlesToTry: string[] = instagramHandles?.length
? instagramHandles
: instagramHandle ? [instagramHandle] : [];
const APIFY_TOKEN = Deno.env.get("APIFY_API_TOKEN");
if (!APIFY_TOKEN) throw new Error("APIFY_API_TOKEN not configured");
@@ -58,55 +64,70 @@ Deno.serve(async (req) => {
// Run all enrichment tasks in parallel
const tasks = [];
// 1. Instagram Profile — with fallback for wrong handle
const cleanIgHandle = normalizeInstagramHandle(instagramHandle);
if (cleanIgHandle) {
// 1. Instagram Profiles — multi-account with fallback
if (igHandlesToTry.length > 0) {
tasks.push(
(async () => {
// Try the given handle first, then common clinic variants
const handleCandidates = [
cleanIgHandle,
`${cleanIgHandle}_ps`, // banobagi → banobagi_ps
`${cleanIgHandle}.ps`, // banobagi → banobagi.ps
`${cleanIgHandle}_clinic`, // banobagi → banobagi_clinic
`${cleanIgHandle}_official`, // banobagi → banobagi_official
];
const accounts: Record<string, unknown>[] = [];
const triedHandles = new Set<string>();
for (const handle of handleCandidates) {
const items = await runApifyActor(
"apify~instagram-profile-scraper",
{ usernames: [handle], resultsLimit: 12 },
APIFY_TOKEN
);
const profile = (items as Record<string, unknown>[])[0];
for (const rawHandle of igHandlesToTry) {
const baseHandle = normalizeInstagramHandle(rawHandle);
if (!baseHandle || triedHandles.has(baseHandle)) continue;
if (profile && !profile.error) {
const followers = (profile.followersCount as number) || 0;
// Try the handle + common clinic variants
const candidates = [
baseHandle,
`${baseHandle}_ps`,
`${baseHandle}.ps`,
`${baseHandle}_clinic`,
`${baseHandle}_official`,
];
// Accept if: has meaningful followers OR is a business account with posts
if (followers >= 100 || ((profile.isBusinessAccount as boolean) && (profile.postsCount as number) > 10)) {
enrichment.instagram = {
username: profile.username,
followers: profile.followersCount,
following: profile.followsCount,
posts: profile.postsCount,
bio: profile.biography,
isBusinessAccount: profile.isBusinessAccount,
externalUrl: profile.externalUrl,
latestPosts: ((profile.latestPosts as Record<string, unknown>[]) || [])
.slice(0, 12)
.map((p) => ({
type: p.type,
likes: p.likesCount,
comments: p.commentsCount,
caption: (p.caption as string || "").slice(0, 200),
timestamp: p.timestamp,
})),
};
break; // Found a valid account
for (const handle of candidates) {
if (triedHandles.has(handle)) continue;
triedHandles.add(handle);
const items = await runApifyActor(
"apify~instagram-profile-scraper",
{ usernames: [handle], resultsLimit: 12 },
APIFY_TOKEN
);
const profile = (items as Record<string, unknown>[])[0];
if (profile && !profile.error) {
const followers = (profile.followersCount as number) || 0;
if (followers >= 100 || ((profile.isBusinessAccount as boolean) && (profile.postsCount as number) > 10)) {
accounts.push({
username: profile.username,
followers: profile.followersCount,
following: profile.followsCount,
posts: profile.postsCount,
bio: profile.biography,
isBusinessAccount: profile.isBusinessAccount,
externalUrl: profile.externalUrl,
latestPosts: ((profile.latestPosts as Record<string, unknown>[]) || [])
.slice(0, 6)
.map((p) => ({
type: p.type,
likes: p.likesCount,
comments: p.commentsCount,
caption: (p.caption as string || "").slice(0, 200),
timestamp: p.timestamp,
})),
});
break; // Found valid for this base handle, move to next
}
}
}
}
// Store as array for multi-account support
if (accounts.length > 0) {
enrichment.instagramAccounts = accounts;
// Keep backwards compat: first account as enrichment.instagram
enrichment.instagram = accounts[0];
}
})()
);
}
@@ -245,7 +266,68 @@ Deno.serve(async (req) => {
}
}
// 4. YouTube Channel (using YouTube Data API v3)
// 4. Naver Blog + Place Search (네이버 검색 API)
if (clinicName) {
const NAVER_CLIENT_ID = Deno.env.get("NAVER_CLIENT_ID");
const NAVER_CLIENT_SECRET = Deno.env.get("NAVER_CLIENT_SECRET");
if (NAVER_CLIENT_ID && NAVER_CLIENT_SECRET) {
const naverHeaders = {
"X-Naver-Client-Id": NAVER_CLIENT_ID,
"X-Naver-Client-Secret": NAVER_CLIENT_SECRET,
};
// 4a. Blog search — "{clinicName} 후기"
tasks.push(
(async () => {
const query = encodeURIComponent(`${clinicName} 후기`);
const res = await fetch(
`https://openapi.naver.com/v1/search/blog.json?query=${query}&display=10&sort=sim`,
{ headers: naverHeaders }
);
if (!res.ok) return;
const data = await res.json();
enrichment.naverBlog = {
totalResults: data.total || 0,
searchQuery: `${clinicName} 후기`,
posts: (data.items || []).slice(0, 10).map((item: Record<string, string>) => ({
title: (item.title || "").replace(/<[^>]*>/g, ""),
description: (item.description || "").replace(/<[^>]*>/g, "").slice(0, 200),
link: item.link,
bloggerName: item.bloggername,
postDate: item.postdate,
})),
};
})()
);
// 4b. Local search — Naver Place
tasks.push(
(async () => {
const query = encodeURIComponent(clinicName);
const res = await fetch(
`https://openapi.naver.com/v1/search/local.json?query=${query}&display=5&sort=comment`,
{ headers: naverHeaders }
);
if (!res.ok) return;
const data = await res.json();
const place = (data.items || [])[0];
if (place) {
enrichment.naverPlace = {
name: (place.title || "").replace(/<[^>]*>/g, ""),
category: place.category,
address: place.roadAddress || place.address,
telephone: place.telephone,
link: place.link,
mapx: place.mapx,
mapy: place.mapy,
};
}
})()
);
}
}
// 5. YouTube Channel (using YouTube Data API v3)
if (youtubeChannelId) {
const YOUTUBE_API_KEY = Deno.env.get("YOUTUBE_API_KEY");
if (YOUTUBE_API_KEY) {
+15 -2
View File
@@ -94,7 +94,7 @@ ${JSON.stringify(analyzeResult.data?.analysis || {}, null, 2)}
"services": ["시술1", "시술2"],
"doctors": [{"name": "의사명", "specialty": "전문분야"}],
"socialMedia": {
"instagram": "정확한 Instagram 핸들 (@ 없이, 예: banobagi_ps)",
"instagramAccounts": ["국내용 핸들", "해외/영문 핸들", "기타 관련 계정 (@ 없이, 예: banobagi_ps, english_banobagi)"],
"youtube": "YouTube 채널 핸들 또는 URL",
"facebook": "Facebook 페이지명",
"naverBlog": "네이버 블로그 ID"
@@ -174,8 +174,21 @@ ${JSON.stringify(analyzeResult.data?.analysis || {}, null, 2)}
// Merge social handles: AI-found (more accurate) > Firecrawl-extracted (fallback)
const scrapeSocial = clinic.socialMedia || {};
const aiSocial = report?.clinicInfo?.socialMedia || {};
// Instagram: collect all accounts from AI + Firecrawl, deduplicate
const aiIgAccounts: string[] = Array.isArray(aiSocial.instagramAccounts)
? aiSocial.instagramAccounts
: aiSocial.instagram ? [aiSocial.instagram] : [];
const scrapeIg = scrapeSocial.instagram ? [scrapeSocial.instagram] : [];
const allIgRaw = [...aiIgAccounts, ...scrapeIg];
const igHandles = [...new Set(
allIgRaw
.map((h: string) => normalizeInstagramHandle(h))
.filter((h): h is string => h !== null)
)];
const normalizedHandles = {
instagram: normalizeInstagramHandle(aiSocial.instagram) || normalizeInstagramHandle(scrapeSocial.instagram),
instagram: igHandles.length > 0 ? igHandles : null, // array of handles
youtube: aiSocial.youtube || scrapeSocial.youtube || null,
facebook: aiSocial.facebook || scrapeSocial.facebook || null,
blog: aiSocial.naverBlog || scrapeSocial.blog || null,