Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

Simple text message formatting #23

Open
jonaths opened this issue Apr 29, 2019 · 2 comments
Open

Simple text message formatting #23

jonaths opened this issue Apr 29, 2019 · 2 comments

Comments

@jonaths
Copy link

jonaths commented Apr 29, 2019

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
Copy link

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
Copy link

So this issue can be closed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants