Merge c988970064 into 4583f88626
This commit is contained in:
commit
19eea57de5
@ -5,6 +5,7 @@ import { DEFAULT_ACCOUNT_ID } from "../routing/session-key.js";
|
||||
export type ActiveWebSendOptions = {
|
||||
gifPlayback?: boolean;
|
||||
accountId?: string;
|
||||
fileName?: string;
|
||||
};
|
||||
|
||||
export type ActiveWebListener = {
|
||||
|
||||
@ -38,9 +38,10 @@ export function createWebSendApi(params: {
|
||||
...(gifPlayback ? { gifPlayback: true } : {}),
|
||||
};
|
||||
} else {
|
||||
const fileName = sendOptions?.fileName?.trim() || "file";
|
||||
payload = {
|
||||
document: mediaBuffer,
|
||||
fileName: "file",
|
||||
fileName,
|
||||
caption: text || undefined,
|
||||
mimetype: mediaType,
|
||||
};
|
||||
|
||||
@ -131,7 +131,9 @@ describe("web outbound", () => {
|
||||
verbose: false,
|
||||
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 () => {
|
||||
|
||||
@ -44,11 +44,13 @@ export async function sendMessageWhatsApp(
|
||||
const jid = toWhatsappJid(to);
|
||||
let mediaBuffer: Buffer | undefined;
|
||||
let mediaType: string | undefined;
|
||||
let mediaFileName: string | undefined;
|
||||
if (options.mediaUrl) {
|
||||
const media = await loadWebMedia(options.mediaUrl);
|
||||
const caption = text || undefined;
|
||||
mediaBuffer = media.buffer;
|
||||
mediaType = media.contentType;
|
||||
mediaFileName = media.fileName;
|
||||
if (media.kind === "audio") {
|
||||
// WhatsApp expects explicit opus codec for PTT voice notes.
|
||||
mediaType =
|
||||
@ -69,10 +71,11 @@ export async function sendMessageWhatsApp(
|
||||
const hasExplicitAccountId = Boolean(options.accountId?.trim());
|
||||
const accountId = hasExplicitAccountId ? resolvedAccountId : undefined;
|
||||
const sendOptions: ActiveWebSendOptions | undefined =
|
||||
options.gifPlayback || accountId
|
||||
options.gifPlayback || accountId || mediaFileName
|
||||
? {
|
||||
...(options.gifPlayback ? { gifPlayback: true } : {}),
|
||||
accountId,
|
||||
...(accountId ? { accountId } : {}),
|
||||
...(mediaFileName ? { fileName: mediaFileName } : {}),
|
||||
}
|
||||
: undefined;
|
||||
const result = sendOptions
|
||||
|
||||
Loading…
Reference in New Issue
Block a user