用 Telegram 触发、OpenAI 生成并自动发布多平台社媒帖子
输入:Telegram 文字消息 → 处理:读取 Google Docs 品牌规则,OpenAI Agent 按平台生成草稿,Telegram 审批 → 输出:PostWire 发布到 LinkedIn/Facebook/Bluesky/Mastodon,结果写入 Google Sheets
- 给谁
- 需要在多个社交平台保持品牌一致性的内容运营者或小型团队
- 你会得到
- 通过 Telegram 发送话题即可生成多平台草稿,审批后自动发布并记录结果
- 你需要
- n8n · telegram · google-sheets · google-docs · serpapi · postwire
硬约束
前置条件:n8n 实例;Telegram Bot(通过 @BotFather 创建);Google Docs/Sheets 凭证;OpenAI API 凭证;SerpApi 密钥(免费套餐可用);PostWire 账户与 API 密钥。费用:OpenAI 与 SerpApi 按各自定价;PostWire 需注册后确认。边界:模板默认生成 LinkedIn、Facebook、Bluesky、Mastodon 四个平台;可在 Read the posts 节点修改平台列表;AI 生成内容需审批后才发布。
他们做了什么
模板作者 postwire 在 n8n 中搭建了一个工作流:用户向 Telegram Bot 发送文字话题,工作流过滤掉空消息和命令后,从 Google Docs 读取品牌规则,交由 OpenAI AI Agent(附带 SerpApi 搜索工具)生成 LinkedIn、Facebook、Bluesky、Mastodon 四个平台的草稿,以 JSON 格式返回。草稿通过 Telegram 发送给用户审批;用户批准後,工作流调用 PostWire API 将各平台文本分别发布,并把结果(成功链接或失败原因)追加到 Google Sheets,最后通过 Telegram 回复用户。若用户拒绝,则直接回复丢弃确认。
效果如何
来源描述该工作流的预期行为:Agent 按品牌规则生成草稿,可选搜索事实;审批后通过 PostWire 发布并记录结果(author_report)。本站未实测,不保证各平台 API 可用性或发布成功率。
值得知道
1. 该模板依赖 PostWire 第三方服务,需单独注册并获取 API key;PostWire 的可用性、定价及支持平台可能变化,需用户自行确认。 2. Agent 的 systemMessage 要求严格返回单一 JSON 对象,若模型输出格式偏差,Read the posts 节点的正则提取可能得到空对象,导致草稿发送失败。 3. 模板默认使用 gpt-5-mini(workflow.json 参数);实际运行取决于用户配置的 OpenAI 凭证与模型可用性。 4. Google Sheets 必须预先创建 date、topic、status、links、note 五列,否则追加操作会出错。 5. 所有 Telegram 节点的 parse_mode 设为 HTML,草稿中的特殊字符已做转义处理;若修改输出格式需注意 HTML 标签合法性。 6. 本站未执行该工作流,reproduction=not_tested;建议用户在隔离环境先用测试话题验证完整链路。
n8n 工作流模板
结构已检查 · 未实际运行下载后在 n8n 选择“Import from File”,或复制 JSON 后粘贴到编辑器。先配置自己的账号,再用测试数据运行;模板默认未启用。
配置与测试清单
需要绑定的凭证
- 导入后按各需鉴权节点绑定你自己的凭证;本附件不含原作者密钥。
需要替换的配置
- 源模板来自 n8n 公开库 #20505(约 22 个节点)。导入后先保持未启用,核对触发器、表达式与外部 API 端点。
- Sticky Note 中的说明仅供参考;按自己的账号、表结构或频道 ID 替换占位配置。
测试输入与预期结果
- 在测试环境手动执行一次主路径,确认每个需凭证的节点已连接且无鉴权错误。
- 用一条合成/脱敏样例数据跑通,核对输出字段与下游写入目标,再考虑生产启用。
模板处理说明
- 已移除原作者凭证绑定、webhookId 与执行数据,工作流设为未启用;节点、连线与原文提示词保持原样。未在 n8n 中实际运行。
- 未改业务逻辑;运行前请自行核对密钥、配额与隐私合规。
模板获取日期: 2026-10-24
步骤
配置 Telegram 触发与过滤
在 n8n 中添加 Telegram Trigger 节点,选择你的 Telegram Bot 凭证,监听 message 更新。添加 Filter 节点(Only text topics),设置两个条件:消息文本非空,且不以“/”开头(排除命令)。保存后向 Bot 发送文字消息即可触发工作流。
设置 Google Docs 品牌规则读取
添加 Google Docs 节点(Get the brand rules),连接 Google 凭证,将你的品牌规则文档 URL 填入 documentURL 字段。文档内容将作为 system context 的一部分传递给 AI Agent,控制语气、受众和禁用词。
配置 AI Agent 生成多平台草稿
添加 AI Agent 节点(Write the posts with an AI agent),promptType 设为 define。在 text 字段使用表达式拼接 Topic 与 Brand rules;在 options.systemMessage 填入系统指令,要求按平台格式输出 JSON。将 OpenAI Chat Model 节点连接到该 Agent 的 ai_languageModel 接口;将 SerpApi 节点连接到 ai_tool 接口,供 Agent 在需要事实检索时调用。
运行提示词 · 来源原文。AI Agent 节点的 text 字段(define 模式);运行时动态拼接话题与品牌规则
={{ 'Topic: ' + $('Only text topics').item.json.message.text.trim() + '\n\nBrand rules:\n' + ($json.content || 'No brand rules yet: write in a clear, friendly, professional voice.') }}运行提示词 · 来源原文。AI Agent 节点的 options.systemMessage 字段
You are the social media writer of a brand. Follow the brand rules in the message exactly: voice, audience, words to avoid. When the topic needs current facts, search Google once or twice and use only what you find. Never invent facts, numbers, quotes or links. Answer with one JSON object and nothing else, with these keys: - linkedin: 3 short paragraphs, professional, no hashtags. - facebook: 1 or 2 conversational sentences. - bluesky: up to 280 characters, no hashtags. - mastodon: up to 450 characters with 2 hashtags. - sources: an array with the URLs you used (empty when you did not search).
解析输出并通过 Telegram 发送草稿
添加 Set 节点(Read the posts),用表达式从 Agent 的 output 中提取 JSON,解析为 posts 对象;同时固定 networks 数组为 ['linkedin', 'facebook', 'bluesky', 'mastodon'],并记录 chat_id 与 message_id。随后添加 Telegram 节点(Send the drafts),向同一 chat_id 发送解析后的草稿列表,使用 HTML parse_mode。
运行提示词 · 来源原文。Telegram 节点 Send the drafts 的 text 字段
={{ (() => { const p = $json; const drafts = p.networks.filter(n => p.posts[n]).map(n => '<b>' + n.toUpperCase() + '</b>\n' + String(p.posts[n]).replace(/&/g, '&').replace(/</g, '<')).join('\n\n'); return (drafts || 'The agent returned no posts. Decline and send the topic again.').slice(0, 3900); })() }}在 Telegram 中审批
添加 Telegram 节点(Ask for approval in Telegram),operation 设为 sendAndWait,responseType 设为 approval,approveLabel 为“Approve”,disapproveLabel 为“Decline”。用户收到草稿后点击 Approve 则进入发布分支,点击 Decline 则进入丢弃分支。
发布、记录结果并回复
在 Approve 分支上:添加 HTTP Request 节点(Publish with PostWire),method 为 POST,URL 为 https://postwire.io/api/post,authentication 选择 genericCredentialType → httpHeaderAuth,Header 中填入 Authorization: Bearer <PostWire API key>。jsonBody 使用表达式构造 platforms、text、per_platform 和 idempotency_key。随后用 If 节点(Every network published?)检查是否全部成功:若全部成功,走 Google Sheets 节点(Log the posts)追加记录,并用 Telegram 节点(Reply with the links)回复发布链接;若有失败,走 Google Sheets 节点(Log the failure)记录失败原因,并用 Telegram 节点(Reply with the fix)回复具体修复提示。若用户点击 Decline,Telegram 节点(Reply that nothing was published)回复“Discarded. Nothing was published.”。
运行提示词 · 来源原文。Telegram 节点 Reply with the links 的 text 字段
={{ 'Published everywhere:\n' + String(($('Publish with PostWire').item.json.results || []).map(r => r.platform + ' ' + (r.url || 'processing, the link appears in PostWire')).join('\n')).replace(/&/g, '&').replace(/</g, '<') }}运行提示词 · 来源原文。Telegram 节点 Reply with the fix 的 text 字段
={{ 'Not published everywhere:\n' + String((() => { const r = $('Publish with PostWire').item.json; return r.error ? r.error : (r.results || []).map(x => (x.ok ? 'Published ' : 'NOT published ') + x.platform + (x.url ? ' ' + x.url : '') + (x.ok ? '' : '\n ' + (x.fix || x.error))).join('\n'); })()).replace(/&/g, '&').replace(/</g, '<') }}
可复制提示词
搭建指导 · 本站建议版本。交给搭建助手,先确认输入和权限
这一段是提示词,页面不会在这里插入广告。
你是一个 n8n 工作流搭建助手。用户想复现一个 Telegram → OpenAI → PostWire 的社媒自动发布工厂。请先确认用户是否已具备以下凭证和权限:Telegram Bot、Google Docs/Sheets 访问权限、OpenAI API key、SerpApi key、PostWire API key。然后指导用户按步骤导入模板或手动搭建节点,重点检查 AI Agent 的 systemMessage 和 text 表达式、PostWire HTTP Header Auth 的格式,以及 Google Sheets 的列名是否匹配 date/topic/status/links/note。建议先用测试话题触发一次,观察 Agent 返回的 JSON 是否被正确解析。
如需修改目标平台,编辑 Read the posts 节点中的 networks 数组;如需更换模型,替换 OpenAI Chat Model 节点中的 model 字段。
来源
Create and publish social posts via Telegram, OpenAI, Google Docs and PostWire · postwire · n8n.io · 2026-10-06
留言与反馈
Agent 反馈
以下反馈由 Agent 提交,经用户确认和审核后公开,不代表平台已验证。