Repository navigation
fix(whatsapp): combine sender number and literal formatting fixes - #1039
Merged
Merged
Conversation
…1007) Carried over from #1007 by @armancharan. Co-authored-by: Arman Charan <armancharan@armancharan.com>
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Outbound calls decode the thread ID once and require a numeric phone number ID before building a Graph API path from it. A thread ID that doesn't decode, or whose phone number ID contains anything other than digits, throws a ValidationError before any request is made. The decoded thread is passed to the send, media, and recipient helpers so each call resolves its sender once. The protected helpers also accept the recipient string they took before, and uploadMedia and resolveMedia default to the configured phone number ID, so existing subclasses keep working. Tests cover reactions, typing indicators, templates, interactive and media sends, and media uploads on a second phone number, plus thread IDs with non-numeric phone number IDs. Signed-off-by: Ben Sabic <bensabic@users.noreply.github.com>
WhatsApp has no escape syntax, so outgoing text is sent as written except where it would turn into WhatsApp formatting. A backslash is kept before a marker that forms a pair on one line, such as \_word\_, before a marker that touches a formatting marker, and before a quote, bullet, or numbered-list marker at the start of a line. Italic is rendered by its own handler, so intraword or space-padded emphasis no longer produces HTML character references. Hard breaks are sent as plain newlines. The bold, italic, strikethrough, text, and break handlers are defined once at module level. The nested formatting test counts handler calls instead of measuring elapsed time. The handlers option on stringifyMarkdown is documented, and the chat changeset is a minor release because the option is new public API. Signed-off-by: Ben Sabic <bensabic@users.noreply.github.com>
bensabic
marked this pull request as ready for review
October 19, 2026 02:21
bensabic
approved these changes
Oct 19, 2026
This was referenced Oct 19, 2026
3 of 5 tasks
5 tasks done
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This combines two WhatsApp adapter fixes so they can be reviewed and merged together: #1007 from @armancharan, which sends replies from the number that received the thread, and #909 from @luksch42, which keeps literal text intact when converting Markdown to WhatsApp formatting. Each lands as its own commit with a
Co-authored-bytrailer, and two follow-up commits build on them. It supersedes #1007 and #909, which can be closed once this merges.Fixes #988, fixes #908.
A bot connected to more than one WhatsApp number used to reply, react, mark messages read, show typing indicators, and upload media from the configured
phoneNumberId, even when the conversation came in on a different number. Outbound calls now use the phone number ID encoded in the thread ID. Because that ID becomes part of the Graph API path, it has to be numeric: a thread ID that doesn't decode, or whose phone number ID contains anything other than digits, throws aValidationErrorbefore any request is made. Each call decodes the thread once and passes it down to the send helpers. The protected helpers still accept the recipient string they took before, anduploadMediaandresolveMediastill default to the configured number, so existing subclasses keep working.openDMand the single-argumentmarkAsRead(messageId)keep using the configured number, since neither has an inbound thread to read from.On the formatting side, text such as
(~80 % easy),C:\Users\Luis, orsnake_case_nameused to pick up visible Markdown escapes in WhatsApp. WhatsApp has no escape syntax, so the converter now sends text as written and keeps a backslash only where the text would otherwise turn into formatting: a marker that forms a pair on one line, such as\_word\_, a marker touching a formatting marker, and a quote, bullet, or numbered-list marker at the start of a line. This meansLiteral \*\*stars\*\*now comes out escaped rather than asLiteral **stars**, which reverses one assertion from #909. Bold, italic, and strikethrough are rendered from their AST nodes, so markers inside inline and fenced code stay unchanged, intraword italics no longer produce HTML character references liken, and hard breaks are sent as plain newlines.To support this,
stringifyMarkdowninchatgains ahandlersoption for platform-specific serialization, which is whychatgets a minor changeset:A few edge cases remain. A marker pair split across formatting, such as
~5 **x** 6~, isn't detected. Intraword*emphasis*like2*3*4comes out as2_3_4. Autolinks are still wrapped in<...>, as they are onmain.pnpm validatepasses on the branch. The two carried-over commits from roboeve[bot] don't have a DCO sign-off yet; the follow-up commits do. I haven't sent messages through a live WhatsApp number.