Download Media
Download and Save Media
Download and save any message file with the functions below
javascript
let client = await superchats.create({
session: "Marketing",
license: "asjdh-efddff734-sdsdf834-233272",
statusFind: async (status) => {
console.log(status)
},
qrcode: async (session, base64Img, asciiQR, urlCode) => {
console.log(asciiQR)
},
onAnyMessage: async (message) => {
if (message.isMedia === true) {
const options = {
msgId?: "3EB01A690E67", // message id
content?: `{
"session": "1",
"device": "556183602797",
"status": 200,
"type": "image",
"fromMe": true,
"id": "KIZAKIXD7D1C224EA9F6",
"remoteJid": "556191922853@s.whatsapp.net",
"isMedia": true,
"to": "556191922853",
"isgroup": false,
"content": {
"imageMessage": {
"url": "https://mmg.whatsapp.net/o1/v/t62.7118-24/f1/m232/up-oil-image-4b89a91d-c5e2-4c4f-a6ec-4d30dcbbdd42?ccb=9-4&oh=01_Q5AaILAA4Omb5nAJp6zM6jMcca0tVhNYkSQ50f1Cwh4IaGoM&oe=6701F614&_nc_sid=000000&mms3=true",
"mimetype": "image/jpeg",
"caption": "Teste pela API ",
"fileSha256": "sONhQzEGrrK5w6Z+ZCxtQqQEiDue0p+liU8OAAt4E6E=",
"fileLength": "100105",
"height": 350,
"width": 745,
"mediaKey": "KbjGVep2neDWOi9+Xv/Zagy1TKzQSPGTR+cCOAYgUk0=",
"fileEncSha256": "d4yLIi69bE2eIaGv4ok+HyA98jgCz338FPk68LXcfB8=",
"directPath": "/o1/v/t62.7118-24/f1/m232/up-oil-image-4b89a91d-c5e2-4c4f-a6ec-4d30dcbbdd42?ccb=9-4&oh=01_Q5AaILAA4Omb5nAJp6zM6jMcca0tVhNYkSQ50f1Cwh4IaGoM&oe=6701F614&_nc_sid=000000",
"mediaKeyTimestamp": "1725596061",
"jpegThumbnail": "/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wAARCAAPACADASIAAhEBAxEB/8QAFgABAQEAAAAAAAAAAAAAAAAABQQG/8QAKRAAAgIBAgQEBwAAAAAAAAAAAQIDBBEABRITIVEGMUHRFCJhcXKBkf/EABUBAQEAAAAAAAAAAAAAAAAAAAAC/8QAFhEBAQEAAAAAAAAAAAAAAAAAAAFB/9oADAMBAAIRAxEAPwBLb2jlmlDQJJF6O7cKhu2e57anvXXo2QJ9pg5LHAXl56d+L166L8P2zZriuoL2YEdxkeRMqdRn6Z0nckN3clXbq80r13cZMioikuT5H20EG67hakqnk1fhqzDi5a9Cfy9saOg221agBs8iqhb5XkXDN9sdTrVvV3+VQJJKqoRhlUcR/p1Lf2OxZhUQwLFInTJk6N+vLRVsyP/Z"
}
},
"participant": "",
"timestamp": 1725596061
}`, // return the message you want to reply to in place of the reply parameter
mongoUrl?: 'mongodb://localhost:27017' // mongo url case use Mongo in driveStorage
};
// Retrieve the file buffer for a given message
// decryption is performed at the same level as (create) of superchats, outside of connection functions
const buffer = await superchats.decrypt(session, options); // mongoUrl is optional if you are using mongo for history
const options = {
msgId?: "3EB01A690E67", // message id
filename?: './directory/filename', // filename with folder for save media
content?: `{
"session": "1",
"device": "556183602797",
"status": 200,
"type": "image",
"fromMe": true,
"id": "KIZAKIXD7D1C224EA9F6",
"remoteJid": "556191922853@s.whatsapp.net",
"isMedia": true,
"to": "556191922853",
"isgroup": false,
"content": {
"imageMessage": {
"url": "https://mmg.whatsapp.net/o1/v/t62.7118-24/f1/m232/up-oil-image-4b89a91d-c5e2-4c4f-a6ec-4d30dcbbdd42?ccb=9-4&oh=01_Q5AaILAA4Omb5nAJp6zM6jMcca0tVhNYkSQ50f1Cwh4IaGoM&oe=6701F614&_nc_sid=000000&mms3=true",
"mimetype": "image/jpeg",
"caption": "Teste pela API ",
"fileSha256": "sONhQzEGrrK5w6Z+ZCxtQqQEiDue0p+liU8OAAt4E6E=",
"fileLength": "100105",
"height": 350,
"width": 745,
"mediaKey": "KbjGVep2neDWOi9+Xv/Zagy1TKzQSPGTR+cCOAYgUk0=",
"fileEncSha256": "d4yLIi69bE2eIaGv4ok+HyA98jgCz338FPk68LXcfB8=",
"directPath": "/o1/v/t62.7118-24/f1/m232/up-oil-image-4b89a91d-c5e2-4c4f-a6ec-4d30dcbbdd42?ccb=9-4&oh=01_Q5AaILAA4Omb5nAJp6zM6jMcca0tVhNYkSQ50f1Cwh4IaGoM&oe=6701F614&_nc_sid=000000",
"mediaKeyTimestamp": "1725596061",
"jpegThumbnail": "/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wAARCAAPACADASIAAhEBAxEB/8QAFgABAQEAAAAAAAAAAAAAAAAABQQG/8QAKRAAAgIBAgQEBwAAAAAAAAAAAQIDBBEABRITIVEGMUHRFCJhcXKBkf/EABUBAQEAAAAAAAAAAAAAAAAAAAAC/8QAFhEBAQEAAAAAAAAAAAAAAAAAAAFB/9oADAMBAAIRAxEAPwBLb2jlmlDQJJF6O7cKhu2e57anvXXo2QJ9pg5LHAXl56d+L166L8P2zZriuoL2YEdxkeRMqdRn6Z0nckN3clXbq80r13cZMioikuT5H20EG67hakqnk1fhqzDi5a9Cfy9saOg221agBs8iqhb5XkXDN9sdTrVvV3+VQJJKqoRhlUcR/p1Lf2OxZhUQwLFInTJk6N+vLRVsyP/Z"
}
},
"participant": "",
"timestamp": 1725596061
}`, // return the message you want to reply to in place of the reply parameter
mongoUrl?: 'mongodb://localhost:27017' // mongo url case use Mongo in driveStorage
};
// Save the message file in the project root or in a directory: './directory/filename' don't forget to create the directory
// decryption is performed at the same level as (create) of superchats, outside of connection functions
const saveFile = await superchats.decryptSave(session, options); // mongoUrl is optional if you are using mongo for history
}
} // Receive an event whenever you receive a message from a contact
})
Return from decryptFile
javascript
{
session: 'Marketing',
status: 200,
type: "decrypt",
mime: "image/jpeg",
ext: "jpeg",
buffer: {
type: "Buffer",
data: [137,80,78,71,13,10,26,10,0,0,0,13,73,72,68]
}
}
Return from decryptFileSave
javascript
{
session: 'Marketing',
status: 200,
type: "decrypt-save",
mime: "image/jpeg",
ext: "jpeg",
response: "./files/teste4.jpeg"
}