w
This commit is contained in:
@@ -254,9 +254,9 @@ function showFallback() {
|
|||||||
|
|
||||||
// ─── n8n Webhook (#5.2, #6) ──────────────────────────────────
|
// ─── n8n Webhook (#5.2, #6) ──────────────────────────────────
|
||||||
|
|
||||||
async function postWebhook(path, body) {
|
async function postWebhook(body) {
|
||||||
const base = (CFG.webhook_base || '').replace(/\/$/, '');
|
const url = (CFG.webhook_base || '').replace(/\/$/, '');
|
||||||
const res = await fetch(`${base}${path}`, {
|
const res = await fetch(url, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify(body),
|
body: JSON.stringify(body),
|
||||||
@@ -268,6 +268,7 @@ async function postWebhook(path, body) {
|
|||||||
|
|
||||||
async function startSession(entry) {
|
async function startSession(entry) {
|
||||||
const payload = {
|
const payload = {
|
||||||
|
action: 'start',
|
||||||
entry,
|
entry,
|
||||||
sponsor: window.FESTIVAL.sponsor,
|
sponsor: window.FESTIVAL.sponsor,
|
||||||
session_id: window.FESTIVAL.session_id,
|
session_id: window.FESTIVAL.session_id,
|
||||||
@@ -277,7 +278,7 @@ async function startSession(entry) {
|
|||||||
};
|
};
|
||||||
const typing = showTyping();
|
const typing = showTyping();
|
||||||
try {
|
try {
|
||||||
const data = await postWebhook('/festival/start', payload);
|
const data = await postWebhook(payload);
|
||||||
if (typing) typing.remove();
|
if (typing) typing.remove();
|
||||||
const reply = (data?.reply && typeof data.reply === 'string')
|
const reply = (data?.reply && typeof data.reply === 'string')
|
||||||
? data.reply
|
? data.reply
|
||||||
@@ -304,6 +305,7 @@ async function sendMessage(text) {
|
|||||||
appendBubble('user', text);
|
appendBubble('user', text);
|
||||||
|
|
||||||
const payload = {
|
const payload = {
|
||||||
|
action: 'message',
|
||||||
session_id: window.FESTIVAL.session_id,
|
session_id: window.FESTIVAL.session_id,
|
||||||
entry: window.FESTIVAL.entry,
|
entry: window.FESTIVAL.entry,
|
||||||
sponsor: window.FESTIVAL.sponsor,
|
sponsor: window.FESTIVAL.sponsor,
|
||||||
@@ -313,7 +315,7 @@ async function sendMessage(text) {
|
|||||||
|
|
||||||
const typing = showTyping();
|
const typing = showTyping();
|
||||||
try {
|
try {
|
||||||
const data = await postWebhook('/festival/message', payload);
|
const data = await postWebhook(payload);
|
||||||
if (typing) typing.remove();
|
if (typing) typing.remove();
|
||||||
const reply = (data?.reply && typeof data.reply === 'string' && data.reply.trim())
|
const reply = (data?.reply && typeof data.reply === 'string' && data.reply.trim())
|
||||||
? data.reply : '…';
|
? data.reply : '…';
|
||||||
|
|||||||
Reference in New Issue
Block a user