Home > Net >  How do I give a name file when send document using WhatsApp API?
How do I give a name file when send document using WhatsApp API?

Time:08-29

I tried to send a document file(pdf/docx/ppt etc.) through WhatsApp API. As per documentation this is my code:

$client = new Client();
    $headers = [
    'Authorization' => 'Bearer '.config('app.wa_token'),
    'Content-Type' => 'application/json'
    ];
    $body = '{
    "messaging_product": "whatsapp",
    "recipient_type": "individual",
    "to": "'.$receiver.'",
    "type": "document",
    "document": {
        "link": "'.$link_docx.'",
        "caption": "'.$filename.'"
    }
    }';

    $request = new Request('POST', 'https://graph.facebook.com/v13.0/'.$kod.'/messages', $headers, $body);
    $res = $client->sendAsync($request)->wait();
    return $res->getBody();

but in the receiver, the document I received showed like this

received document

and when I receive it in my phone the name is null.pdf

how do I send a document with the original name?

CodePudding user response:

document object can have an optional filename, that is later shown to the recipient. Make sure you provide a name with file extension, so that the file is displayed correctly to the recipient.

Check here for details.

  • Related