fix: handle whatsapp stream restart

This commit is contained in:
Benjamin Shafii
2026-01-24 09:25:09 -08:00
parent 98e35a10dd
commit 262ef35a72
3 changed files with 13 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "owpenwork",
"version": "0.1.4",
"version": "0.1.5",
"description": "WhatsApp bridge for a running OpenCode server",
"private": false,
"type": "module",

View File

@@ -23,7 +23,7 @@ const program = new Command();
program
.name("owpenbot")
.version("0.1.3")
.version("0.1.5")
.description("OpenCode WhatsApp + Telegram bridge")
.argument("[path]")
.option("--non-interactive", "Run setup defaults and exit", false)
@@ -333,4 +333,7 @@ program
console.log("If replies fail, ensure OpenCode server is running at OPENCODE_URL.");
});
await program.parseAsync(process.argv);
program.parseAsync(process.argv).catch((error) => {
console.error(error);
process.exitCode = 1;
});

View File

@@ -98,6 +98,13 @@ export function createWhatsAppAdapter(
| { error?: { output?: { statusCode?: number } } }
| undefined;
const statusCode = lastDisconnect?.error?.output?.statusCode;
if (statusCode === 515 && !stopped) {
log.warn("whatsapp stream error; restarting connection");
setTimeout(() => {
void connect();
}, 1000);
return;
}
const shouldReconnect = statusCode !== DisconnectReason.loggedOut;
if (shouldReconnect && !stopped) {
log.warn("whatsapp connection closed, reconnecting");