feishu.ts 758 B

12345678910111213141516171819202122232425262728293031323334
  1. export interface FeishuConfig {
  2. readonly webhookUrl: string;
  3. }
  4. export async function sendFeishu(
  5. config: FeishuConfig,
  6. title: string,
  7. content: string,
  8. ): Promise<void> {
  9. const response = await fetch(config.webhookUrl, {
  10. method: "POST",
  11. headers: { "Content-Type": "application/json" },
  12. body: JSON.stringify({
  13. msg_type: "interactive",
  14. card: {
  15. header: {
  16. title: { tag: "plain_text", content: title },
  17. template: "blue",
  18. },
  19. elements: [
  20. {
  21. tag: "markdown",
  22. content,
  23. },
  24. ],
  25. },
  26. }),
  27. });
  28. if (!response.ok) {
  29. const body = await response.text();
  30. throw new Error(`Feishu send failed: ${response.status} ${body}`);
  31. }
  32. }