Skip to main content
Glama

waha_send_media

Send media files like images, videos, or documents to WhatsApp chats using URL or base64 data. Specify chat ID, media type, and MIME type to deliver files with optional captions or replies.

Instructions

Send media files (images, videos, or documents) to a WhatsApp chat. Supports URL or base64 data.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chatIdYesChat ID (format: number@c.us)
mediaTypeYesType of media to send
fileUrlNoURL of the file to send (use either fileUrl or fileData, not both)
fileDataNoBase64 encoded file data (use either fileUrl or fileData, not both)
mimetypeYesMIME type of the file (e.g., 'image/jpeg', 'video/mp4', 'application/pdf')
filenameNoOptional filename for the media
captionNoOptional caption for the media
replyToNoOptional message ID to reply to

Implementation Reference

  • Executes the waha_send_media tool: validates input, constructs file object from URL or base64 data, calls WAHAClient.sendMedia, formats success response with media details.
    private async handleSendMedia(args: any) { const chatId = args.chatId; const mediaType = args.mediaType; const fileUrl = args.fileUrl; const fileData = args.fileData; const mimetype = args.mimetype; const filename = args.filename; const caption = args.caption; const replyTo = args.replyTo; if (!chatId) { throw new Error("chatId is required"); } if (!mediaType) { throw new Error("mediaType is required"); } if (!mimetype) { throw new Error("mimetype is required"); } if (!fileUrl && !fileData) { throw new Error("Either fileUrl or fileData is required"); } const file: any = { mimetype, filename, }; if (fileUrl) { file.url = fileUrl; } else { file.data = fileData; } const response = await this.wahaClient.sendMedia({ chatId, file, mediaType, caption, reply_to: replyTo, }); const formattedResponse = formatSendMessageSuccess( chatId, response.id, response.timestamp ); return { content: [ { type: "text", text: `${formattedResponse}\nMedia type: ${mediaType}${caption ? `\nCaption: ${caption}` : ''}`, }, ], }; }
  • Tool schema definition including input schema with properties for chatId, mediaType, fileUrl/fileData, mimetype, and optional fields; defines required parameters.
    name: "waha_send_media", description: "Send media files (images, videos, or documents) to a WhatsApp chat. Supports URL or base64 data.", inputSchema: { type: "object", properties: { chatId: { type: "string", description: "Chat ID (format: number@c.us)", }, mediaType: { type: "string", enum: ["image", "video", "document"], description: "Type of media to send", }, fileUrl: { type: "string", description: "URL of the file to send (use either fileUrl or fileData, not both)", }, fileData: { type: "string", description: "Base64 encoded file data (use either fileUrl or fileData, not both)", }, mimetype: { type: "string", description: "MIME type of the file (e.g., 'image/jpeg', 'video/mp4', 'application/pdf')", }, filename: { type: "string", description: "Optional filename for the media", }, caption: { type: "string", description: "Optional caption for the media", }, replyTo: { type: "string", description: "Optional message ID to reply to", }, }, required: ["chatId", "mediaType", "mimetype"], }, },
  • src/index.ts:1079-1081 (registration)
    MCP tool dispatch registration: routes CallToolRequest for 'waha_send_media' to the handleSendMedia method.
    case "waha_send_media": return await this.handleSendMedia(args); case "waha_send_audio":
  • Underlying WAHAClient helper method that makes HTTP POST to appropriate WAHA API endpoint (/api/sendImage|Video|File) based on mediaType.
    async sendMedia(params: { chatId: string; file: { mimetype: string; url?: string; data?: string; // base64 filename?: string; }; mediaType: "image" | "video" | "document"; caption?: string; reply_to?: string; }): Promise<SendMessageResponse> { const { chatId, file, mediaType, caption, reply_to } = params; if (!chatId) { throw new WAHAError("chatId is required"); } if (!file || (!file.url && !file.data)) { throw new WAHAError("file with url or data is required"); } const endpointMap = { image: "/api/sendImage", video: "/api/sendVideo", document: "/api/sendFile", }; const body = { chatId, file, session: this.session, caption, reply_to, }; return this.request<SendMessageResponse>(endpointMap[mediaType], { method: "POST", body: JSON.stringify(body), }); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/seejux/waha-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server