fix: guard mediaType fallback, add missing MIME + send-api tests, changelog

This commit is contained in:
Marcus Castro
2026-04-01 23:54:05 -03:00
parent a1eae4d7ac
commit 83f2eabd49
4 changed files with 25 additions and 1 deletions

View File

@@ -162,4 +162,24 @@ describe("createWebSendApi", () => {
await api.sendComposingTo("+1555");
expect(sendPresenceUpdate).toHaveBeenCalledWith("composing", "1555@s.whatsapp.net");
});
it("sends media as document when mediaType is undefined", async () => {
const mediaBuffer = Buffer.from("test");
await api.sendMessage("123", "hello", mediaBuffer, undefined);
expect(sendMessage).toHaveBeenCalledWith(
"123@s.whatsapp.net",
expect.objectContaining({
document: mediaBuffer,
mimetype: "application/octet-stream",
}),
);
});
it("does not set mediaType when mediaBuffer is absent", async () => {
await api.sendMessage("123", "hello");
expect(sendMessage).toHaveBeenCalledWith("123@s.whatsapp.net", { text: "hello" });
});
});

View File

@@ -34,7 +34,9 @@ export function createWebSendApi(params: {
): Promise<{ messageId: string }> => {
const jid = toWhatsappJid(to);
let payload: AnyMessageContent;
mediaType ??= "application/octet-stream";
if (mediaBuffer) {
mediaType ??= "application/octet-stream";
}
if (mediaBuffer && mediaType) {
if (mediaType.startsWith("image/")) {
payload = {