Skip to content

feature(enhanced_media_support): added new options to override media filename #326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions src/controllers/clientController.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,47 +75,52 @@ const sendMessage = async (req, res) => {
case 'string':
if (options?.media) {
const media = options.media
media.filename = null
media.filesize = null
options.media = new MessageMedia(media.mimetype, media.data, media.filename, media.filesize)
media.filename = media.filename || null;
media.filesize = media.filesize || null;
options.media = new MessageMedia(media.mimetype, media.data, media.filename, media.filesize);
}
messageOut = await client.sendMessage(chatId, content, options)
break
break;
case 'MessageMediaFromURL': {
const messageMediaFromURL = await MessageMedia.fromUrl(content, { unsafeMime: true })
messageOut = await client.sendMessage(chatId, messageMediaFromURL, options)
break

if (options?.filename) {
messageMediaFromURL.filename = options?.filename;
}

messageOut = await client.sendMessage(chatId, messageMediaFromURL, options);
break;
}
case 'MessageMedia': {
const messageMedia = new MessageMedia(content.mimetype, content.data, content.filename, content.filesize)
messageOut = await client.sendMessage(chatId, messageMedia, options)
break
break;
}
case 'Location': {
const location = new Location(content.latitude, content.longitude, content.description)
messageOut = await client.sendMessage(chatId, location, options)
break
break;
}
case 'Buttons': {
const buttons = new Buttons(content.body, content.buttons, content.title, content.footer)
messageOut = await client.sendMessage(chatId, buttons, options)
break
break;
}
case 'List': {
const list = new List(content.body, content.buttonText, content.sections, content.title, content.footer)
messageOut = await client.sendMessage(chatId, list, options)
break
break;
}
case 'Contact': {
const contactId = content.contactId.endsWith('@c.us') ? content.contactId : `${content.contactId}@c.us`
const contact = await client.getContactById(contactId)
messageOut = await client.sendMessage(chatId, contact, options)
break
break;
}
case 'Poll': {
const poll = new Poll(content.pollName, content.pollOptions, content.options)
messageOut = await client.sendMessage(chatId, poll, options)
break
break;
}
default:
return sendErrorResponse(res, 404, 'contentType invalid, must be string, MessageMedia, MessageMediaFromURL, Location, Buttons, List, Contact or Poll')
Expand Down