Google Forms + Server酱:表单有新提交时推送到微信

效果:Google Forms 表单每次有新提交时,自动将所有问答内容推送到你的微信。

前置条件

  • 一个 Google Forms 表单及其对应的 Google Sheets 响应表格
  • Server酱 SendKey(登录 sct.ftqq.com,在「SendKey」页面复制;详见 30 秒获取教程
  • Server酱 支持推送到微信服务号/企业微信/钉钉/飞书等多个通道,详见 通道说明

配置步骤

在表单对应的 Google Sheets 响应表格中,依次点击 扩展程序 → Apps Script,将以下代码粘贴到编辑器中:

function onFormSubmit(e) {
  var response = e.response;
  var itemResponses = response.getItemResponses();
  var desp = '';
  for (var i = 0; i < itemResponses.length; i++) {
    var item = itemResponses[i];
    desp += '**' + item.getItem().getTitle() + '**: ' + item.getResponse() + '\n\n';
  }

  UrlFetchApp.fetch('https://sctapi.ftqq.com/你的SENDKEY.send', {
    method: 'post',
    payload: {
      title: '收到新的表单提交',
      desp: desp
    }
  });
}

将代码中的 你的SENDKEY 替换为你自己的 SendKey。如果使用 Server酱³(SendKey 以 sctp 开头),将 API 地址改为 https://你的UID.push.ft07.com/send/你的SENDKEY.send(UID 为 sctp 与 t 之间的数字)。

点击保存后,设置触发器:在编辑器左侧点击「触发器」图标,添加新触发器——函数选 onFormSubmit,事件来源选「来自电子表格」,事件类型选「提交表单时」(具体选项以应用内实际显示为准)。

完整示例

以下版本增加了时间戳、空值处理和错误捕获,可直接替换上方代码:

function onFormSubmit(e) {
  try {
    var response = e.response;
    var timestamp = new Date().toLocaleString('zh-CN');
    var itemResponses = response.getItemResponses();
    var desp = '';
    for (var i = 0; i < itemResponses.length; i++) {
      var item = itemResponses[i];
      var answer = item.getResponse() || '(未填写)';
      desp += '**' + item.getItem().getTitle() + '**: ' + answer + '\n\n';
    }

    UrlFetchApp.fetch('https://sctapi.ftqq.com/你的SENDKEY.send', {
      method: 'post',
      payload: {
        title: '【新提交】Google Forms ' + timestamp,
        desp: desp
      }
    });
  } catch (err) {
    console.error('推送失败: ' + err.message);
  }
}

常见问题

每天能发多少条消息?

免费用户每天可发送 5 条,订阅会员目前特价最低 3 元/月,一天最多可发 1000 条(价格详情)。

提交表单后没有收到微信通知?

先在 Apps Script 编辑器中手动运行 onFormSubmit 检查是否有报错,再确认触发器已正确设置。如代码执行正常但仍未收到消息,参考 常见问题与排查 排查推送通道问题。

每分钟最多能发多少条?

Server酱 API 每分钟上限为 50 条。Google Forms 短时间内大量提交可能触发频率限制。

触发器没有自动执行怎么办?

确认触发器的事件来源为「来自电子表格」、事件类型为「提交表单时」。Apps Script 触发器偶尔有延迟,若长时间未执行,可在触发器页面查看执行记录排查错误。

相关集成

懒人方案:把这段话复制给你的 AI 助手

把下面这段文字原样粘贴给 Claude Code、Cursor 或任何 AI 编程助手,它就会替你完成 Server酱 的接入:

请帮我把 Server酱 微信通知接入到我当前的项目/工具中:
1. API:POST https://sctapi.ftqq.com/{SendKey}.send,参数 title(必填,不能含换行)、desp(正文,支持 Markdown,可选);成功时返回 JSON 的 code 为 0。
2. 如果我的 SendKey 以 sctp 开头,则改用 https://{uid}.push.ft07.com/send/{SendKey}.send,uid 是 SendKey 中 sctp 与 t 之间的数字。
3. SendKey 从环境变量 SERVERCHAN_SENDKEY 读取;如果没有,提醒我到 https://sct.ftqq.com 免费获取(每天 5 条额度)。
4. 安全要求:不要把 SendKey 硬编码进代码、不要打印到日志、不要提交到 git。
5. 频率约定:任务结束发 1 条结果摘要即可,批量任务合并成一条,不要每步都推。
请根据我当前的项目和场景直接写好代码/配置并验证。