2

I use bot to post cards with version 2 (сards_v2 property).

Cards are rendered as normal, but I want to add a Button to open Dialog. This does not work.

How can I achieve this?

I post to POST /v1/chat/channels/:channel_id/messages?

body:

{
    "cards_v2": [{
        "card": {
            "header": {
                "title": "Rolodex",
                "subtitle": "Manage your contacts!",
                "imageType": "CIRCLE",
                "imageUrl": "https://www.gstatic.com/images/branding/product/2x/contacts_48dp.png"
            },
            "sections": [{
                "widgets": [{
                    "buttonList": {
                        "buttons": [{
                            "text": "Add Contact",
                            "onClick": {
                                "action": {
                                    "function": "openDialog",
                                    "interaction": "OPEN_DIALOG"
                                }
                            }
                        }]
                    }
                }]
            }]
        }
    }]
}

Card successfully posted

Then I click on Button, and receive event:

{
    "type": "CARD_CLICKED",
    "eventTime": "2022-08-31T16:16:36.147391Z",
    "message": {
        "name": "spaces/:space_id/messages/YTyNVBNW-H4.YTyNVBNW-H4",
        "sender": { ... },
        "createTime": "2022-08-31T16:16:31.639439Z",
        "thread": { ... },
        "space": { ... },
        "cardsV2": [{
            "card": {
                "header": {
                    "title": "Rolodex",
                    "subtitle": "Manage your contacts!",
                    "imageType": "CIRCLE",
                    "imageUrl": "https://www.gstatic.com/images/branding/product/2x/contacts_48dp.png"
                },
                "sections": [{
                    "widgets": [{
                        "buttonList": {
                            "buttons": [{
                                "text": "Add Contact",
                                "onClick": {
                                    "action": {
                                        "function": "openDialog"
                                    }
                                }
                            }]
                        }
                    }]
                }]
            }
        }],
        "retentionSettings": {
            "state": "PERMANENT"
        }
    },
    "user": { ... },
    "space": { ... },
    "action": {
        "actionMethodName": "openDialog"
    },
    "common": {
        "hostApp": "CHAT",
        "invokedFunction": "openDialog"
    }
}

First: Event skips DialogEventType is REQUEST_DIALOG.

Second: When I respond with dialog response, but no dialog appears.

{
    "actionResponse": {
        "type": "DIALOG",
        "dialogAction": {
            "dialog": {
                "body": {
                    "sections": [{
                        "header": "Add new contact",
                        "widgets": [{
                            "textInput": {
                                "name": "contactName",
                                "label": "Name",
                                "type": "SINGLE_LINE"
                            }
                        }, {
                            "buttonList": {
                                "buttons": [{
                                    "text": "Next",
                                    "onClick": {
                                        "action": {
                                            "function": "openSequentialDialog"
                                        }
                                    }
                                }]
                            }
                        }]
                    }]
                }
            }
        }
    }
}

I see only error: Error message

  • 2
    Google team, please respond. Buttons and dialogs are essential elements of the cards. How come this is not working? – Alexey Aug 29 '22 at 13:37
  • The code you provided above worked for me, so my guess is that you're just missing something small. Check your onCardClick(event) because there error you mentioned will occur if that function fails. – Design.Garden Apr 20 '23 at 15:09
  • Having the same problem. Just getting an error that says "Message cannot be empty". – Jason Jurotich May 14 '23 at 00:40

0 Answers0