Quick Overview
This workflow processes incoming chat messages, uses Google Sheets to deduplicate and track escalation status by session, and calls OpenAI to decide whether to answer or escalate to a human, muting the bot during active handoffs and re-enabling it after a timeout.
How it works
- Runs manually (replace with your chat webhook in production) and maps the incoming message fields like sessionId, messageId, channel, and userMessage.
- Checks a Google Sheets “processed_messages” sheet to detect whether the messageId was already handled and stops if it is a duplicate.
- Logs the messageId to Google Sheets for idempotency and looks up the session’s escalation status in an “escalations” sheet.
- If the escalation status is PENDING and the configured timeout has not expired, the workflow stays silent so a human can continue the conversation.
- Otherwise, it sends the user message to an OpenAI-powered agent to either generate a normal reply or return the signal ESCALATE_TO_HUMAN.
- If escalation is needed, it upserts a PENDING escalation record in Google Sheets, sets a holding message for the user, and prepares a notification payload for a human agent.
- If escalation is not needed, it outputs the AI’s response for you to send back via your messaging provider.
Setup
- Add an OpenAI API credential and select the chat model in the OpenAI Chat Model node.
- Add a Google Sheets OAuth credential and create a spreadsheet with two sheets named “processed_messages” (messageId, processedAt) and “escalations” (sessionId, userMessage, channel, status, escalatedAt, resolvedAt).
- Update the Google Sheets document URL/ID and sheet references to point to your spreadsheet.
- Replace the manual trigger and sample input mapping with your real inbound webhook payload (for example from Evolution API, Twilio, or WhatsApp Cloud).
- Replace the “Notify Human” placeholder with a real notification action (for example Slack or email) and connect the normal and escalation responses to your messaging provider to reply to the user.
- Adjust the workflow config values (escalationTimeoutMinutes and holdingMessage) to match your handoff process.