Clawdbot 定时任务

使用 Clawdbot AI 助手定时任务安排自动化任务。了解如何配置定期消息、报告和自动化工作流。

Clawdbot 定时任务概述

Clawdbot 支持使用 cron 风格语法的计划任务。定时任务支持自动消息、定期报告、健康检查和定期工作流。

配置

基本定时任务

{
  "cron": {
    "jobs": [
      {
        "id": "daily-summary",
        "schedule": "0 9 * * *",
        "action": "send_message",
        "target": {
          "channel": "whatsapp",
          "peer": "+15551234567"
        },
        "message": "早上好!这是您的每日摘要。"
      }
    ]
  }
}

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": "工作日开始提醒!"
}

代理任务

运行代理任务:

{
  "id": "daily-report",
  "schedule": "0 18 * * *",
  "action": "run_agent",
  "agentId": "reporter",
  "prompt": "生成今天的活动报告"
}

Webhook 任务

触发 webhooks:

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

会话处理

定时任务会话键

定时任务使用专用会话:

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": "每日站会时间到!你昨天做了什么?"
}

周报

{
  "id": "weekly-report",
  "schedule": "0 17 * * 5",
  "action": "run_agent",
  "agentId": "main",
  "prompt": "生成周报摘要并发送到团队频道"
}

下一步