web: handle multi-payload replies
parent
10182f1182
commit
ec46932259
|
|
@ -656,31 +656,33 @@ export async function monitorWebProvider(
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if (
|
const replyList = replyResult
|
||||||
!replyResult ||
|
? Array.isArray(replyResult)
|
||||||
(!replyResult.text &&
|
? replyResult
|
||||||
!replyResult.mediaUrl &&
|
: [replyResult]
|
||||||
!replyResult.mediaUrls?.length)
|
: [];
|
||||||
) {
|
|
||||||
|
if (replyList.length === 0) {
|
||||||
logVerbose("Skipping auto-reply: no text/media returned from resolver");
|
logVerbose("Skipping auto-reply: no text/media returned from resolver");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply response prefix if configured (skip for HEARTBEAT_OK to preserve exact match)
|
// Apply response prefix if configured (skip for HEARTBEAT_OK to preserve exact match)
|
||||||
const responsePrefix = cfg.inbound?.responsePrefix;
|
const responsePrefix = cfg.inbound?.responsePrefix;
|
||||||
|
|
||||||
|
for (const replyPayload of replyList) {
|
||||||
if (
|
if (
|
||||||
responsePrefix &&
|
responsePrefix &&
|
||||||
replyResult.text &&
|
replyPayload.text &&
|
||||||
replyResult.text.trim() !== HEARTBEAT_TOKEN
|
replyPayload.text.trim() !== HEARTBEAT_TOKEN &&
|
||||||
|
!replyPayload.text.startsWith(responsePrefix)
|
||||||
) {
|
) {
|
||||||
if (!replyResult.text.startsWith(responsePrefix)) {
|
replyPayload.text = `${responsePrefix} ${replyPayload.text}`;
|
||||||
replyResult.text = `${responsePrefix} ${replyResult.text}`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await deliverWebReply({
|
await deliverWebReply({
|
||||||
replyResult,
|
replyResult: replyPayload,
|
||||||
msg: latest,
|
msg: latest,
|
||||||
maxMediaBytes,
|
maxMediaBytes,
|
||||||
replyLogger,
|
replyLogger,
|
||||||
|
|
@ -688,11 +690,11 @@ export async function monitorWebProvider(
|
||||||
connectionId,
|
connectionId,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (replyResult.text) {
|
if (replyPayload.text) {
|
||||||
recentlySent.add(replyResult.text);
|
recentlySent.add(replyPayload.text);
|
||||||
recentlySent.add(combinedBody); // Prevent echo on the batch text itself
|
recentlySent.add(combinedBody); // Prevent echo on the batch text itself
|
||||||
logVerbose(
|
logVerbose(
|
||||||
`Added to echo detection set (size now: ${recentlySent.size}): ${replyResult.text.substring(0, 50)}...`,
|
`Added to echo detection set (size now: ${recentlySent.size}): ${replyPayload.text.substring(0, 50)}...`,
|
||||||
);
|
);
|
||||||
if (recentlySent.size > MAX_RECENT_MESSAGES) {
|
if (recentlySent.size > MAX_RECENT_MESSAGES) {
|
||||||
const firstKey = recentlySent.values().next().value;
|
const firstKey = recentlySent.values().next().value;
|
||||||
|
|
@ -703,13 +705,13 @@ export async function monitorWebProvider(
|
||||||
if (isVerbose()) {
|
if (isVerbose()) {
|
||||||
console.log(
|
console.log(
|
||||||
success(
|
success(
|
||||||
`↩️ Auto-replied to ${from} (web${replyResult.mediaUrl || replyResult.mediaUrls?.length ? ", media" : ""}; batched ${messages.length})`,
|
`↩️ Auto-replied to ${from} (web${replyPayload.mediaUrl || replyPayload.mediaUrls?.length ? ", media" : ""}; batched ${messages.length})`,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
console.log(
|
console.log(
|
||||||
success(
|
success(
|
||||||
`↩️ ${replyResult.text ?? "<media>"}${replyResult.mediaUrl || replyResult.mediaUrls?.length ? " (media)" : ""}`,
|
`↩️ ${replyPayload.text ?? "<media>"}${replyPayload.mediaUrl || replyPayload.mediaUrls?.length ? " (media)" : ""}`,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -718,6 +720,7 @@ export async function monitorWebProvider(
|
||||||
danger(`Failed sending web auto-reply to ${from}: ${String(err)}`),
|
danger(`Failed sending web auto-reply to ${from}: ${String(err)}`),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const enqueueBatch = async (msg: WebInboundMsg) => {
|
const enqueueBatch = async (msg: WebInboundMsg) => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue