eristemena / dialogflow-fulfillment-webhook-php

Dialogflow agent fulfillment PHP library supporting v1 & v2
MIT License
104 stars 47 forks source link

Simple text message formatting #23

Open jonaths opened 5 years ago

jonaths commented 5 years ago

Hi. Documentation here: https://developers.google.com/actions/assistant/responses#basic_card, says that it is possible to give some simple formatting to text like this.

A limited subset of markdown is supported: New line with a double space followed by \n bold italics

I am setting response from an array:

$text = '';
        foreach($due_payments as $d){
            $text .=
                '**' . $d['name'] . ':** ' .
                $d['amount'] . ' ' . $d['currency'] . ' ' .
                '*' . $d['contract'] . '*' .  '  \n';
        }

        $card = \Dialogflow\RichMessage\Card::create()
            ->title('Ellos te deben: ')
            ->text($text)
        ;

The raw interaction log from dialogflow looks like this:

"fulfillmentMessages": [
    {
      "text": {
        "text": [
          "[{\"type\":1,\"platform\":\"telegram\",\"title\":\"Ellos te deben: \",\"subtitle\":\"**User Yundt:** 2450 MXN *JRLD6XSWME*  \\\\n**Jonathan sc:** 309 MXN *P9CY1W7A5N*  \\\\n**Jonathan serrano:** 500 MXN *1NWHCG6R24*  \\\\n**Jonathan sc:** 1050 MXN *AHQBNGJT2E*  \\\\n**Diana b:** 1400 MXN *DBT8NQCERL*  \\\\n\",\"imageUrl\":\"\",\"buttons\":[]},{\"type\":0,\"platform\":\"telegram\",\"speech\":\"hola\"}]"
        ]
      }
    }
  ],

The final result is that the text is not being properly formatted. Seems like the \n are being escaped?

IMG_20190429_011144

Thanks.

Freeman015 commented 5 years ago

Hello Jonathan,

I don't know if you resolved it yet but that has to do with php accepting \n only in " " and not in ' '. So in php '\n' will display \n and "\n" will go to a new line.

Greetings, Freeman015

basiteaal commented 5 years ago

So this issue can be closed.