Clawdbot 定時任務

使用 Clawdbot AI 助手定時任務排程自動化任務。了解如何配置週期性訊息、報告和自動化工作流程。

Clawdbot 定時任務概述

Clawdbot 支援使用 cron 風格語法的排程任務。定時任務可實現自動化訊息、週期性報告、健康檢查和週期性工作流程。

配置

基本定時任務

{
  "cron": {
    "jobs": [
      {
        "id": "daily-summary",
        "schedule": "0 9 * * *",
        "action": "send_message",
        "target": {
          "channel": "whatsapp",
          "peer": "+15551234567"
        },
        "message": "Good morning! Here's your daily summary."
      }
    ]
  }
}

Cron 語法

欄位描述
分鐘0-59小時中的分鐘
小時0-23一天中的小時
日期1-31月份中的日期
月份1-12一年中的月份
星期0-6星期幾(0=星期日)

常用排程

排程Cron 表達式
每小時0 * * * *
每天上午9點0 9 * * *
每週一0 9 * * 1
每月1號0 9 1 * *

任務類型

訊息任務

發送排程訊息:

{
  "id": "reminder",
  "schedule": "0 8 * * 1-5",
  "action": "send_message",
  "target": {
    "channel": "telegram",
    "peer": "123456789"
  },
  "message": "Start of workday reminder!"
}

代理任務

執行代理任務:

{
  "id": "daily-report",
  "schedule": "0 18 * * *",
  "action": "run_agent",
  "agentId": "reporter",
  "prompt": "Generate today's activity report"
}

Webhook 任務

觸發 webhooks:

{
  "id": "health-check",
  "schedule": "*/5 * * * *",
  "action": "webhook",
  "url": "https://api.example.com/health",
  "method": "POST"
}

會話處理

Cron 會話金鑰

定時任務使用專用會話:

cron:<job.id>

會話隔離

  • 每個任務有自己的會話
  • 歷史記錄在執行間持續存在
  • 上下文會延續

任務管理

CLI 命令

# 列出定時任務
clawdbot cron list

# 新增任務
clawdbot cron add --id daily --schedule "0 9 * * *" --action send_message

# 移除任務
clawdbot cron remove daily

# 立即執行任務
clawdbot cron run daily

任務狀態

狀態描述
active任務已排程
paused任務已暫停
running正在執行
failed上次執行失敗

錯誤處理

重試策略

{
  "cron": {
    "retry": {
      "maxAttempts": 3,
      "backoff": "exponential",
      "initialDelay": 1000
    }
  }
}

失敗通知

{
  "cron": {
    "notifications": {
      "onFailure": {
        "channel": "telegram",
        "peer": "admin_id"
      }
    }
  }
}

時區

配置

{
  "cron": {
    "timezone": "Asia/Shanghai"
  }
}

預設行為

  • 如未指定則使用系統時區
  • 所有排程按配置的時區解釋

範例

每日站會提醒

{
  "id": "standup",
  "schedule": "0 9 * * 1-5",
  "action": "send_message",
  "target": {
    "channel": "discord",
    "peer": { "kind": "group", "id": "standup-channel" }
  },
  "message": "Time for daily standup! What did you work on yesterday?"
}

每週報告

{
  "id": "weekly-report",
  "schedule": "0 17 * * 5",
  "action": "run_agent",
  "agentId": "main",
  "prompt": "Generate weekly summary report and send to team channel"
}

下一步