mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-22 14:41:34 +00:00
fix: guard mediaType fallback, add missing MIME + send-api tests, changelog
This commit is contained in:
@@ -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" });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user