Comando JSON

case 'uploadapi':
reagir(from, "๐Ÿ’พ")
try {//By: ๐–ง„ ๐‹๐”๐‚๐€๐’ ๐Œ๐Ž๐ƒ ๐ƒ๐Ž๐Œ๐ˆ๐๐€ ๐–ง„
let media, type, mimetype
if (isQuotedSticker || (info.message.stickerMessage && info.message.stickerMessage.mimetype === 'image/webp')) {
media = isQuotedSticker ? info.message.extendedTextMessage.contextInfo.quotedMessage.stickerMessage : info.message.stickerMessage
mimetype = 'image/webp'
type = 'sticker'
} else if (isQuotedImage || isImage) {
media = isQuotedImage ? info.message.extendedTextMessage.contextInfo.quotedMessage.imageMessage : info.message.imageMessage
mimetype = media.mimetype
type = 'image'
} else if (isQuotedVideo || isVideo) {
media = isQuotedVideo ? info.message.extendedTextMessage.contextInfo.quotedMessage.videoMessage : info.message.videoMessage
mimetype = media.mimetype
type = 'video'
} else if (isQuotedAudio || isAudio) {
media = isQuotedAudio ? info.message.extendedTextMessage.contextInfo.quotedMessage.audioMessage : info.message.audioMessage
mimetype = media.mimetype
type = 'audio'
} else if (isQuotedDocument || isDocument) {
media = isQuotedDocument ? info.message.extendedTextMessage.contextInfo.quotedMessage.documentMessage : info.message.documentMessage
mimetype = media.mimetype
type = mimetype.split('/')[0]
} else {
return reply('โŒ Marque uma Imagem, Vรญdeo, รudio, Sticker ou Documento.')
}
const ext = mimetype.split('/').pop()
const validExtensions = { mpeg: 'mp3', m4a: 'mp3' }
const finalExt = validExtensions[ext] || ext
const tempFile = `temp_${Date.now()}.${finalExt}`
const fileBuffer = await getFileBuffer(media, type)
fs.writeFileSync(tempFile, fileBuffer)
console.log(`๐ŸŸข Enviando arquivo para a API: ${tempFile}`)
const FormData = require('form-data')
const form = new FormData()
form.append('file', fs.createReadStream(tempFile))
const response = await axios.post('https://zero-two.info/upload', form, {
headers: { ...form.getHeaders() }
})
if (!response || !response.data || !response.data.fileUrl) {
throw new Error('โŒ Sem resposta vรกlida da API de upload.')
}
const fileUrl = response.data.fileUrl
const fileExtension = fileUrl.split('.').pop()
if (fileExtension === 'webp' && type === 'sticker') {
reply(`๐Ÿ–ผ๏ธ ร‰ uma figurinha.\n\n๐Ÿ”— *LINK:* ${fileUrl}`)
zerotwo.sendMessage(from, { sticker: fileBuffer }, { quoted: info })
} else if (['jpg', 'jpeg', 'png', 'gif'].includes(fileExtension)) {
reply('๐Ÿ–ผ๏ธ ร‰ uma imagem.')
zerotwo.sendMessage(from, { image: fileBuffer, caption: `๐Ÿ”— *LINK:* ${fileUrl}` }, { quoted: info })
} else if (['mp4'].includes(fileExtension)) {
reply('๐ŸŽฅ ร‰ um vรญdeo.')
zerotwo.sendMessage(from, { video: fileBuffer, caption: `๐Ÿ”— *LINK:* ${fileUrl}` }, { quoted: info })
} else if (['mp3', 'wav'].includes(fileExtension)) {
reply(`๐ŸŽต ร‰ um รกudio.\n\n๐Ÿ”— *LINK:* ${fileUrl}`)
zerotwo.sendMessage(from, { audio: { url: fileUrl }, mimetype: "audio/mpeg", ptt: true }, { quoted: info })
} else {
reply('๐Ÿ“„ ร‰ um documento.')
zerotwo.sendMessage(from, { document: fileBuffer, caption: `๐Ÿ”— *LINK:* ${fileUrl}`, mimetype, fileName: `arquivo.${fileExtension}` }, { quoted: info })
}
console.log(`๐ŸŸข Arquivo enviado com sucesso: ${fileUrl}`)
fs.unlinkSync(tempFile)
} catch (error) {
console.error('โŒ Erro no upload:', error)
reply('โŒ Ocorreu um erro durante o upload.')
}
break
> Loading... > Processing... > Completed... > Error... > Done...