Quick overview
This workflow polls a Chatwork room every minute, detects new mentions of a bot account, and uses Anthropic Claude to generate an opinion based on recent context, citing linked source messages, then replies in Chatwork and logs handled mentions in an n8n Data Table.
How it works
- Runs every minute (or manually) to check activity in a specified Chatwork room.
- Fetches the bot’s Chatwork account details, reads the latest room messages, and loads previously answered mention IDs from an n8n Data Table.
- Identifies new, recent mentions of the bot, builds a plain-text conversation context for each, and limits processing to a maximum number per run.
- If the mention doesn’t include a clear topic, replies in Chatwork asking the user to state what they want an opinion on.
- If a topic is present, sends the context and request to Anthropic Claude and expects a structured JSON response with premises, opinion, concerns, and human decision points.
- Validates that each premise references a real message in the captured context, formats a reply with Chatwork links to the source messages, posts it to the room, and records the mention as answered in the Data Table.
Setup
- Create a Chatwork bot account, add it to the target room, and create an HTTP Header Auth credential that sends
X-ChatWorkToken with the bot’s API token.
- Add an Anthropic credential and select the Claude model you want to use.
- Create an n8n Data Table with columns
message_id, room_id, result, and reply_message_id, and select it in both Data Table nodes.
- Set the Chatwork
room_id (and optional limits like context_size, max_age_minutes, and max_answers_per_run) in the Config step.
- Run the workflow once manually to confirm the bot can read messages and post replies, then activate it for scheduled polling.
Requirements
- A Chatwork account for the bot (a separate account, added to the room) and its API token
- Header Auth credential: name X-ChatWorkToken, value = the bot's API token
- Anthropic API key (Claude Haiku 5.5 by default; any chat model works)
- An n8n Data Table with the text columns message_id, room_id, result, reply_message_id
Customization
- Config: room_id, context_size (how many earlier messages the AI reads, default 50), max_age_minutes (older mentions are skipped, default 60), max_answers_per_run, timezone
- Reply wording: the L object at the top of "Check sources and build the reply" (labels, ask-back and failure messages)
- Swap the model node for another chat model
Additional info
The rule in the room is that whoever mentions the bot writes what they want an opinion on. A mention with no topic is answered with a short question instead of an opinion.
Every premise in the reply links to its source message, and code removes any premise whose message number is not in the conversation, so the AI cannot cite messages that do not exist.
The conversation is passed to the AI as data, so instructions written inside the chat are not followed (tested).
Each mention is recorded in a Data Table and answered once, including when the AI call fails.
Tested on a real Chatwork room in Japanese and English.