feishu-lark について
feishu-lark は、Feishu と Lark のグループチャットにメッセージを送るためのスキルです。Webhook と App Bot API の手順を扱い、テキスト、リッチテキスト、インタラクティブカードを送信できます。
主な機能
- 01Webhook と App Bot API の手順
- 02テキストとリッチメッセージの送信
- 03インタラクティブカードの作成
- 04App Bot API による画像アップロード
- 05チャットやユーザーへのメッセージ送信
活用シーン
- 01グループチャットへの告知投稿
- 02書式付き週次レポートの送信
- 03インタラクティブカードによるチーム通知
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ openclaudia/ openclaudia-skills --skill feishu-larkインストール後、Claude Code で/feishu-larkを入力して読み込まれたか確認します。
詳細
Feishu/Lark メッセージングスキル
Feishu(飞书、ByteDance の中国向け職場プラットフォーム)と Lark(国際版)のメッセージングスペシャリストです。Custom Bot Webhook または App Bot API を使用して、Feishu/Lark のグループチャットにメッセージ、インタラクティブカード、マーケティングコンテンツを送信します。
前提条件
利用可能な認証情報を確認します。
echo "FEISHU_WEBHOOK_URL is ${FEISHU_WEBHOOK_URL:+set}"
echo "FEISHU_WEBHOOK_SECRET is ${FEISHU_WEBHOOK_SECRET:+set}"
echo "FEISHU_APP_ID is ${FEISHU_APP_ID:+set}"
echo "FEISHU_APP_SECRET is ${FEISHU_APP_SECRET:+set}"
2 つの連携モード
| モード | 必要な認証情報 | 機能 |
|---|---|---|
| Custom Bot Webhook(シンプル) | FEISHU_WEBHOOK_URL(+任意で FEISHU_WEBHOOK_SECRET) | 1 つのグループにテキスト、リッチテキスト、インタラクティブカードを送信 |
| App Bot API(フル機能) | FEISHU_APP_ID + FEISHU_APP_SECRET | 任意のチャットへの送信、画像のアップロード、ユーザーへのメンション、カードの管理、イベントの受信 |
認証情報が設定されていない場合は、ユーザーに次の手順を案内してください。
Custom Bot Webhook(最短のセットアップ):
- Feishu/Lark のグループチャットを開きます
- 上部のグループ名をクリックして、グループ設定を開きます
- Bots > Add Bot > Custom Bot に移動します
- ボットに名前を付け、必要に応じて署名検証シークレットを設定します
- Webhook URL をコピーし、
.envに追加します:FEISHU_WEBHOOK_URL=https://open.feishu.cn/open-apis/bot/v2/hook/{webhook_id} FEISHU_WEBHOOK_SECRET=your_secret_here # optional, for signed webhooksApp Bot API(高度な用途向け):
- Feishu Open Platform または Lark Developer Console に移動します
- 新しいアプリを作成し、ボット機能を有効にします
- 必要な権限を追加します:
im:message:send_as_bot、im:chat:readonly- アプリを公開して承認を受けた後、
.envに追加します:FEISHU_APP_ID=cli_xxxxx FEISHU_APP_SECRET=xxxxx
Webhook URL の形式
- Feishu(中国):
https://open.feishu.cn/open-apis/bot/v2/hook/{webhook_id} - Lark(国際版):
https://open.larksuite.com/open-apis/bot/v2/hook/{webhook_id}
API ベース URL
- Feishu(中国):
https://open.feishu.cn/open-apis - Lark(国際版):
https://open.larksuite.com/open-apis
1. Custom Bot Webhook メッセージ
1.1 プレーンテキストメッセージ
curl -s -X POST "${FEISHU_WEBHOOK_URL}" \
-H "Content-Type: application/json" \
-d '{
"msg_type": "text",
"content": {
"text": "Hello from OpenClaudia! This is a test message."
}
}'
グループの全員にメンションする:
curl -s -X POST "${FEISHU_WEBHOOK_URL}" \
-H "Content-Type: application/json" \
-d '{
"msg_type": "text",
"content": {
"text": "<at user_id=\"all\">Everyone</at> Important announcement: new release is live!"
}
}'
1.2 リッチテキストメッセージ(投稿)
リッチテキストでは、太字、リンク、メンション、画像を構造化形式で使用できます。
curl -s -X POST "${FEISHU_WEBHOOK_URL}" \
-H "Content-Type: application/json" \
-d '{
"msg_type": "post",
"content": {
"post": {
"zh_cn": {
"title": "产品更新公告",
"content": [
[
{"tag": "text", "text": "我们很高兴地宣布 "},
{"tag": "a", "text": "v2.0 版本", "href": "https://example.com/changelog"},
{"tag": "text", "text": " 已正式发布!"}
],
[
{"tag": "text", "text": "主要更新:"}
],
[
{"tag": "text", "text": "1. 全新用户界面\n2. 性能提升 50%\n3. 支持暗色模式"}
],
[
{"tag": "at", "user_id": "all", "user_name": "所有人"}
]
]
}
}
}
}'
英語版(Lark 向け):
curl -s -X POST "${FEISHU_WEBHOOK_URL}" \
-H "Content-Type: application/json" \
-d '{
"msg_type": "post",
"content": {
"post": {
"en_us": {
"title": "Product Update Announcement",
"content": [
[
{"tag": "text", "text": "We are excited to announce that "},
{"tag": "a", "text": "v2.0", "href": "https://example.com/changelog"},
{"tag": "text", "text": " is now live!"}
],
[
{"tag": "text", "text": "Key updates:"}
],
[
{"tag": "text", "text": "1. Brand new UI\n2. 50% performance improvement\n3. Dark mode support"}
],
[
{"tag": "at", "user_id": "all", "user_name": "Everyone"}
]
]
}
}
}
}'
リッチテキストのタグリファレンス
| タグ | 用途 | 属性 |
|---|---|---|
text | プレーンテキスト | text、un_escape(ブール値。\n などを解釈) |
a | ハイパーリンク | text、href |
at | メンション | user_id(全員の場合は "all" を使用)、user_name |
img | 画像(App Bot のみ) | image_key(事前に画像をアップロードする必要があります) |
media | 動画/ファイル(App Bot のみ) | file_key、image_key |
1.3 署名付き Webhook リクエスト
FEISHU_WEBHOOK_SECRET が設定されている場合、検証用の署名が Webhook に必要です。
署名付きリクエストを生成する:
# Calculate timestamp and signature
TIMESTAMP=$(date +%s)
STRING_TO_SIGN="${TIMESTAMP}\n${FEISHU_WEBHOOK_SECRET}"
SIGN=$(printf '%b' "${STRING_TO_SIGN}" | openssl dgst -sha256 -hmac "" -binary | openssl base64)
# For proper HMAC-SHA256 signing:
SIGN=$(echo -ne "${TIMESTAMP}\n${FEISHU_WEBHOOK_SECRET}" | openssl dgst -sha256 -hmac "" -binary | base64)
curl -s -X POST "${FEISHU_WEBHOOK_URL}" \
-H "Content-Type: application/json" \
-d "{
\"timestamp\": \"${TIMESTAMP}\",
\"sign\": \"${SIGN}\",
\"msg_type\": \"text\",
\"content\": {
\"text\": \"Signed message from OpenClaudia.\"
}
}"
Feishu 署名アルゴリズムの詳細:
timestamp + "\n" + secretを連結して署名対象文字列を作成します- 空のキーを使用して、その文字列の HMAC-SHA256 を計算します
- 結果を Base64 エンコードします
- リクエストの JSON 本文に
timestampとsignの両方を含めます
2. インタラクティブカードメッセージ
インタラクティブカードは、最も高機能なメッセージ形式です。ヘッダー、コンテンツセクション、画像、アクションボタン、構造化レイアウトに対応しています。
2.1 基本的なカード構造
{
"msg_type": "interactive",
"card": {
"header": {
"title": {
"tag": "plain_text",
"content": "Card Title Here"
},
"template": "blue"
},
"elements": []
}
}
ヘッダーのカラーテンプレート
| テンプレート | 色 | 主な用途 |
|---|---|---|
blue | 青 | 一般情報、更新 |
green | 緑 | 成功、前向きなニュース |
red | 赤 | 緊急、アラート、エラー |
orange | オレンジ | 警告、対応が必要な場合 |
purple | 紫 | イベント、クリエイティブ |
indigo | インディゴ | 技術、エンジニアリング |
turquoise | ターコイズ | 成長、マーケティング |
yellow | 黄 | ハイライト、ヒント |
grey | グレー | 中立、優先度低 |
wathet | 水色 | デフォルト、すっきりした印象 |
2.2 カード要素リファレンス
Markdown コンテンツブロック:
{
"tag": "markdown",
"content": "**Bold text** and *italic text*\n[Link text](https://example.com)\nList:\n- Item 1\n- Item 2"
}
区切り線:
{
"tag": "hr"
}
注記(フッターに表示する小さな灰色のテキスト):
{
"tag": "note",
"elements": [
{"tag": "plain_text", "content": "Sent via OpenClaudia Marketing Toolkit"}
]
}
画像ブロック:
{
"tag": "img",
"img_key": "img_v2_xxx",
"alt": {"tag": "plain_text", "content": "Image description"},
"title": {"tag": "plain_text", "content": "Image Title"}
}
アクションボタン:
{
"tag": "action",
"actions": [
{
"tag": "button",
"text": {"tag": "plain_text", "content": "View Details"},
"type": "primary",
"url": "https://example.com/details"
},
{
"tag": "button",
"text": {"tag": "plain_text", "content": "Dismiss"},
"type": "default"
}
]
}
ボタンの種類: primary(青)、danger(赤)、default(灰色)
複数列レイアウト:
{
"tag": "column_set",
"flex_mode": "bisect",
"columns": [
{
"tag": "column",
"width": "weighted",
"weight": 1,
"elements": [
{"tag": "markdown", "content": "**Left Column**\nContent here"}
]
},
{
"tag": "column",
"width": "weighted",
"weight": 1,
"elements": [
{"tag": "markdown", "content": "**Right Column**\nContent here"}
]
}
]
}
2.3 カードの完全な例:製品発表
curl -s -X POST "${FEISHU_WEBHOOK_URL}" \
-H "Content-Type: application/json" \
-d '{
"msg_type": "interactive",
"card": {
"header": {
"title": {
"tag": "plain_text",
"content": "New Feature Launch: AI-Powered Analytics"
},
"template": "turquoise"
},
"elements": [
{
"tag": "markdown",
"content": "We are thrilled to announce our latest feature!\n\n**AI-Powered Analytics** is now available to all Pro and Enterprise users.\n\nKey highlights:\n- **Smart Insights**: Automatic trend detection and anomaly alerts\n- **Natural Language Queries**: Ask questions in plain English\n- **Predictive Forecasting**: 90-day revenue and growth projections\n- **Custom Dashboards**: Drag-and-drop report builder"
},
{
"tag": "hr"
},
{
"tag": "markdown",
"content": "**Availability:** Rolling out now, fully live by end of week\n**Documentation:** [View the guide](https://example.com/docs/analytics)\n**Feedback:** Reply in this thread or submit via [feedback form](https://example.com/feedback)"
},
{
"tag": "action",
"actions": [
{
"tag": "button",
"text": {"tag": "plain_text", "content": "Try It Now"},
"type": "primary",
"url": "https://example.com/analytics"
},
{
"tag": "button",
"text": {"tag": "plain_text", "content": "Read Docs"},
"type": "default",
"url": "https://example.com/docs/analytics"
}
]
},
{
"tag": "note",
"elements": [
{"tag": "plain_text", "content": "Product Team | Released 2025-01-15"}
]
}
]
}
}'
3. App Bot API(フル機能)
App Bot API を使用するには、FEISHU_APP_ID と FEISHU_APP_SECRET が必要です。任意のチャットへの送信、画像のアップロード、メッセージの管理など、メッセージング機能をすべて利用できます。
3.1 テナントアクセストークンを取得する
App Bot API のすべての呼び出しには tenant_access_token が必要です。トークンの有効期限は 2 時間です。
# For Feishu (China)
FEISHU_API_BASE="https://open.feishu.cn/open-apis"
# For Lark (International)
# FEISHU_API_BASE="https://open.larksuite.com/open-apis"
TENANT_TOKEN=$(curl -s -X POST "${FEISHU_API_BASE}/auth/v3/tenant_access_token/internal" \
-H "Content-Type: application/json" \
-d "{
\"app_id\": \"${FEISHU_APP_ID}\",
\"app_secret\": \"${FEISHU_APP_SECRET}\"
}" | python3 -c "import json,sys; print(json.load(sys.stdin).get('tenant_access_token',''))")
echo "Token: ${TENANT_TOKEN:0:10}..."
3.2 ボットが参加しているチャットの一覧を取得する
curl -s "${FEISHU_API_BASE}/im/v1/chats?page_size=20" \
-H "Authorization: Bearer ${TENANT_TOKEN}" | \
python3 -c "
import json, sys
data = json.load(sys.stdin)
for chat in data.get('data', {}).get('items', []):
print(f\"Chat ID: {chat['chat_id']} | Name: {chat.get('name', 'N/A')} | Type: {chat.get('chat_type', 'N/A')}\")
"
3.3 チャットにメッセージを送信する
CHAT_ID="oc_xxxxx" # Replace with actual chat_id
# Send a text message
curl -s -X POST "${FEISHU_API_BASE}/im/v1/messages?receive_id_type=chat_id" \
-H "Authorization: Bearer ${TENANT_TOKEN}" \
-H "Content-Type: application/json" \
-d "{
\"receive_id\": \"${CHAT_ID}\",
\"msg_type\": \"text\",
\"content\": \"{\\\"text\\\": \\\"Hello from the App Bot!\\\"}\"
}"
API 経由でリッチテキストメッセージを送信する:
curl -s -X POST "${FEISHU_API_BASE}/im/v1/messages?receive_id_type=chat_id" \
-H "Authorization: Bearer ${TENANT_TOKEN}" \
-H "Content-Type: application/json" \
-d "{
\"receive_id\": \"${CHAT_ID}\",
\"msg_type\": \"post\",
\"content\": $(python3 -c "
import json
content = {
'zh_cn': {
'title': 'App Bot 消息',
'content': [
[
{'tag': 'text', 'text': '这是一条通过 App Bot API 发送的 '},
{'tag': 'a', 'text': '富文本消息', 'href': 'https://example.com'},
{'tag': 'text', 'text': '。'}
]
]
}
}
print(json.dumps(json.dumps(content)))
")
}"
API 経由でインタラクティブカードを送信する:
curl -s -X POST "${FEISHU_API_BASE}/im/v1/messages?receive_id_type=chat_id" \
-H "Authorization: Bearer ${TENANT_TOKEN}" \
-H "Content-Type: application/json" \
-d "{
\"receive_id\": \"${CHAT_ID}\",
\"msg_type\": \"interactive\",
\"content\": $(python3 -c "
import json
card = {
'header': {
'title': {'tag': 'plain_text', 'content': 'Marketing Update'},
'template': 'turquoise'
},
'elements': [
{'tag': 'markdown', 'content': '**Campaign Performance This Week**\n\n- Impressions: **120,450** (+12%)\n- Clicks: **8,320** (+8%)\n- Conversions: **342** (+15%)\n- Cost per Conversion: **\$14.20** (-5%)'},
{'tag': 'hr'},
{'tag': 'action', 'actions': [
{'tag': 'button', 'text': {'tag': 'plain_text', 'content': 'View Full Report'}, 'type': 'primary', 'url': 'https://example.com/report'}
]},
{'tag': 'note', 'elements': [{'tag': 'plain_text', 'content': 'Auto-generated by OpenClaudia Marketing Toolkit'}]}
]
}
print(json.dumps(json.dumps(card)))
")
}"
3.4 画像をアップロードする
画像をアップロードして、カードやリッチテキストメッセージで使用する image_key を取得します。
IMAGE_KEY=$(curl -s -X POST "${FEISHU_API_BASE}/im/v1/images" \
-H "Authorization: Bearer ${TENANT_TOKEN}" \
-F "image_type=message" \
-F "image=@/path/to/image.png" | python3 -c "import json,sys; print(json.load(sys.stdin).get('data',{}).get('image_key',''))")
echo "Image key: ${IMAGE_KEY}"
3.5 特定のユーザーに送信する(メールアドレスまたは user_id で指定)
# By email (receive_id_type=email)
curl -s -X POST "${FEISHU_API_BASE}/im/v1/messages?receive_id_type=email" \
-H "Authorization: Bearer ${TENANT_TOKEN}" \
-H "Content-Type: application/json" \
-d "{
\"receive_id\": \"[email protected]\",
\"msg_type\": \"text\",
\"content\": \"{\\\"text\\\": \\\"Direct message from the marketing bot.\\\"}\"
}"
4. メッセージテンプレート
4.1 製品発表
send_product_announcement() {
local TITLE="$1"
local VERSION="$2"
local FEATURES="$3"
local DOCS_URL="$4"
local CTA_URL="$5"
curl -s -X POST "${FEISHU_WEBHOOK_URL}" \
-H "Content-Type: application/json" \
-d "$(python3 -c "
import json
card = {
'msg_type': 'interactive',
'card': {
'header': {
'title': {'tag': 'plain_text', 'content': '${TITLE}'},
'template': 'green'
},
'elements': [
{'tag': 'markdown', 'content': '**Version ${VERSION}** is now available!\n\n${FEATURES}'},
{'tag': 'hr'},
{'tag': 'action', 'actions': [
{'tag': 'button', 'text': {'tag': 'plain_text', 'content': 'Get Started'}, 'type': 'primary', 'url': '${CTA_URL}'},
{'tag': 'button', 'text': {'tag': 'plain_text', 'content': 'Release Notes'}, 'type': 'default', 'url': '${DOCS_URL}'}
]},
{'tag': 'note', 'elements': [{'tag': 'plain_text', 'content': 'Product Team | $(date +%Y-%m-%d)'}]}
]
}
}
print(json.dumps(card))
")"
}
4.2 チームの近況報告/週次レポート
curl -s -X POST "${FEISHU_WEBHOOK_URL}" \
-H "Content-Type: application/json" \
-d '{
"msg_type": "interactive",
"card": {
"header": {
"title": {"tag": "plain_text", "content": "Weekly Marketing Report - W03 2025"},
"template": "blue"
},
"elements": [
{
"tag": "column_set",
"flex_mode": "bisect",
"columns": [
{
"tag": "column",
"width": "weighted",
"weight": 1,
"elements": [
{"tag": "markdown", "content": "**Traffic**\n\nSessions: **45,230**\nUnique Visitors: **32,100**\nBounce Rate: **42%**"}
]
},
{
"tag": "column",
"width": "weighted",
"weight": 1,
"elements": [
{"tag": "markdown", "content": "**Conversions**\n\nSignups: **580**\nTrials: **120**\nPaid: **34**"}
]
}
]
},
{"tag": "hr"},
{
"tag": "markdown",
"content": "**Top Performing Content:**\n1. \"10 Tips for Better SEO\" - 8,200 views\n2. \"Product Comparison Guide\" - 5,100 views\n3. \"Customer Success Story: Acme Corp\" - 3,800 views\n\n**Action Items:**\n- [ ] Publish Q1 campaign landing page\n- [ ] Review ad spend allocation\n- [ ] Schedule social media posts for next week"
},
{
"tag": "action",
"actions": [
{
"tag": "button",
"text": {"tag": "plain_text", "content": "Full Dashboard"},
"type": "primary",
"url": "https://example.com/dashboard"
}
]
},
{
"tag": "note",
"elements": [
{"tag": "plain_text", "content": "Marketing Team | Auto-generated weekly report"}
]
}
]
}
}'
4.3 イベント通知
curl -s -X POST "${FEISHU_WEBHOOK_URL}" \
-H "Content-Type: application/json" \
-d '{
"msg_type": "interactive",
"card": {
"header": {
"title": {"tag": "plain_text", "content": "Upcoming Webinar: AI in Marketing"},
"template": "purple"
},
"elements": [
{
"tag": "markdown",
"content": "Join us for an exclusive webinar on leveraging AI for marketing success.\n\n**Date:** Thursday, January 30, 2025\n**Time:** 2:00 PM - 3:30 PM (PST)\n**Speaker:** Jane Smith, VP of Marketing\n**Format:** Live presentation + Q&A\n\n**What you will learn:**\n- How to use AI for content personalization\n- Automating campaign optimization\n- Measuring AI-driven marketing ROI"
},
{"tag": "hr"},
{
"tag": "action",
"actions": [
{
"tag": "button",
"text": {"tag": "plain_text", "content": "Register Now"},
"type": "primary",
"url": "https://example.com/webinar/register"
},
{
"tag": "button",
"text": {"tag": "plain_text", "content": "Add to Calendar"},
"type": "default",
"url": "https://example.com/webinar/calendar"
}
]
},
{
"tag": "note",
"elements": [
{"tag": "plain_text", "content": "Limited to 200 seats | Free for all team members"}
]
}
]
}
}'
4.4 マーケティングキャンペーンのアラート
curl -s -X POST "${FEISHU_WEBHOOK_URL}" \
-H "Content-Type: application/json" \
-d '{
"msg_type": "interactive",
"card": {
"header": {
"title": {"tag": "plain_text", "content": "Campaign Alert: Budget Threshold Reached"},
"template": "orange"
},
"elements": [
{
"tag": "markdown",
"content": "**Google Ads - Q1 Brand Campaign** has reached **80%** of its monthly budget.\n\n| Metric | Value |\n|--------|-------|\n| Budget | $10,000 |\n| Spent | $8,042 |\n| Remaining | $1,958 |\n| Days Left | 8 |\n| Projected Overspend | $2,100 |\n\n**Recommendation:** Reduce daily bid cap by 15% or pause low-performing ad groups."
},
{
"tag": "action",
"actions": [
{
"tag": "button",
"text": {"tag": "plain_text", "content": "Adjust Budget"},
"type": "danger",
"url": "https://ads.google.com/campaigns"
},
{
"tag": "button",
"text": {"tag": "plain_text", "content": "View Campaign"},
"type": "default",
"url": "https://example.com/campaigns/q1-brand"
}
]
}
]
}
}'
5. ヘルパー:プログラムでカードを作成して送信する
複雑なカードや動的なカードを作成する場合は、Python を使用して JSON ペイロードを構築します。
python3 -c "
import json, subprocess, os
webhook_url = os.environ.get('FEISHU_WEBHOOK_URL', '')
if not webhook_url:
print('Error: FEISHU_WEBHOOK_URL not set')
exit(1)
# Build card dynamically
card = {
'msg_type': 'interactive',
'card': {
'header': {
'title': {'tag': 'plain_text', 'content': 'Dynamic Card Title'},
'template': 'blue'
},
'elements': []
}
}
# Add content blocks
card['card']['elements'].append({
'tag': 'markdown',
'content': 'This card was built programmatically.\n\n**Key metrics:**\n- Users: 10,000\n- Revenue: \$50,000'
})
# Add a divider
card['card']['elements'].append({'tag': 'hr'})
# Add buttons
card['card']['elements'].append({
'tag': 'action',
'actions': [
{
'tag': 'button',
'text': {'tag': 'plain_text', 'content': 'Learn More'},
'type': 'primary',
'url': 'https://example.com'
}
]
})
# Add footer
card['card']['elements'].append({
'tag': 'note',
'elements': [{'tag': 'plain_text', 'content': 'Sent via OpenClaudia'}]
})
payload = json.dumps(card)
result = subprocess.run(
['curl', '-s', '-X', 'POST', webhook_url,
'-H', 'Content-Type: application/json',
'-d', payload],
capture_output=True, text=True
)
print(result.stdout)
"
6. バイリンガル対応(中国語+英語)
中国語と英語の両方のコンテンツを含むメッセージを送信する場合は、複数のロケールに対応したリッチテキストの post 形式を使用します。Feishu は、ユーザーの言語設定に一致するロケールを表示します。
curl -s -X POST "${FEISHU_WEBHOOK_URL}" \
-H "Content-Type: application/json" \
-d '{
"msg_type": "post",
"content": {
"post": {
"zh_cn": {
"title": "重要通知:系统维护",
"content": [
[
{"tag": "text", "text": "我们将于 "},
{"tag": "text", "text": "1月25日 22:00-02:00 (北京时间)", "un_escape": true},
{"tag": "text", "text": " 进行系统维护。"}
],
[
{"tag": "text", "text": "维护期间服务将暂时不可用。如有问题请联系 "},
{"tag": "a", "text": "技术支持", "href": "https://example.com/support"},
{"tag": "text", "text": "。"}
]
]
},
"en_us": {
"title": "Important: Scheduled Maintenance",
"content": [
[
{"tag": "text", "text": "We will perform scheduled maintenance on "},
{"tag": "text", "text": "January 25, 10:00 PM - 2:00 AM (CST)"},
{"tag": "text", "text": "."}
],
[
{"tag": "text", "text": "Services will be temporarily unavailable. For questions, contact "},
{"tag": "a", "text": "Support", "href": "https://example.com/support"},
{"tag": "text", "text": "."}
]
]
}
}
}
}'
7. エラー処理
Webhook の応答コード
| Code | StatusMessage | Meaning |
|---|---|---|
| 0 | "success" | メッセージが正常に送信されました |
| 9499 | "Bad Request" | JSON の形式が正しくないか、必須フィールドが不足しています |
| 19001 | "param invalid" | msg_type または content の形式が無効です |
| 19002 | "sign match fail" | 署名の検証に失敗しました(タイムスタンプとシークレットを確認してください) |
| 19021 | "request too fast" | レート制限:Webhook ごとに 1 分あたり最大 100 件のメッセージ |
| 19024 | "bot not in chat" | ボットがグループから削除されています |
よくあるトラブルシューティング
メッセージが配信されない:
- Webhook URL が正しく、ボットがまだグループに参加していることを確認してください
msg_typeがコンテンツの構造と一致していることを確認してください- 署名付き Webhook の場合、タイムスタンプが現在時刻から 1 時間以内であることを確認してください
カードが表示されない:
- JSON 構造を検証してください。header と elements の両方が必要です
- ボタンの URL は
http://またはhttps://で始まる必要があります - カード内の Markdown でサポートされるのは、太字、斜体、リンク、リスト、表の一部に限られます
API トークンのエラー:
- テナントアクセストークンの有効期限は 2 時間です。送信前に再取得してください
- 開発者コンソールでアプリが公開され、承認済みであることを確認してください
im:message:send_as_bot権限が付与されていることを確認してください
レート制限
| Integration | Limit |
|---|---|
| カスタムボット Webhook | Webhook ごとに 1 分あたり 100 件のメッセージ |
| App Bot API(メッセージ) | アプリごとに 1 秒あたり 50 件のメッセージ |
| App Bot API(トークンの更新) | 1 時間あたり 500 リクエスト |
8. ワークフロー:マーケティングコンテンツを Feishu/Lark に投稿する
ユーザーから Feishu または Lark へのマーケティングコンテンツの送信を依頼された場合は、次のワークフローに従います。
ステップ 1:認証情報を確認する
FEISHU_WEBHOOK_URL または FEISHU_APP_ID + FEISHU_APP_SECRET が設定されていることを確認します。設定されていない場合は、セットアップ方法を案内します。
ステップ 2:メッセージの種類を決定する
| User Intent | Recommended Format |
|---|---|
| 簡単なテキストの更新 | プレーンテキスト(msg_type: text) |
| 書式付きのお知らせ | リッチテキスト(msg_type: post) |
| 指標を含むマーケティングレポート | 列を含むインタラクティブカード |
| 製品の発売 | ボタン付きインタラクティブカード |
| イベント通知 | CTA ボタン付きインタラクティブカード |
| アラートまたは警告 | red/orange のヘッダー付きインタラクティブカード |
ステップ 3:メッセージを作成する
- セクション 4 の適切なテンプレートを使用します
- ユーザーの要件に合わせて内容を調整します
- バイリンガルグループには、
zh_cnとen_usの両方の内容を用意します
ステップ 4:プレビューして確認する
送信前に、JSON ペイロード全体をユーザーに表示します。メッセージがどのように表示されるかを説明します。
ユーザーの明示的な確認なしに、自動送信してはいけません。
ステップ 5:送信する
curl コマンドを実行し、応答を報告します。
ステップ 6:検証する
応答コードを確認します。code: 0 の場合、メッセージは配信されています。エラーが発生した場合は、上記のエラーテーブルを参考にトラブルシューティングします。
9. 応用編:メッセージカード JSON スキーマのクイックリファレンス
{
"msg_type": "interactive",
"card": {
"header": { // Required
"title": {
"tag": "plain_text",
"content": "string"
},
"template": "blue|green|red|..." // Header color
},
"elements": [ // Required, array of blocks
{"tag": "markdown", "content": "..."}, // Rich content
{"tag": "hr"}, // Divider line
{"tag": "img", "img_key": "...", "alt": {...}}, // Image
{ // Multi-column layout
"tag": "column_set",
"flex_mode": "bisect|trisect|...",
"columns": [
{"tag": "column", "width": "weighted", "weight": 1, "elements": [...]}
]
},
{ // Action buttons
"tag": "action",
"actions": [
{"tag": "button", "text": {...}, "type": "primary|danger|default", "url": "..."}
]
},
{ // Footer note
"tag": "note",
"elements": [{"tag": "plain_text", "content": "..."}]
}
]
}
}
ヒント
- まずは Webhook から始めましょう。 カスタム Bot Webhook はコード不要のインフラで、1 分もかからずに設定できます。
- シンプルなテキスト以外には、インタラクティブカードを使用しましょう。 可読性が高く、操作もしやすくなります。
- マーケティング用のカードには、アクションボタンを必ず含めましょう。 ランディングページ、ダッシュボード、登録フォームに誘導できます。
- チームで Feishu と Lark の両方を利用している場合や、中国国内外にメンバーがいる場合は、バイリンガルサポートを活用しましょう。
- レート制限を守りましょう。 一括メッセージ(複数のグループへの送信など)では、リクエストの間に 1 秒の遅延を入れます。
- 大規模なチームチャンネルに送信する前に、まず非公開グループでテストしましょう。
- カードの内容は簡潔にまとめましょう。 カードの最大コンテンツサイズは約 30KB です。非常に長いレポートは、外部ページにリンクしてください。
- ビジュアルなカードデザインには、Feishu Message Card Builder を使用します:https://open.feishu.cn/tool/cardbuilder(Feishu)または https://open.larksuite.com/tool/cardbuilder(Lark)。