How to set filename parameter in WhatsApp Business API while sending document attachment?
I'm sending the PDF document to WhatsApp number, which is been successfully sent to the user but the title of the document is getting displayed as Untitled.
WhatsApp Business API version we are using is v2.21.6. I've referred to the documentation of WhatsApp Business API where it explains how one should send the document with ID or link. Documentation link https://developers.facebook.com/docs/whatsapp/api/messages/media
This is my file object to send the file to WhatsApp Number,
const fileDetails = { mime_type: 'application/pdf', id: uploadFile.media[0].id(media id), filename: fileName[3]( file name which we have to show) };
and below is helper function to send the message,
function getMessageByContentType(contentType, link, id = '', filename = '', caption = '') { const contentTypeMessageMapper = { audio: { type: 'audio', audio: { id, }, }, document: { type: 'document', document: { id, filename, caption, }, }, video: { type: 'video', video: { link, }, }, image: { type: 'image', image: { id, link, }, }, }; //Method to send document to user WhatsApp mobile number yield whatsAppMessage.sendWhatsappMediaMessageToUser( bot, userId, //Mobile number fileDetails //File object. ); //POST request { "method": "POST", "json": true, "headers": { "content-type": "application/json", "Authorization": "Auth Token" }, "body": { "type": "document", "document": { "id": "a0706671-4fe7-49b0-8d1b-bcfb2fc5f7e8", "filename": "fileName.pdf", "caption": "" }, "recipient_type": "individual", "to": "Mobile Number" }, "uri": "https://WhatsApp-Business-API-URL/v1/messages", "rejectUnauthorized": false }
After uploading binary file to WhatsApp Business API, we are using the ID to send the file to the customer which is getting uploaded successfully without any error message but the filename is coming as "Untitled" and not taking filename from the file object.