vercel / vercel/chat

WhatsApp adapter adds visible backslashes before literal tildes

Open
#908 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
2.4k
Forks
314
Avg merge
1d 18h
Merged PRs (30d)
63

Description

Bug Description

In @chat-adapter/whatsapp@4.39.0, outgoing Markdown containing a literal tilde gets an extra backslash. For example, (~80 % easy) is delivered as (\~80 % easy), with the backslash visible in WhatsApp.

The original model output contains no backslash. This reproduces directly in the adapter’s formatter without an LLM or network request.

Steps to Reproduce
  1. Use @chat-adapter/whatsapp@4.39.0 with chat@4.37.0 (our project pins chat via an override).
  2. Run the minimal code sample below with Bun.
  3. Observe that the formatter returns (\~80 % easy) instead of (~80 % easy).
  4. Sending { markdown: "(~80 % easy)" } uses the same converter and includes the unwanted backslash in the outgoing message.
Expected Behavior

The formatter should return (~80 % easy) unchanged. Literal text should arrive without serializer-added Markdown escapes, while supported formatting still converts to WhatsApp syntax. Intentional backslashes and code content should remain intact.

Actual Behavior

The formatter returns (\~80 % easy). The added backslash remains visible in the delivered WhatsApp message.

This also affects multiple tildes: ~45 min, Pace ~6:29/km becomes \~45 min, Pace \~6:29/km.

Code Sample
import { WhatsAppAdapter } from "@chat-adapter/whatsapp";
import { ConsoleLogger, parseMarkdown } from "chat";

const adapter = new WhatsAppAdapter({
  accessToken: "test",
  appSecret: "test",
  phoneNumberId: "test",
  verifyToken: "test",
  userName: "test",
  logger: new ConsoleLogger("silent"),
});

console.log(adapter.renderFormatted(parseMarkdown("(~80 % easy)")));
// Expected: (~80 % easy)
// Actual:   (\~80 % easy)
Chat SDK Version

chat@4.37.0; @chat-adapter/whatsapp@4.39.0

Node.js Version

Not used for reproduction — Bun 1.4.0

Platform Adapter

WhatsApp

Operating System

macOS

Additional Context

The issue appears to originate in packages/adapter-whatsapp/src/markdown.ts:

  1. WhatsAppFormatConverter.fromAst() calls the shared stringifyMarkdown() helper.
  2. That helper uses remark-stringify with remark-gfm. Its strikethrough serializer escapes literal ~ characters.
  3. toWhatsAppFormat() converts bold and strikethrough markers but leaves the Markdown escapes intact.

The whole-string regex conversions also modify formatting markers inside code: **literal** in a fenced code block becomes *literal*.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with packages/adapter-whatsapp/src/markdown.ts, tracing WhatsAppFormatConverter.fromAst() through stringifyMarkdown() and toWhatsAppFormat(). Run the minimal Bun reproduction from the issue, then verify that literal tildes are unchanged while supported formatting, intentional backslashes, and code content remain intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
markdown, typescript
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.