Cannot sending message containing newline to whatsapp api

Viewed 30

I made a chat app that send message through Whatsapp API, but when I enter a new line an error occured

Error API

when i tried to dump the content of the message

newline

look like it has an extra quotation marks, because usually its like this

usual

i dont know why it automatically add an extra quotation marks nor do i know how to remove it before sending it,

and this is how i send it, normally its work

$client = new Client();
    $headers = [
    'Authorization' => 'Bearer '.config('app.wa_token'),
    'Content-Type' => 'application/json'
    ];
    $body = '{
        "messaging_product": "whatsapp",
        "preview_url": false,
        "recipient_type": "individual",
        "to": "'.$receiver.'",
        "type": "text",
        "text": {
          "body": "'.$pesan.'"
        }
      }';
    // dump($headers);
    // dd($body);
    $request = new Request('POST', 'https://graph.facebook.com/v13.0/19999999999999/messages', $headers, $body);
    $res = $client->sendAsync($request)->wait();
    return $res->getBody();
0 Answers
Related