'use client'; import Link from 'next/link'; import { useState } from 'react'; import { appPath } from '@/lib/base-path'; import type { FeishuDeliveryFilter, FeishuStatus } from '@/lib/feishu'; const deliveryLabels = { pending: '等待发送', sending: '发送中', sent: '已发送', failed: '发送失败' }; const date = (value: string) => new Date(value).toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai', hour12: false }); export function FeishuManagement({ initial }: { initial: FeishuStatus }) { const [status, setStatus] = useState(initial); const [busy, setBusy] = useState(false); const [error, setError] = useState(''); const [message, setMessage] = useState(''); const [pageCursors, setPageCursors] = useState>([null]); async function request(action?: 'test' | 'retry', id?: string, selection?: { filter: FeishuDeliveryFilter; cursors: Array }) { setBusy(true); setError(''); setMessage(''); try { const params = new URLSearchParams({ filter: selection?.filter ?? status.deliveryFilter }); const cursor = (selection?.cursors ?? pageCursors).at(-1); if (cursor) params.set('cursor', cursor); const response = await fetch(appPath('/api/admin/feishu?' + params.toString()), action ? { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ action, id }) } : { cache: 'no-store' }); const data = await response.json(); if (!response.ok) throw new Error(data.error || '操作失败,请重试。'); setStatus(data); setMessage(action === 'test' ? '测试消息已发送,请在飞书群中查看。' : action === 'retry' ? '已加入发送队列,稍后刷新查看结果。' : '状态已刷新。'); if (selection) setPageCursors(selection.cursors); } catch (cause) { setError(cause instanceof Error ? cause.message : '网络异常,请重试。'); } finally { setBusy(false); } } return
返回工作台需有序

飞书集成

管理飞书登录与需求流转群通知。

{error &&
{error}
} {message &&
{message}
} {status.configurationError &&
{status.configurationError}
}

飞书登录 {status.loginConfigured ? '已配置' : '未配置'}

首次飞书登录自动创建普通成员账号,直接进入工作台;已有绑定继续使用原账号的角色和需求。

授权回调地址
{status.callbackUrl}
企业限制
{status.tenantRestricted ? '已限制为指定企业' : '按飞书应用可用范围注册及登录'}
绑定我的飞书账号

群机器人 {status.botConfigured ? '已配置' : '未配置'}

正式需求每次成功保存后发送流转摘要,包含标题、状态、操作人和详情链接。草稿不推送。

签名校验:{status.botSigned ? '已配置' : '未配置'}

配置步骤与通知范围
  1. 在飞书开放平台创建企业自建应用,配置网页应用能力,将上方回调地址加入安全设置的重定向 URL,发布应用并设置成员可用范围。
  2. 在服务器环境变量配置 FEISHU_APP_ID、FEISHU_APP_SECRET,可用 FEISHU_TENANT_KEY 限定企业。
  3. 在目标群添加自定义机器人,配置 FEISHU_BOT_WEBHOOK;开启签名校验时同时配置 FEISHU_BOT_SECRET。关键词校验可填写「需有序」。
  4. 重启服务后刷新状态,发送测试消息。密钥仅在服务器设置,无需填写到浏览器。

群成员均可看到通知摘要,请选择适合接收全部正式需求摘要的群。查看详情仍需系统登录及对应权限。发送失败自动重试最多 5 次,之后可手动重试;网络超时可能导致重复消息,可按需求编号和保存版本核对。

通知记录

{status.deliveries.length ?
{status.deliveries.map(item => )}
需求 / 保存版本发送状态尝试次数创建时间操作
{item.demandId}第 {item.revision} 次保存{deliveryLabels[item.status]}{item.lastError && {item.lastError}}{item.attempts}{date(item.createdAt)}{item.status === 'failed' ? : '—'}
:

{status.deliveryFilter === 'failed' ? '当前页暂无失败通知。可返回上一页或切换为全部通知。' : pageCursors.length > 1 ? '当前页暂无通知,请返回上一页。' : '暂无通知。配置机器人后,新登记及后续流转的正式需求会显示在这里。'}

}
第 {pageCursors.length} 页 · 每页最多 50 条{status.failedCount > 0 ? ` · 共有 ${status.failedCount} 条失败通知` : ''}
; }