WhatsApp 关键词规则
Bird 自带关键词目录,因此收件人向您任一可接收入站消息的号码回复 STOP 时,即会被退订,您无需任何设置。START 可撤销退订。您自己的规则会在其覆盖的范围内替代 Bird 的默认规则。
本页介绍 Bird 能识别哪些词、入站消息如何匹配,以及如何修改回复措辞或添加关键词。在控制台中,对应的操作位于 Keywords 页面。

Bird 默认识别的关键词
以下九个词会记录退订:
stop、stop all、stopall、unsubscribe、cancel、end、quit、revoke、optout
以下两个词会撤销退订:start 和 unstop。
匹配针对整条消息,而不是其中的子串。由于 cancel 和 end 都是关键词,这一区别很重要:"cancel my 3pm delivery" 是一条普通消息,不会撤回同意。匹配时会忽略大小写、重音符号、连续空格和末尾标点,因此 Stop! 和 STOP 都能匹配。词前或词中的标点不会被忽略,因此 #stop 不会匹配。
不匹配关键词的情况
群组消息中的关键词会被跳过,因此参与者无法通过在群组中回复来退订。请在您自己的发送逻辑中遵从群组成员明确表示的退订意愿。
偏好何时记录
分类与 whatsapp.received 事件同时运行,而不是先于该事件。因此,监听该事件的集成可能会在 STOP 所记录的偏好生成之前就看到这条消息到达。如果您的处理程序在收到入站消息后会发送内容,请重新读取该收件人的记录,不要依赖事件顺序。
查看适用的规则
GET /v1/whatsapp/keyword-rules 描述对您号码的回复如何处理。不加筛选时,它为每个范围返回一行:有您的规则时返回您的规则,没有时返回 Bird 的规则。您的规则如果没有 waba,会替换 Bird 针对同一操作和国家的规则。可以用 country、waba、operation 或 scope 缩小结果范围:
scope=system返回 Bird 的目录,包括被您的规则覆盖的默认规则。scope=workspace返回您自己的规则。
const rules = await bird.whatsapp.keywordRules.list({ operation: "opt_out" });
for (const rule of rules.data ?? []) {
console.log(rule.scope, rule.effective_keywords);
}rules = client.whatsapp.keyword_rules.list(operation="opt_out")
for rule in rules.data or []:
print(rule.scope, rule.effective_keywords)rules, err := client.Whatsapp.KeywordRules.List(context.Background(), bird.WhatsappKeywordRulesListParams{
Operation: "opt_out", // omit for both operations, Bird's rules and your own
})
if err != nil {
log.Fatal(err)
}
for _, rule := range rules.Data {
fmt.Println(rule.Scope, rule.EffectiveKeywords)
}$rules = $bird->whatsapp->keywordRules->list(['operation' => 'opt_out']);
foreach ($rules->getData() ?? [] as $rule) {
echo $rule->getScope(), ' ', implode(',', $rule->getEffectiveKeywords() ?? []), PHP_EOL;
}bird whatsapp keyword-rules listcurl "https://us1.platform.bird.com/v1/whatsapp/keyword-rules?operation=opt_out" \
-H "Authorization: Bearer $BIRD_API_KEY"规则按从最具体到最宽泛的顺序返回,这也是入站消息与规则匹配的顺序。每条规则都带有 effective_keywords:即 Bird 针对该操作和国家的关键词集合,减去您移除的,再加上您添加的。
对于您自己的、没有 country 的规则,effective_keywords 显示 Bird 的全球集合,因为该规则没有国家,而发送者的国家要等消息到达后才能知道。该规则实际会按 Bird 针对发送者所在国家的集合进行匹配,这个集合可能更大。在您的规则上设置 country,即可准确查看这些发送者会匹配哪些关键词。
country 是发送者所在的国家,根据发送者自己的电话号码推断,而不是根据其发送消息的目标号码。这是 WhatsApp 发送的国家信号。通过企业范围用户 ID 识别的发送者不带国家信息,因此来自此类发送者的消息会跳过按国家限定的规则,改为匹配全球规则。
更改回复
Bird 的默认回复内容正确,但较为通用。如需以您自己的名义回复,请创建一条规则:
const rule = await bird.whatsapp.keywordRules.create({
operation: "opt_out",
country: "US", // the SENDER's country, from their own number
reply: "You're off the list. ACME Courier won't message you again.",
});
// effective_keywords is Bird's set plus any of your own.
console.log(rule.id, rule.effective_keywords);rule = client.whatsapp.keyword_rules.create(
operation="opt_out",
country="US", # the SENDER's country, from their own number
reply="You're off the list. ACME Courier won't message you again.",
)
# effective_keywords is Bird's set plus any of your own.
print(rule.id, rule.effective_keywords)rule, err := client.Whatsapp.KeywordRules.Create(context.Background(), bird.WhatsappKeywordRulesCreateParams{
Operation: "opt_out",
Country: bird.String("US"), // the SENDER's country, from their own number
Reply: bird.String("You're off the list. ACME Courier won't message you again."),
})
if err != nil {
log.Fatal(err)
}
// EffectiveKeywords is Bird's set plus any of your own.
fmt.Println(rule.Id, rule.EffectiveKeywords)$rule = $bird->whatsapp->keywordRules->create(
(new WhatsAppKeywordRuleCreate())
->setOperation('opt_out')
->setCountry('US')
->setReply("You're off the list. ACME Courier won't message you again."),
);
// getEffectiveKeywords() is Bird's set plus any of your own.
echo $rule->getId(), ' ', implode(',', $rule->getEffectiveKeywords() ?? []);bird whatsapp keyword-rules create \
--country US \
--keywords 'no more texts' \
--keywords 'remove me' \
--operation opt_out \
--reply "You're off the list. ACME Courier won't message you again." \
--waba 102290129340398curl -X POST https://us1.platform.bird.com/v1/whatsapp/keyword-rules \
-H "Authorization: Bearer $BIRD_API_KEY" \
-H "Content-Type: application/json" \
-d '{"operation":"opt_out","country":"US","reply":"You'"'"'re off the list. ACME Courier won'"'"'t message you again."}'您的规则会替换 Bird 在该范围内的回复,并保留 Bird 的关键词。您的 keywords 是追加项而非替换项,因此 Bird 日后新增的关键词无需您做任何更改即可开始匹配。
如需在不发送任何回复的情况下仍记录退订,请在创建规则时省略 reply。如需让现有规则静默,请在下方更新操作的 JSON 请求体中将 reply 设为 null;CLI 标志无法传递 null。

添加您自己的关键词
// Omitting keywords leaves the set alone; an empty array clears your additions
// back to Bird's. reply: null switches the auto-reply off and still records
// the opt-out.
const rule = await bird.whatsapp.keywordRules.update("wkr_01m2kj8x4te9p0rr7e5w2n1abc", {
keywords: ["no more texts", "remove me"],
});
console.log(rule.effective_keywords);# Omitting keywords leaves the set alone; an empty list clears your additions
# back to Bird's.
rule = client.whatsapp.keyword_rules.update(
"wkr_01m2kj8x4te9p0rr7e5w2n1abc", keywords=["no more texts", "remove me"]
)
print(rule.effective_keywords)// Omitting keywords leaves the set alone; an empty slice clears your
// additions back to Bird's.
rule, err := client.Whatsapp.KeywordRules.Update(context.Background(),
"wkr_01m2kj8x4te9p0rr7e5w2n1abc", bird.WhatsappKeywordRulesUpdateParams{
Keywords: []string{"no more texts", "remove me"},
})
if err != nil {
log.Fatal(err)
}
fmt.Println(rule.EffectiveKeywords)// Omitting keywords leaves the set alone; an empty array clears your additions
// back to Bird's.
$rule = $bird->whatsapp->keywordRules->update(
'wkr_01m2kj8x4te9p0rr7e5w2n1abc',
(new WhatsAppKeywordRuleUpdate())->setKeywords(['no more texts', 'remove me']),
);
echo implode(',', $rule->getEffectiveKeywords() ?? []);bird whatsapp keyword-rules update <id> \
--keywords 'no more texts' \
--reply "You're off the list. ACME Courier won't message you again."curl -X PATCH https://us1.platform.bird.com/v1/whatsapp/keyword-rules/wkr_01m2kj8x4te9p0rr7e5w2n1abc \
-H "Authorization: Bearer $BIRD_API_KEY" \
-H "Content-Type: application/json" \
-d '{"keywords":["no more texts"]}'省略 keywords 会保留您的追加项不变。发送空数组会清除这些追加项,恢复为 Bird 的关键词集。
移除 Bird 的关键词
有些对话需要把 cancel 或 stop 当作普通词语使用,例如在机器人流程中 cancel 表示取消当前步骤。请在您的规则的 excluded_keywords 中列出这些词:
curl -X POST https://us1.platform.bird.com/v1/whatsapp/keyword-rules \
-H "Authorization: Bearer $BIRD_API_KEY" \
-H "Content-Type: application/json" \
-d '{"operation":"opt_out","waba":"102290129340398","excluded_keywords":["cancel","end"]}'此后,对于该规则覆盖的用户,内容恰好为其中某个词的消息不会让任何人退订,也不会收到回复。该消息仍会照常送达您,Bird 自身的规则也不会转而处理它。排除 Bird 的全部关键词即可将其关闭。Bird 日后新增的关键词仍会匹配,除非您的规则已将其排除。移除关键词后,您需要自行处理这些关键词所表达的退订。Meta 营销模板上自带的退订按钮仍然有效。
在更新操作中,excluded_keywords 会替换已移除的关键词集;空数组表示不移除任何关键词;省略该字段则保留原关键词集不变。同一关键词不能既被添加又被排除。每个被排除的关键词都必须是 Bird 针对该规则操作的关键词之一。对于带有 country 的规则,它必须是 Bird 针对该国家的关键词之一;如果 Bird 没有针对该国家的关键词,则必须是 Bird 的全球关键词之一。Bird 会以 422 拒绝其他任何词,否则一旦 Bird 日后新增该词,它就会被移除。
规则范围与重复
规则可以通过 waba 限定到一个 WhatsApp Business Account,通过 country 限定到一个发送方国家,也可以同时限定两者,或都不限定。每种操作、国家和账户的组合只能有一条规则。对同一组合再次写入会返回重复错误。
Bird 会拒绝将 stop 绑定到 opt_in 的规则,无论该词来自 Bird 的目录还是您的其他规则,因此退订词不能被设置为授予同意。
删除规则
删除你的规则后,该范围会交由匹配顺序中的下一条规则处理,而这条规则不一定是你的。顺序如下:
- 你针对某个账户和国家的规则。
- 你针对该账户的规则。
- 你针对该国家的规则。
- Bird 针对发送者所在国家的规则。
- 你的全球规则。
- Bird 的全球规则。
因此,删除你针对某个国家的规则后,该范围会先交由 Bird 针对该国家的规则处理,而不是你自己的全球规则:
// The next rule in the ladder answers the scope, which is another rule of yours if you hold a less specific one.
await bird.whatsapp.keywordRules.delete("wkr_01m2kj8x4te9p0rr7e5w2n1abc");# The next rule in the ladder answers the scope, which is another rule of yours if you hold a less specific one.
client.whatsapp.keyword_rules.delete("wkr_01m2kj8x4te9p0rr7e5w2n1abc")if err := client.Whatsapp.KeywordRules.Delete(context.Background(),
"wkr_01m2kj8x4te9p0rr7e5w2n1abc"); err != nil {
log.Fatal(err)
}// The next rule in the ladder answers the scope, which is another rule of yours if you hold a less specific one.
$bird->whatsapp->keywordRules->delete('wkr_01m2kj8x4te9p0rr7e5w2n1abc');bird whatsapp keyword-rules delete <id> --yescurl -X DELETE https://us1.platform.bird.com/v1/whatsapp/keyword-rules/wkr_01m2kj8x4te9p0rr7e5w2n1abc \
-H "Authorization: Bearer $BIRD_API_KEY"删除规则后,回复文案和关键词集合会恢复为该顺序中下一条规则的设置。如果下一条规则是你自己的、且排除了 stop,那么 STOP 在该范围内同样不起作用。