最佳实践:HubSpot留资工具
Last updated
Was this helpful?
Was this helpful?
// 统一取 payload(兼容 Webhook 是否包 body)
const payload = $json.body ?? $json;
// 安全取 WhatsApp 消息对象
const wa = payload.whatsappInboundMessage ?? {};
// 取文本
const text = (wa.text?.body || "").trim();
// 取手机号(identity)
const phone = wa.from || "";
// 默认输出
let result = {
is_lead: false,
lead_score: 0,
intent: "unknown",
phone,
reason: "",
text: text,
nextstep: false
};
/**
* 空 / 极短
*/
if (!text || text.length < 2) {
result.intent = "spam";
result.reason = "empty_or_too_short";
result.nextstep = false
return result;
}
/**
* 测试消息
*/
const testPatterns = [/测试/i, /^test$/i, /^123+$/i];
if (testPatterns.some((re) => re.test(text))) {
result.intent = "spam";
result.reason = "test_message";
result.nextstep = false
return result;
}
/**
* 仅打招呼
*/
const greetingPatterns = [/^hi$/i, /^hello$/i,/^hola/i, /^你好$/i, /^您好$/i];
if (greetingPatterns.some((re) => re.test(text))) {
result.intent = "greeting";
result.reason = "greeting_only";
result.nextstep = false
return result;
}
/**
* 纯表情 / 符号
*/
const emojiOnlyRegex = /^[\p{Emoji}\p{Punctuation}\p{Symbol}\s]+$/u;
if (emojiOnlyRegex.test(text)) {
result.intent = "spam";
result.reason = "emoji_only";
result.nextstep = false
return result;
}
/**
* 其他情况:交给 LLM
*/
result.reason = "-1";
result.nextstep = true
return result;// ========= Layer 2: High-Confidence Intent Detection =========
// 1️⃣ 安全取值 & 归一化
const text = ($json.text || "").trim();
const phone = $json.phone || "";
const t = text.toLowerCase();
// 默认结果(不在 Layer 2 判 lead)
let result = {
is_lead: false,
lead_score: 0,
intent: "unknown",
phone,
reason: "",
text: text
};
// ========= 价格意向(非常明确) =========
const pricePatterns = [
/(多少钱|价格|收费|费用)/,
/(price|pricing|cost|fee)/
];
if (pricePatterns.some(re => re.test(t))) {
return {
is_lead: true,
lead_score: 80,
intent: "price",
phone,
reason: "explicit pricing inquiry"
};
}
// ========= 明确开通 / 使用意向(强) =========
const purchasePatterns = [
/(开通|购买|注册|申请)/,
/(sign\s?up|activate|purchase|start using)/
];
if (purchasePatterns.some(re => re.test(t))) {
return {
is_lead: true,
lead_score: 90,
intent: "consult",
phone,
reason: "explicit activation or purchase intent"
};
}
// ========= 明确能力咨询(结构化) =========
// 必须同时包含:疑问 + 能力 + 业务对象
const capabilityPatterns = [
/(是否|能否|可以).*(支持|对接|使用|实现).*(api|接口|whatsapp|系统|平台)/,
/(do you|can you).*(support|integrate|provide).*(api|whatsapp|service|system)/
];
if (capabilityPatterns.some(re => re.test(t))) {
return {
is_lead: true,
lead_score: 65,
intent: "consult",
phone,
reason: "clear capability consultation"
};
}
// ========= 明确售后问题 =========
const afterSalePatterns = [
/(不能用|用不了|失败|报错|异常|问题)/,
/(error|issue|failed|not working)/
];
if (afterSalePatterns.some(re => re.test(t))) {
return {
is_lead: true,
lead_score: 70,
intent: "after_sale",
phone,
reason: "explicit after-sales issue"
};
}
// 明确业务对象 + 了解意向(中英)
const objectInterestPatterns = [
/了解.*(whatsapp\s?api|api|接口)/i,
/想了解.*(whatsapp\s?api|api|接口)/i,
/(whatsapp\s?api).*(了解|咨询)/i,
/(learn|know|understand).*(whatsapp\s?api|api)/i
];
if (objectInterestPatterns.some(re => re.test(t))) {
return {
is_lead: true,
lead_score: 55,
intent: "consult",
phone,
reason: "explicit interest in WhatsApp API",
text
};
}
// ========= 其余情况 → 交给 LLM =========
return {
...result,
reason: "-1"
};You are an enterprise AI assistant responsible for evaluating
whether a WhatsApp user message represents a valid business lead
AND deciding whether a reply should be sent.
This message has already passed rule-based filtering.
Clear pricing questions, explicit purchase intent, and after-sales issues
have already been handled by earlier layers.
Your responsibility is to handle WEAK or AMBIGUOUS business intent.
You must output JSON only, following the Output Schema.
---
【CORE RESPONSIBILITIES】
1. Decide whether the message should be considered a lead (is_lead)
2. Assign a lead_score (0–100)
3. Classify intent
4. Decide whether a reply is needed
5. If a reply is needed, generate ONE short, polite, business-appropriate reply
---
【WHEN TO GENERATE A REPLY】
Generate a reply ONLY if ALL of the following are true:
- is_lead = true
- lead_score < 60
- intent = "consult"
- The user's message lacks specific details
If these conditions are NOT met:
- reply MUST be an empty string ""
---
【REPLY GUIDELINES】
The reply must:
- Be polite and professional
- Be short (1–2 sentences)
- Ask for clarification or key details
- NOT include pricing, promotions, or sales pressure
- NOT assume the user's intent beyond what is stated
Examples of acceptable replies:
- "Could you please let us know which specific services you are interested in?"
- "May I ask what kind of solution or integration you would like to learn more about?"
---
【INTENT CLASSIFICATION】
Use only:
- consult
- unknown
---
【LEAD SCORE RULES】
- If is_lead = false → lead_score = 0
- If is_lead = true:
- Generic or vague interest → 30–45
- Clear but early consultation → 45–60
---
【OUTPUT FORMAT】
Return JSON ONLY with the following fields:
- is_lead
- lead_score
- intent
- phone (pass through as-is)
- reason
- reply
---
CURRENT MESSAGE:
"{{ $json.text }}"
PHONE:
"{{ $json.phone }}"
Return JSON only.curl --request POST \
--url https://api.hubapi.com/crm/v3/objects/contacts \
--header 'Content-Type: application/json' \
--data '
{
"properties": {} //在此处,你可以存放你想要的字段,如phone,和自定义字段
}
'curl --request PATCH \
--url https://api.hubapi.com/crm/v3/objects/contacts/{contactId} \
--header 'Content-Type: application/json' \
--data '
{
"properties": {
}
}
'