0

I'm using the Google Chat API to send daily updates. I want to have a UI like this:

enter image description here

Like this, I want the UI should appear, https://developers.google.com/hangouts/chat/reference/message-formats/cards I'm referring this sheet to generate those UIs.

Zsolt Meszaros
  • 21,961
  • 19
  • 54
  • 57
vinuta
  • 1

1 Answers1

0

Checkbox is not an available card message. You can use button widget in a card message. But there are only 2 types of buttons that you can use, its either an image button or a text button.

Buttons

  • a widget may contain one or more buttons.
  • buttons in the same widget will be laid out horizontally.
  • buttons in a different widget will be laid out vertically.
  • there are two types of buttons: ImageButton and TextButton.
  • A button can specify a URL that will be opened when a user clicks on it, or an action to be handled by the bot's CARD_CLICKED event handler, as shown in Creating interactive cards.

An ImageButton may specify either a built-in icon or a custom image URL.

You can create card message using spaces.messages.create.

Sample Message Request Body: (card message)

In this example, there are 3 widgets created having 1 button in each widget so that the buttons will be aligned vertically.

{
  "cards": [
    {
      "header": {
        "title": "ChatBot",
        "imageUrl": "https://www.gstatic.com/images/icons/material/system/1x/face_black_24dp.png",

      },
      "sections": [
        {
          "widgets": [
            {
              "buttons": [
                {
                  "textButton": {
                    "text": "I have a bike",
                    "onClick": {
                      "action": {
                        "actionMethodName": "optionClick",
                        "parameters": [
                          {
                            "key": "mode",
                            "value": "bike"
                          }
                        ]
                      }
                    }
                  }
                }
              ]
            },
            {
              "buttons": [
                {
                  "textButton": {
                    "text": "I have a car",
                    "onClick": {
                      "action": {
                        "actionMethodName": "optionClick",
                        "parameters": [
                          {
                            "key": "mode",
                            "value": "car"
                          }
                        ]
                      }
                    }
                  }
                }
              ]
            },
            {
              "buttons": [
                {
                  "textButton": {
                    "text": "I have a boat",
                    "onClick": {
                      "action": {
                        "actionMethodName": "optionClick",
                        "parameters": [
                          {
                            "key": "mode",
                            "value": "boat"
                          }
                        ]
                      }
                    }
                  }
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

OUTPUT:

enter image description here

Ron M
  • 5,791
  • 1
  • 4
  • 16
  • Thank you very much for the reply. Is it possible to make the above UI as an array, For example, I have 4 questions in front of each question I will have a yes or no option, on selecting one option the other one which is unselected should disappear – vinuta Jan 29 '21 at 14:19
  • You can arrange your widget in any way you want, as mentioned in the answer if you add 1 widget with multiple [text paragraph](https://developers.google.com/hangouts/chat/reference/message-formats/cards#textparagraph) or [buttons](https://developers.google.com/hangouts/chat/reference/message-formats/cards#buttons) it will be arranged horizontally. While if you create 3 widgets, each widget will occupy 1 row just like the sample image in the answer – Ron M Jan 29 '21 at 20:35
  • Regarding hiding unselected option, it is also possible you just need to update the card once a button was clicked. For example Yes button was clicked for question 1. then you need to update your card which will remove your No button. Please refer here on how to [update an interactive card](https://developers.google.com/hangouts/chat/how-tos/cards-onclick#updating_an_interactive_card) – Ron M Jan 29 '21 at 20:38
  • If you think this was helpful, feel free to accept or upvote the answer as reference to other users. Thanks – Ron M Jan 29 '21 at 20:39