Search code examples
htmlhangouts-apigoogle-hangouts

hangouts api cards trimming text


Im trying to send large descriptions inside a card using the google hangout api; but unfortunately the text is being trimmed when its too long. Below is a sample of the card I send:

"cards": [{
        "sections": [{
                "widgets": [{
                        "keyValue": {
                            "topLabel": "Label",
                            "content": "Long Description goes here..."
                        }
                    }
                ]
            }
        ]
    }
]

When I look at the html received by the bot the content is in a dive with white-space: nowrap;... I tried placing the content in a div and giving it white-space: wrap; as such "content": "<div style='white-space: wrap;'>Long Description...</div>", but the bot just removes that div when it sends the card.

I also noticed that on pc browser the text was trimmed at 43 characters, so I used regex to add \n at every 43 character using .replace(/.{42}/g, '$&\n'), which kind of works but on mobile the card seems to trim messages even more...

Anyway I could simply remove that annoying white-space style??

EDIT

I know about this post, but it tries to increase width of the card (which technically would work for me), and there were no solutions...


Solution

  • It is possible to do it and very simple:

    You only have to add contentMultiline: true to your KeyValue property.

    "cards": [{
            "sections": [{
                    "widgets": [{
                            "keyValue": {
                                "topLabel": "Label",
                                "content": "The working day is thus not a constant, but a variable quantity. One of its parts, certainly, is determined by the working-time required for the reproduction of the labour-power of the labourer himself. But its total amount varies with the duration of the surplus labour. The working day is, therefore, determinable, but is, per se, indeterminate.",
                                "contentMultiline": true,
                            }
                         },
                     ]
                }
            ]
        }
    ]
    

    Here you'll find the documentation of KeyValue fields:

    https://developers.google.com/hangouts/chat/reference/rest/v1/cards#keyvalue