WhatsApp: preserve document filenames
This commit is contained in:
parent
a989fe8af9
commit
c988970064
@ -5,6 +5,7 @@ import { DEFAULT_ACCOUNT_ID } from "../routing/session-key.js";
|
|||||||
export type ActiveWebSendOptions = {
|
export type ActiveWebSendOptions = {
|
||||||
gifPlayback?: boolean;
|
gifPlayback?: boolean;
|
||||||
accountId?: string;
|
accountId?: string;
|
||||||
|
fileName?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ActiveWebListener = {
|
export type ActiveWebListener = {
|
||||||
|
|||||||
@ -38,9 +38,10 @@ export function createWebSendApi(params: {
|
|||||||
...(gifPlayback ? { gifPlayback: true } : {}),
|
...(gifPlayback ? { gifPlayback: true } : {}),
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
const fileName = sendOptions?.fileName?.trim() || "file";
|
||||||
payload = {
|
payload = {
|
||||||
document: mediaBuffer,
|
document: mediaBuffer,
|
||||||
fileName: "file",
|
fileName,
|
||||||
caption: text || undefined,
|
caption: text || undefined,
|
||||||
mimetype: mediaType,
|
mimetype: mediaType,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -131,7 +131,9 @@ describe("web outbound", () => {
|
|||||||
verbose: false,
|
verbose: false,
|
||||||
mediaUrl: "/tmp/file.pdf",
|
mediaUrl: "/tmp/file.pdf",
|
||||||
});
|
});
|
||||||
expect(sendMessage).toHaveBeenLastCalledWith("+1555", "doc", buf, "application/pdf");
|
expect(sendMessage).toHaveBeenLastCalledWith("+1555", "doc", buf, "application/pdf", {
|
||||||
|
fileName: "file.pdf",
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("sends polls via active listener", async () => {
|
it("sends polls via active listener", async () => {
|
||||||
|
|||||||
@ -44,11 +44,13 @@ export async function sendMessageWhatsApp(
|
|||||||
const jid = toWhatsappJid(to);
|
const jid = toWhatsappJid(to);
|
||||||
let mediaBuffer: Buffer | undefined;
|
let mediaBuffer: Buffer | undefined;
|
||||||
let mediaType: string | undefined;
|
let mediaType: string | undefined;
|
||||||
|
let mediaFileName: string | undefined;
|
||||||
if (options.mediaUrl) {
|
if (options.mediaUrl) {
|
||||||
const media = await loadWebMedia(options.mediaUrl);
|
const media = await loadWebMedia(options.mediaUrl);
|
||||||
const caption = text || undefined;
|
const caption = text || undefined;
|
||||||
mediaBuffer = media.buffer;
|
mediaBuffer = media.buffer;
|
||||||
mediaType = media.contentType;
|
mediaType = media.contentType;
|
||||||
|
mediaFileName = media.fileName;
|
||||||
if (media.kind === "audio") {
|
if (media.kind === "audio") {
|
||||||
// WhatsApp expects explicit opus codec for PTT voice notes.
|
// WhatsApp expects explicit opus codec for PTT voice notes.
|
||||||
mediaType =
|
mediaType =
|
||||||
@ -69,10 +71,11 @@ export async function sendMessageWhatsApp(
|
|||||||
const hasExplicitAccountId = Boolean(options.accountId?.trim());
|
const hasExplicitAccountId = Boolean(options.accountId?.trim());
|
||||||
const accountId = hasExplicitAccountId ? resolvedAccountId : undefined;
|
const accountId = hasExplicitAccountId ? resolvedAccountId : undefined;
|
||||||
const sendOptions: ActiveWebSendOptions | undefined =
|
const sendOptions: ActiveWebSendOptions | undefined =
|
||||||
options.gifPlayback || accountId
|
options.gifPlayback || accountId || mediaFileName
|
||||||
? {
|
? {
|
||||||
...(options.gifPlayback ? { gifPlayback: true } : {}),
|
...(options.gifPlayback ? { gifPlayback: true } : {}),
|
||||||
accountId,
|
...(accountId ? { accountId } : {}),
|
||||||
|
...(mediaFileName ? { fileName: mediaFileName } : {}),
|
||||||
}
|
}
|
||||||
: undefined;
|
: undefined;
|
||||||
const result = sendOptions
|
const result = sendOptions
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user