Search code examples
phparraysgoogle-hangouts

Constructing PHP Array for Hangouts Webhook


I'm trying to build the following Array with PHP so that I can send a card to Google Hangouts Chat Webhook.

{
    "cards": [
        {
            "sections": [
                {
                    "widgets": [
                        {
                            "keyValue": {
                                "topLabel": "Order No.",
                                "content": "12345",
                                "contentMultiline": "false",
                                "bottomLabel": "Delayed",
                                "onClick": {
                                     "openLink": {
                                        "url": ""
                                     }
                                 },
                                "icon": "TRAIN",
                                "button": {
                                    "textButton": {
                                       "text": "VISIT WEBSITE",
                                       "onClick": {
                                           "openLink": {
                                                "url": ""
                                            }
                                        }
                                      }
                                 }
                             }
                        }
                    ]
                }
            ]
        }
    ]
}

This is where I got to but does not seem to work..

$card["cards"]["sections"]["widgets"]["keyValue"]["topLabel"] = "Issue No";
$card["cards"]["sections"]["widgets"]["keyValue"]["topLabel"] = $_GET["issueid"];
$card["cards"]["sections"]["widgets"]["keyValue"]["contentMultiline"] = false;

Any help would be amazing, just a brief overview of how to contsruct the above array in PHP.

Thanks!


Solution

  • Solved.

    $card["cards"]["sections"]["widgets"]["keyValue"]["topLabel"] = $_GET["issueid"];

    this will overwrite above the one I think, I think ["topLabel"] should be ["content"] in the second index ??

    Thanks @devpro