Integrate Wix Chat with OpenAI: Inbox Migration and Draft Replies

Updated: Nov 2
A Wix Chat integration with OpenAI needs more than a model request: it must identify the incoming conversation, keep credentials on the backend, control duplicate processing and provide a clear path to a person.
Wix’s older wix-chat-backend events are deprecated. Use the Wix Chat migration guidance to move toward Inbox events and the current Inbox message API.

Choose a narrow first version
Start with AI-generated draft replies reviewed by a team member. Define the questions it may help answer and the information it can rely on. Do not ask a model to infer current prices, booking availability or private account details from a short customer message.
The helper below generates a draft. Sending that draft to a visitor is a separate operation and should happen only under your defined review or automation rules.
Prepare backend configuration
Create an OpenAI API project with appropriate spending controls. Store OPENAI_API_KEY and OPENAI_MODEL in Wix Secrets Manager. Set OPENAI_MODEL to a Responses-compatible model available to that API project; verify its suitability, cost and limits in the official documentation.
The OpenAI Responses reference and text-generation guide document the model request and returned text. A ChatGPT subscription and API project access are different product arrangements.
Add a backend-only draft helper
Create backend/ai-reply.js:
// backend/ai-reply.js — backend-only helper, not a public web method
import { secrets } from "@wix/secrets";
import { auth } from "@wix/essentials";
import { fetch } from "wix-fetch";
const readSecret = auth.elevate(secrets.getSecretValue);
export async function createDraftReply(question) {
if (typeof question !== "string" || !question.trim() || question.length > 2000) {
throw new Error("A question of 1–2,000 characters is required.");
}
const [{ value: apiKey }, { value: model }] = await Promise.all([
readSecret("OPENAI_API_KEY"),
readSecret("OPENAI_MODEL")
]);
const response = await fetch("https://api.openai.com/v1/responses", {
method: "POST",
headers: {
Authorization: "Bearer " + apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify({
model,
instructions:
"Draft a short customer-support response. Do not invent prices, " +
"availability, account details or completed actions. If information " +
"is missing, ask for clarification or recommend human assistance.",
input: question.trim(),
max_output_tokens: 300,
store: false
})
});
if (!response.ok) throw new Error("A draft reply could not be generated.");
const result = await response.json();
if (result.status !== "completed") throw new Error("The draft reply is incomplete.");
const text = (result.output ?? [])
.filter(item => item.type === "message")
.flatMap(item => item.content ?? [])
.filter(part => part.type === "output_text")
.map(part => part.text)
.join("\n")
.trim();
if (!text) throw new Error("No draft reply was returned.");
return text;
}The helper validates the question, bounds the output request, checks for a completed response and reads output_text content blocks. It does not assume that the first output item is always a text message.
The store setting controls response storage for this API request; it is not a promise that no operational logging or other retention applies. Review the provider’s current data controls for your use case.
Receive messages through the current Inbox workflow
Follow Wix’s migration mapping for the event generated when a message is sent to the business. Register the event through the supported backend event workflow.
Use the event’s message ID and conversation ID to create a processing record. Verify the channel, sender and message type before requesting a draft. Do not process outgoing business replies as new customer prompts.
Backend event behaviour must be checked on the published site, rather than assumed from Preview.
Review and send through Inbox
Use the current Inbox sendMessage API when an approved response should be sent. The documented message includes the conversation, direction, visibility and structured content.
Keep the conversation ID from the trusted event or a verified record. A public caller must not be able to choose another customer’s conversation.
Add safeguards before automatic replies
Store a durable processing record keyed to the incoming message. Handle repeated events, timeouts, provider errors and cases where a person has taken over the conversation.
An in-memory Set or boolean is not a durable duplicate-prevention system. Decide how failed work is retried and when it is routed to a person. Avoid automatically retrying an operation that may already have sent a reply.
Keep a clear distinction between customer instructions, approved business information and the assistant’s operating rules. Treat text from a visitor as input, not permission to change settings or expose private data.
Test the complete conversation
Try empty messages, attachments, duplicate events, long input, unavailable models, incomplete responses and a human handoff. Verify that one accepted incoming message cannot start a reply loop.
Local checks covered the draft helper’s validation, request shape and output parsing using simulated services. The Inbox connection and any automatic-send workflow require a separate published-site test.
Confirm the chat product and integration boundary
Identify the chat or Inbox product actually installed on the site and the current events and sending methods it supports. The restored Wix Chat screenshots show the earlier tutorial’s installation and prototype interfaces. Use them as context while checking the current Wix workflow for the site being maintained.
This guide’s executable component is a backend draft helper. It accepts a question and returns draft text. It does not install a chat app, subscribe to Inbox events or automatically post a message into a conversation. Keeping that boundary clear makes it possible to test the text-generation component before connecting it to customer communications.

Complete the backend setup before testing a draft
Create backend/ai-reply.js and keep it as a backend-only module. Store the API credential in OPENAI_API_KEY and a model identifier available to the intended API project in OPENAI_MODEL. A website’s browser code should not receive either secret.
Use a backend-controlled caller when testing createDraftReply. Start with a fictional, non-sensitive customer question and inspect the returned text. Do not make the helper public merely to call it from an arbitrary browser input. A later staff interface needs its own appropriate permission boundary.
The official OpenAI text-generation guide documents Responses requests and the distinction between instructions and input. The model is configuration in this sample so the application owner can select an available, appropriate model without hard-coding an obsolete product name into the article.

Give the draft enough approved context
The small helper does not retrieve a business knowledge base. It cannot reliably answer a question about current opening hours, an unpublished price or a customer’s order unless the application supplies authorized, current information through an appropriately designed workflow.
Begin with a narrow task such as drafting a polite acknowledgement or rephrasing a staff-approved answer. If factual business answers are required, identify the approved source and how it is kept current. Keep customer-supplied messages separate from the application’s instructions and approved business information.
For a hypothetical enquiry asking whether a service is available next Tuesday, an appropriate draft may ask staff to check availability. It should not invent a booking confirmation. A confident tone does not establish that an external system was consulted or an action completed.
Build a deliberate human handoff
In a reviewed workflow, staff read the customer message, request a draft through the authorized interface, check it against the business information and send an approved reply through Inbox. Keep the original question visible during review so an apparently polished answer is not approved out of context.
Make the draft status obvious. A staff member should be able to edit or discard the text without accidentally sending it. Record the association with the correct conversation only through the intended backend workflow, and verify the destination before any send action.
The restored prototype image illustrates the earlier chat experience. The updated code’s returned string is a draft, not evidence that a message reached a customer. Testing the draft helper and testing a full conversation are separate stages.

Prepare useful failure and escalation behavior
If generation fails or returns an incomplete response, keep a working route to staff assistance. Do not replace an error with an invented answer that appears authoritative. Show an appropriate service message and preserve the original customer task.
Define topics that require a human decision. A request to change an account, promise a refund or confirm a booking needs the relevant authorization and system evidence. A text-generation response should not be treated as that authorization.
For a future automated workflow, define event handling, conversation ownership, duplicate processing, rate limits and loop prevention before enabling replies. A message generated by the system must not become a new customer question that triggers another reply repeatedly.
Test questions that expose the limits
Use fictional examples covering a normal enquiry, a vague request, a question requiring unavailable information and a message attempting to change the assistant’s instructions. Review whether the returned draft stays within the approved task and gives staff a useful starting point.
Then test the operational handoff: the right conversation, the correct staff permissions, an unavailable API and a rejected draft. Keep private customer information out of public screenshots and unnecessary diagnostic logs. Review the current API data controls for the project rather than treating one request parameter as a complete privacy policy.
Keep each integration responsibility explicit
Component | Responsibility | Included in the helper? |
Input boundary | Validate a question of 1–2,000 characters | Yes |
Responses request | Send the question using backend credentials | Yes |
Draft extraction | Read completed output_text content | Yes |
Inbox event adapter | Receive the correct customer conversation | No; requires current site-specific integration |
Review and sending | Approve a draft and address the correct conversation | No automatic sending in this example |
The 300 max_output_tokens setting is a configured output budget, not a promise of exactly 300 words. Follow official OpenAI text-generation guidance for request behavior. A triggered email is a separate communication workflow and should not be substituted silently for an Inbox reply.
Can the model book or refund something automatically?
Only a separately implemented and authorized business workflow can perform those actions. A generated sentence is not proof that an action occurred.
Should I send full customer records to the model?
Provide only information appropriate to the task and your privacy obligations. Avoid forwarding sensitive conversation history by default.
Contact CodeMasters to scope the integration, or review our Wix enquiry troubleshooting guide if the immediate issue is missed customer messages.


