feat: add send file function
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type {
|
||||
GetMessagesParams,
|
||||
ListChatsParams,
|
||||
SendFileParams,
|
||||
SendTextParams,
|
||||
} from "../shared/protocol";
|
||||
import type {
|
||||
@@ -158,6 +159,10 @@ export class WhatsAppClient {
|
||||
return this.request<any>("sendText", params);
|
||||
}
|
||||
|
||||
sendFile(params: SendFileParams) {
|
||||
return this.request<any>("sendFile", params);
|
||||
}
|
||||
|
||||
getMedia(msgId: string) {
|
||||
return this.request<string>("getMedia", msgId);
|
||||
}
|
||||
|
||||
@@ -214,6 +214,7 @@ wss.on("connection", (ws) => {
|
||||
case "listGroups":
|
||||
case "getMessages":
|
||||
case "sendText":
|
||||
case "sendFile":
|
||||
case "getMedia":
|
||||
case "exec":
|
||||
result = await call(wa, request.method, request.params);
|
||||
|
||||
+17
-6
@@ -40,16 +40,26 @@ export interface GetMessagesParams {
|
||||
id?: string;
|
||||
}
|
||||
|
||||
export interface SendTextOptions {
|
||||
delay?: number;
|
||||
quotedMsg?: string;
|
||||
mentionedList?: string[];
|
||||
waitForAck?: boolean;
|
||||
caption?: string;
|
||||
filename?: string;
|
||||
mimetype?: string;
|
||||
}
|
||||
|
||||
export interface SendTextParams {
|
||||
chatId: string;
|
||||
text: string;
|
||||
options?: SendTextOptions;
|
||||
}
|
||||
|
||||
options?: {
|
||||
delay?: number;
|
||||
quotedMsg?: string;
|
||||
mentionedList?: string[];
|
||||
waitForAck?: boolean;
|
||||
};
|
||||
export interface SendFileParams {
|
||||
chatId: string;
|
||||
data: string;
|
||||
options?: SendTextOptions;
|
||||
}
|
||||
|
||||
export interface GetContactsParams {
|
||||
@@ -64,5 +74,6 @@ export type BridgeRequest =
|
||||
| RpcRequest<"listGroups">
|
||||
| RpcRequest<"getMessages", GetMessagesParams>
|
||||
| RpcRequest<"sendText", SendTextParams>
|
||||
| RpcRequest<"sendFile", SendFileParams>
|
||||
| RpcRequest<"getMedia", string>
|
||||
| RpcRequest<"exec", string>;
|
||||
|
||||
+11
-6
@@ -110,12 +110,17 @@ async function handleRequest(request: BridgeRequest) {
|
||||
const result = await WPP.chat.sendTextMessage(
|
||||
request.params.chatId,
|
||||
request.params.text,
|
||||
{
|
||||
delay: request.params.options?.delay,
|
||||
quotedMsg: request.params.options?.quotedMsg,
|
||||
mentionedList: request.params.options?.mentionedList,
|
||||
waitForAck: request.params.options?.waitForAck,
|
||||
},
|
||||
request.params.options,
|
||||
);
|
||||
|
||||
return serialize(result);
|
||||
}
|
||||
|
||||
case "sendFile": {
|
||||
const result = await WPP.chat.sendFileMessage(
|
||||
request.params.chatId,
|
||||
request.params.data,
|
||||
request.params.options,
|
||||
);
|
||||
|
||||
return serialize(result);
|
||||
|
||||
Vendored
+22
-10
@@ -1,5 +1,20 @@
|
||||
declare const __WS_URL__: string;
|
||||
|
||||
type SendMessageOptions = {
|
||||
delay?: number;
|
||||
detectMentioned?: boolean;
|
||||
markIsRead?: boolean;
|
||||
mentionedList?: string[];
|
||||
messageId?: string;
|
||||
quotedMsg?: string;
|
||||
quotedMsgPayload?: string;
|
||||
waitForAck?: boolean;
|
||||
isViewOnce?: boolean;
|
||||
filename?: string;
|
||||
mimetype?: string;
|
||||
type?: string;
|
||||
};
|
||||
|
||||
declare const WPP: {
|
||||
isReady: boolean;
|
||||
|
||||
@@ -38,16 +53,13 @@ declare const WPP: {
|
||||
sendTextMessage(
|
||||
chatId: string,
|
||||
text: string,
|
||||
options?: {
|
||||
delay?: number;
|
||||
detectMentioned?: boolean;
|
||||
markIsRead?: boolean;
|
||||
mentionedList?: string[];
|
||||
messageId?: string;
|
||||
quotedMsg?: string;
|
||||
quotedMsgPayload?: string;
|
||||
waitForAck?: boolean;
|
||||
},
|
||||
options?: SendMessageOptions,
|
||||
): Promise<any>;
|
||||
|
||||
sendFileMessage(
|
||||
chatId: string,
|
||||
data: string,
|
||||
options?: SendMessageOptions,
|
||||
): Promise<any>;
|
||||
|
||||
downloadMedia(msgId: string): Promise<Blob>;
|
||||
|
||||
Reference in New Issue
Block a user