feat: add getMedia

This commit is contained in:
2026-09-16 05:07:21 +08:00
parent d673055210
commit 78faf2b070
7 changed files with 25 additions and 5 deletions
+4 -1
View File
@@ -2,7 +2,7 @@
// ==UserScript== // ==UserScript==
// @name WhatsApp Web Bridge // @name WhatsApp Web Bridge
// @namespace https://rul.sh/ // @namespace https://rul.sh/
// @version 0.0.4 // @version 0.0.5
// @description WhatsApp Web WebSocket bridge // @description WhatsApp Web WebSocket bridge
// @match https://web.whatsapp.com/* // @match https://web.whatsapp.com/*
// @updateURL https://git.rul.sh/khairul169/whatsapp-bridge/raw/branch/main/dist/whatsapp-bridge.user.js // @updateURL https://git.rul.sh/khairul169/whatsapp-bridge/raw/branch/main/dist/whatsapp-bridge.user.js
@@ -308,6 +308,9 @@
); );
return serialize(result); return serialize(result);
} }
case "getMedia":
const media = await WPP.chat.downloadMedia(request.params).then(WPP.util.blobToBase64);
return media;
default: default:
throw new Error(`Unknown method: ${request.method}`); throw new Error(`Unknown method: ${request.method}`);
} }
+2 -2
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -14,7 +14,7 @@ await esbuild.build({
// ==UserScript== // ==UserScript==
// @name WhatsApp Web Bridge // @name WhatsApp Web Bridge
// @namespace https://rul.sh/ // @namespace https://rul.sh/
// @version 0.0.4 // @version 0.0.5
// @description WhatsApp Web WebSocket bridge // @description WhatsApp Web WebSocket bridge
// @match https://web.whatsapp.com/* // @match https://web.whatsapp.com/*
// @updateURL https://git.rul.sh/khairul169/whatsapp-bridge/raw/branch/main/dist/whatsapp-bridge.user.js // @updateURL https://git.rul.sh/khairul169/whatsapp-bridge/raw/branch/main/dist/whatsapp-bridge.user.js
+4
View File
@@ -150,4 +150,8 @@ export class WhatsAppClient {
sendText(params: SendTextParams) { sendText(params: SendTextParams) {
return this.request<any>("sendText", params); return this.request<any>("sendText", params);
} }
getMedia(msgId: string) {
return this.request<string>("getMedia", msgId);
}
} }
+2 -1
View File
@@ -68,4 +68,5 @@ export type BridgeRequest =
| RpcRequest<"listGroups"> | RpcRequest<"listGroups">
| RpcRequest<"getMessages", GetMessagesParams> | RpcRequest<"getMessages", GetMessagesParams>
| RpcRequest<"searchMessages", SearchMessagesParams> | RpcRequest<"searchMessages", SearchMessagesParams>
| RpcRequest<"sendText", SendTextParams>; | RpcRequest<"sendText", SendTextParams>
| RpcRequest<"getMedia", string>;
+6
View File
@@ -108,6 +108,12 @@ async function handleRequest(request: BridgeRequest) {
return serialize(result); return serialize(result);
} }
case "getMedia":
const media = await WPP.chat
.downloadMedia(request.params)
.then(WPP.util.blobToBase64);
return media;
default: default:
throw new Error(`Unknown method: ${(request as any).method}`); throw new Error(`Unknown method: ${(request as any).method}`);
} }
+6
View File
@@ -48,6 +48,8 @@ declare const WPP: {
}, },
): Promise<any>; ): Promise<any>;
downloadMedia(msgId: string): Promise<Blob>;
on(event: string, callback: (...args: any[]) => void): void; on(event: string, callback: (...args: any[]) => void): void;
}; };
@@ -60,5 +62,9 @@ declare const WPP: {
getAllGroups(): Promise<any[]>; getAllGroups(): Promise<any[]>;
}; };
util: {
blobToBase64: (blob: Blob) => Promise<string>;
};
on(event: string, callback: (...args: any[]) => void): void; on(event: string, callback: (...args: any[]) => void): void;
}; };