apibotschatbotgoogle-hangoutsgoogle-chat

Create a dialog in google chat


I have followed the documentation provided by google https://developers.google.com/chat/how-tos/bot-dialogs but cannot figure out how to respond correctly to the "REQUEST_DIALOG" event. Here is what I did so far:

I created a new slash command with "opens a dialog" enter image description here

This results in an request dialog event as expected:

  "type": "MESSAGE",
  "eventTime": "2021-07-27T11:34:55.036447Z",
  "message": {
    "name": "***",
    "sender": {
      "name": "***",
      "displayName": "***",
      "avatarUrl": "***",
      "email": "***",
      "type": "HUMAN",
      "domainId": "***"
    },
    ..."slashCommand": {
      "commandId": "17"
    },
    "lastUpdateTime": "2021-07-27T11:34:55.036447Z"
  },
  .."configCompleteRedirectUrl": "https://chat.google.com/api/bot_config_complete?token\u003dAAJCfVWmnk9F9-p3tLQJcUN0lhskjka74V3SMYvZ5dQ_l4Ft1VkCG7JDybLxvLEc7WRwK05c768H6UO3d_EPzehsb2hnt1faOJsgSI6xUIZshjA2PNj1iWCyzp5JmtJtfDOzbmPjlUR7lW2bcOT5",
  "isDialogEvent": true,
  "dialogEventType": "REQUEST_DIALOG"
}

But I cannot figure out how to respond properly. A card, the ok response or follow-up dialog (as in the example) do not seem to work.

Can someone please provide a simple example that should work ?


Solution

  • I finally got it working. Here is the response that can be used to generate a simple dialog in google chat.

    {
      "action_response": {
        "dialog_action": {
          "dialog": {
            "body": {
              "sections": [
                {
                  "widgets": [
                    {
                      "textInput": {
                        "label": "Text input",
                        "type": "SINGLE_LINE",
                        "name": "fieldName"
                      }
                    }
                  ]
                }
              ]
            }
          }
        },
        "type": "DIALOG"
      }
    }
    

    It will look something like this:

    enter image description here

    The following page helped me to get it right. https://developers.googleblog.com/2021/06/add-dialogs-and-slash-commands-to-your-google-workspace-chat-bots.html