OA0 = Omni AI 0
OA0 是一个探索 AI 的论坛
现在注册
已注册用户请  登录
OA0  ›  技能包  ›  autoresponder:监控 iMessage/短信并根据情境自动回复

autoresponder:监控 iMessage/短信并根据情境自动回复

 
  code ·  2026-02-14 20:41:44 · 3 次点击  · 0 条评论  

名称: imsg-autoresponder
描述: 监控 iMessage/SMS 对话,并根据可配置的规则、AI 提示和速率限制条件自动回复。当你需要基于对话上下文,用 AI 生成的回复自动回复特定联系人时使用。当用户要求管理自动回复器设置、联系人、提示词或查看状态/历史记录时也可使用。


iMessage 自动回复器

使用符合你语气和对话上下文的 AI 生成回复,自动回复来自特定联系人的 iMessage/SMS。

⚠️ 使用前检查清单

使用此技能前,请确保已满足:

  • [ ] 已登录 iMessage 的 macOS 系统及 Messages.app
  • [ ] 已安装 imsg CLIbrew install steipete/tap/imsg
  • [ ] 已在 Clawdbot 配置中配置 OpenAI API 密钥
  • [ ] 已授予终端/iTerm 完全磁盘访问权限
  • [ ] 已授予 Messages 自动化权限(首次使用时 macOS 会提示)

功能特性

  • 🤖 AI 驱动回复:使用 OpenAI GPT-4
  • 📱 基于联系人的提示词:为每个联系人配置不同的 AI 个性
  • ⏱️ 速率限制:可配置自动回复之间的延迟时间
  • 💬 上下文感知:AI 能看到最近的对话历史
  • 📊 Telegram 管理:支持斜杠命令和自然语言
  • 🔄 后台监控:持续轮询新消息
  • 🔧 自动清理:重启时清除陈旧锁(防止联系人卡住)
  • 🧪 测试模式:生成真实的 AI 回复但不发送
  • 时间窗口:仅在特定时段内回复(例如,上午 9 点至晚上 10 点)
  • 🔑 关键词触发:仅当消息包含特定关键词时才回复(例如,“urgent”、“help”)
  • 📊 统计跟踪:跟踪总回复数、每日计数和每个联系人的平均值
  • 🚦 每日上限:限制每个联系人每天的最大回复数(安全功能)

快速开始

1. 添加联系人到监控列表

cd ~/clawd/imsg-autoresponder/scripts
node manage.js add "+15551234567" "回复一个中指表情" "最好的朋友"
node manage.js add "+15559876543" "你是我的得力助手。热情而简短地回复,就像我自己在回复一样。保持在 160 个字符以内。" "妈妈"

2. 启动监控器

node watcher.js

监控器将在前台运行,日志输出到 ~/clawd/logs/imsg-autoresponder.log

3. 在后台运行(推荐)

# 在后台启动
nohup node ~/clawd/imsg-autoresponder/scripts/watcher.js > /dev/null 2>&1 &

# 或使用 screen/tmux
screen -S imsg-watcher
node ~/clawd/imsg-autoresponder/scripts/watcher.js
# 按 Ctrl+A,然后按 D 分离会话

配置

配置文件:~/clawd/imsg-autoresponder.json

{
  "enabled": true,
  "defaultMinMinutesBetweenReplies": 15,
  "watchList": [
    {
      "identifier": "+15551234567",
      "name": "最好的朋友",
      "prompt": "回复一个中指表情",
      "minMinutesBetweenReplies": 10,
      "enabled": true
    }
  ]
}

通过 Telegram 管理(推荐)

自动回复器可以直接通过 Telegram 使用斜杠命令自然语言进行管理。

斜杠命令

支持空格和下划线两种格式:

/autorespond list              或  /autorespond_list
/autorespond status            或  /autorespond_status
/autorespond add               或  /autorespond_add <号码> <名称> <提示词>
/autorespond remove            或  /autorespond_remove <号码>
/autorespond edit              或  /autorespond_edit <号码> <提示词>
/autorespond delay             或  /autorespond_delay <号码> <分钟数>
/autorespond history           或  /autorespond_history <号码>
/autorespond test              或  /autorespond_test <号码> <消息>
/autorespond toggle            或  /autorespond_toggle
/autorespond restart           或  /autorespond_restart

批量操作:
/autorespond set-all-delays    或  /autorespond_set_all_delays <分钟数>
/autorespond enable-all        或  /autorespond_enable_all
/autorespond disable-all       或  /autorespond_disable_all

时间窗口:
/autorespond set-time-window   或  /autorespond_set_time_window <号码> <开始时间> <结束时间>
/autorespond clear-time-windows 或  /autorespond_clear_time_windows <号码>

关键词触发:
/autorespond add-keyword       或  /autorespond_add_keyword <号码> <关键词>
/autorespond remove-keyword    或  /autorespond_remove_keyword <号码> <关键词>
/autorespond clear-keywords    或  /autorespond_clear_keywords <号码>

统计与限制:
/autorespond stats             或  /autorespond_stats [<号码>]
/autorespond set-daily-cap     或  /autorespond_set_daily_cap <号码> <上限>

示例:

/autorespond_list
/autorespond_status
/autorespond_edit +15551234567 回复更讽刺一些
/autorespond_delay +15551234567 30
/autorespond_history +15551234567
/autorespond_set_time_window +15551234567 09:00 22:00
/autorespond_clear_time_windows +15551234567
/autorespond_add_keyword +15551234567 urgent
/autorespond_add_keyword +15551234567 help
/autorespond_clear_keywords +15551234567
/autorespond_stats
/autorespond_stats +15551234567
/autorespond_set_daily_cap +15551234567 10
/autorespond_set_all_delays 30
/autorespond_disable_all
/autorespond_restart

自然语言

你也可以直接用自然语言询问:

  • “给我看看自动回复器的状态”
  • “把 +15551234567 添加到监控列表,提示词是:回复要讽刺一点”
  • “把 Scott 的提示词改成更友好一些”
  • “禁用给妈妈的自动回复”
  • “自动回复器最近给 Foxy 发了什么?”
  • “重启自动回复器”

代理将理解并使用 telegram-handler.js 脚本执行命令。

命令行管理(高级)

cd ~/clawd/imsg-autoresponder/scripts

# 列出所有联系人
node manage.js list

# 添加联系人
node manage.js add "+15551234567" "你的自定义提示词" "可选名称"

# 移除联系人
node manage.js remove "+15551234567"

# 启用/禁用联系人
node manage.js enable "+15551234567"
node manage.js disable "+15551234567"

# 为联系人设置自定义延迟(分钟)
node manage.js set-delay "+15551234567" 30

# 切换整个系统的开关状态
node manage.js toggle

工作原理

  1. 监控器 通过 imsg watch 监控所有收到的消息
  2. 检查监控列表 以确定发件人是否配置了自动回复
  3. 速率限制 确保不会发送垃圾信息(可配置的回复间隔分钟数)
  4. 获取消息历史 用于对话(最近 20 条消息)
  5. 生成 AI 回复 使用 Clawdbot 和联系人配置的提示词
  6. 发送回复 通过 imsg send
  7. 记录所有内容~/clawd/logs/imsg-autoresponder.log

状态跟踪

回复时间记录在 ~/clawd/data/imsg-autoresponder-state.json 中:

{
  "lastResponses": {
    "+15551234567": 1706453280000
  }
}

这确保了速率限制在重启后也能正常工作。

提示词

提示词定义了 AI 应如何回复每个联系人。请具体说明!

示例:

"回复一个中指表情"

"你是我的得力助手。热情而简短地回复,就像我自己在回复一样。保持在 160 个字符以内。"

"你是我讽刺的朋友。用机智、略带挖苦的回复。保持简短。"

"礼貌地拒绝任何请求,就说我很忙。简短但友好。"

AI 将看到:
- 联系人的自定义提示词
- 最近的消息历史(最后 5 条消息)
- 最新的收到消息

系统要求

  • 已登录的 macOS 系统及 Messages.app
  • 已安装 imsg CLI (brew install steipete/tap/imsg)
  • 终端具有完全磁盘访问权限
  • 已安装并配置 Clawdbot
  • Anthropic API 密钥(在 ~/.clawdbot/clawdbot.json 中配置或设置 ANTHROPIC_API_KEY 环境变量)
  • curl(macOS 已预装)

安全性

  • 速率限制 防止垃圾信息(默认:每个联系人每 15 分钟回复一次)
  • 手动覆盖 通过配置中的 enabled: falsenode manage.js disable <号码>
  • 系统开关 禁用所有自动回复:node manage.js toggle
  • 日志 记录所有活动以供审查

故障排除

监控器无响应:
- 检查 ~/clawd/logs/imsg-autoresponder.log 中的错误
- 手动验证 imsg watch 是否工作:imsg watch --json
- 确保联系人在监控列表中:node manage.js list

速率限制过于严格:
- 调整延迟:node manage.js set-delay "+15551234567" 5
- 或编辑配置中的 defaultMinMinutesBetweenReplies

AI 回复不准确:
- 优化该联系人的提示词
- 检查消息历史是否正确捕获(查看日志)

代理命令处理

当用户使用关于自动回复器的斜杠命令或自然语言时,使用 telegram-handler.js 脚本。

命令映射(两种格式均支持)

用户输入 标准化为 处理程序调用
/autorespond list/autorespond_list list node telegram-handler.js list
/autorespond status/autorespond_status status node telegram-handler.js status
/autorespond add/autorespond_add <参数> add node telegram-handler.js add <号码> <名称> <提示词>
/autorespond remove/autorespond_remove <号码> remove node telegram-handler.js remove <号码>
/autorespond edit/autorespond_edit <参数> edit node telegram-handler.js edit <号码> <提示词>
/autorespond delay/autorespond_delay <参数> delay node telegram-handler.js delay <号码> <分钟数>
/autorespond history/autorespond_history <号码> history node telegram-handler.js history <号码> [限制条数]
/autorespond test/autorespond_test <号码> <消息> test node telegram-handler.js test <号码> <消息>
/autorespond toggle/autorespond_toggle toggle node telegram-handler.js toggle
/autorespond restart/autorespond_restart restart node telegram-handler.js restart
/autorespond set-all-delays/autorespond_set_all_delays <分钟数> set-all-delays node telegram-handler.js set-all-delays <分钟数>
/autorespond enable-all/autorespond_enable_all enable-all node telegram-handler.js enable-all
/autorespond disable-all/autorespond_disable_all disable-all node telegram-handler.js disable-all
/autorespond set-time-window/autorespond_set_time_window <号码> <开始> <结束> set-time-window node telegram-handler.js set-time-window <号码> <开始> <结束>
/autorespond clear-time-windows/autorespond_clear_time_windows <号码> clear-time-windows node telegram-handler.js clear-time-windows <号码>
/autorespond add-keyword/autorespond_add_keyword <号码> <关键词> add-keyword node telegram-handler.js add-keyword <号码> <关键词>
/autorespond remove-keyword/autorespond_remove_keyword <号码> <关键词> remove-keyword node telegram-handler.js remove-keyword <号码> <关键词>
/autorespond clear-keywords/autorespond_clear_keywords <号码> clear-keywords node telegram-handler.js clear-keywords <号码>
/autorespond stats/autorespond_stats [<号码>] stats node telegram-handler.js stats [<号码>]
/autorespond set-daily-cap/autorespond_set_daily_cap <号码> <上限> set-daily-cap node telegram-handler.js set-daily-cap <号码> <上限>

处理步骤:
1. 检测 /autorespond/autorespond_ 前缀
2. 提取子命令(将下划线标准化为空格)
3. 解析剩余参数
4. 使用适当的参数调用 telegram-handler.js

自然语言模式匹配

  • “显示/列出/查看自动回复器” → node telegram-handler.js list
  • “将 [联系人] 添加到自动回复器” → node telegram-handler.js add <号码> <名称> <提示词>
  • “更改/编辑/更新 [联系人] 的提示词” → node telegram-handler.js edit <号码> <提示词>
  • “为 [联系人] 设置延迟” → node telegram-handler.js delay <号码> <分钟数>
  • “禁用/从自动回复器中移除 [联系人]” → node telegram-handler.js remove <号码>
  • “自动回复器状态” → node telegram-handler.js status
  • “自动回复器给 [联系人] 发了什么” → node telegram-handler.js history <号码>
  • “重启自动回复器” → node telegram-handler.js restart
  • “启用/禁用自动回复器” → node telegram-handler.js toggle

联系人解析:
- 当用户提到联系人姓名时,从配置中查找其电话号码
- 始终使用完整的 E.164 格式(例如,+15551234567

配置更改后:
如果命令输出提到需要重启监控器,请务必提醒用户。

故障排除

监控器无响应

检查状态:

/autorespond_status

查看日志:

tail -f ~/clawd/logs/imsg-autoresponder.log

重启:

/autorespond_restart

常见问题

“OPENAI_API_KEY not found”
- 将 API 密钥添加到 ~/.clawdbot/clawdbot.json
json { "skills": { "openai-whisper-api": { "apiKey": "sk-proj-YOUR_KEY_HERE" } } }
- 添加密钥后重启监控器

权限错误
- 在系统设置中授予终端完全磁盘访问权限
- 授予权限后重启终端
- 手动验证 imsg chats --json 是否工作

未检测到消息
- 检查 Messages.app 是否已登录
- 验证联系人是否在监控列表中:/autorespond_list
- 确保监控器正在运行:/autorespond_status

重复回复
- 当前版本已通过处理锁修复此问题
- 重启监控器以应用修复:/autorespond_restart

测试

生成实际的 AI 回复但不发送(预览模式):

/autorespond_test +15551234567 嘿,最近怎么样?

这将:
- 使用联系人的实际提示词
- 通过 OpenAI 生成真实的 AI 回复
- 显示将要发送的确切内容
- 实际上不会发送消息

非常适合在正式使用前测试新提示词!

隐私与安全

⚠️ 重要提示: 此工具会自动代表你发送消息。

  • 只添加那些知道自己在与 AI 发短信或不介意的人
  • 定期通过 /autorespond_history 审查回复
  • 使用速率限制避免垃圾信息
  • 在适当时保持透明
  • 需要时可立即禁用:/autorespond_toggle

未来增强

  • 基于对话模式的智能速率限制
  • 群聊支持
  • Web 仪表板
  • 语音消息转录
3 次点击  ∙  0 人收藏  
登录后收藏  
目前尚无回复
0 条回复
About   ·   Help   ·    
OA0 - Omni AI 0 一个探索 AI 的社区
沪ICP备2024103595号-2
Developed with Cursor