fix(bot): pin Baileys to latest WA Web version + handle smart quotes
Two pairing-flow fixes after live test: - Connection Failure during pairing: Baileys announced a stale WhatsApp Web version that the server rejected before the QR was emitted. Pull the current version via fetchLatestBaileysVersion() at session start. - Telegram mobile auto-converts straight quotes to curly quotes, so labels like /pair "test 1" arrived as “test 1” and the curly quotes were never stripped. Extend the quote-stripping regex on /pair, /unpair, /groups.
This commit is contained in:
parent
33e1fcd2c4
commit
1e3173424a
@ -3,7 +3,10 @@ import { db } from "../../db.js";
|
||||
|
||||
export async function handleGroups(ctx: Context): Promise<void> {
|
||||
const text = ctx.message?.text ?? "";
|
||||
const label = text.replace(/^\/groups\s*/, "").trim().replace(/^["']|["']$/g, "");
|
||||
const label = text
|
||||
.replace(/^\/groups\s*/, "")
|
||||
.trim()
|
||||
.replace(/^["'“”‘’]|["'“”‘’]$/g, "");
|
||||
if (!label) {
|
||||
await ctx.reply('Usage: /groups "Account Label"');
|
||||
return;
|
||||
|
||||
@ -12,7 +12,10 @@ const qrMessageIdByAccount = new Map<string, number>();
|
||||
|
||||
export async function handlePair(ctx: Context): Promise<void> {
|
||||
const text = ctx.message?.text ?? "";
|
||||
const label = text.replace(/^\/pair\s*/, "").trim().replace(/^["']|["']$/g, "");
|
||||
const label = text
|
||||
.replace(/^\/pair\s*/, "")
|
||||
.trim()
|
||||
.replace(/^["'“”‘’]|["'“”‘’]$/g, "");
|
||||
if (!label) {
|
||||
await ctx.reply('Usage: /pair "Account Label"');
|
||||
return;
|
||||
|
||||
@ -10,7 +10,10 @@ import { writeAuditLog } from "../../audit.js";
|
||||
|
||||
export async function handleUnpair(ctx: Context): Promise<void> {
|
||||
const text = ctx.message?.text ?? "";
|
||||
const label = text.replace(/^\/unpair\s*/, "").trim().replace(/^["']|["']$/g, "");
|
||||
const label = text
|
||||
.replace(/^\/unpair\s*/, "")
|
||||
.trim()
|
||||
.replace(/^["'“”‘’]|["'“”‘’]$/g, "");
|
||||
if (!label) {
|
||||
await ctx.reply('Usage: /unpair "Account Label"');
|
||||
return;
|
||||
|
||||
@ -3,6 +3,7 @@ import { join } from "node:path";
|
||||
import {
|
||||
makeWASocket,
|
||||
useMultiFileAuthState,
|
||||
fetchLatestBaileysVersion,
|
||||
type WASocket,
|
||||
type ConnectionState,
|
||||
DisconnectReason,
|
||||
@ -34,9 +35,14 @@ export async function startSession(params: {
|
||||
|
||||
const { state, saveCreds } = await useMultiFileAuthState(sessionDir);
|
||||
|
||||
// Fetch the WhatsApp Web version Baileys should announce. Without this,
|
||||
// the noise handshake fails because WA's server-side rejects stale versions.
|
||||
const { version, isLatest } = await fetchLatestBaileysVersion();
|
||||
logger.info({ accountId, version, isLatest }, "session: using WA Web version");
|
||||
|
||||
const socket = makeWASocket({
|
||||
version,
|
||||
auth: state,
|
||||
printQRInTerminal: false,
|
||||
browser: Browsers.macOS("Safari"),
|
||||
syncFullHistory: false,
|
||||
logger: logger.child({ accountId, component: "baileys" }) as never,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user