top of page
bottom of page
// Replace YOUR_API_KEY with your actual API key const apiKey = "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"; // Listen for incoming chat messages wixChat.onMessage((event) => { // Extract the user's message from the event object const userMessage = event.message.text; // Call the OpenAI GPT API to generate a response fetch("https://api.openai.com/v1/engines/davinci-codex/completions", { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}`, }, body: JSON.stringify({ prompt: userMessage, max_tokens: 50, temperature: 0.5, }), }) .then((response) => response.json()) .then((data) => { // Extract the generated response from the API response const responseText = data.choices[0].text; // Send the response back to the user via the chatbot wixChat.sendChatMessage({ text: responseText, }); }) .catch((error) => console.error(error)); });