Google Chat ऐप्लिकेशन के तौर पर, स्लैश कमांड का जवाब देना

इस पेज में बताया गया है कि Google Chat ऐप्लिकेशन.

स्लैश कमांड एक ऐसा सामान्य तरीका है जिससे उपयोगकर्ता चैट ऐप्लिकेशन. स्लैश कमांड से, लोगों को यह जानने में भी मदद मिलती है कि Chat ऐप्लिकेशन की मुख्य सुविधाओं का इस्तेमाल करते हैं.

स्लैश कमांड का इस्तेमाल करने के लिए, लोग स्लैश (/) टाइप करते हैं. इसके बाद, एक छोटा टेक्स्ट निर्देश देते हैं, जैसे, Chat ऐप्लिकेशन के बारे में जानकारी पाने के लिए /about. उपयोगकर्ता स्लैश कमांड Google Chat, जो एक विंडो दिखाता है. इस विंडो में, चैट ऐप्लिकेशन:

स्लैश कमांड विंडो
पहली इमेज: यह विंडो तब दिखती है, जब उपयोगकर्ता Google Chat में स्लैश टाइप करते हैं.

जब कोई उपयोगकर्ता ऐसा मैसेज भेजता है जिसमें स्लैश कमांड शामिल होता है, तो यह मैसेज सिर्फ़ उपयोगकर्ता और Chat ऐप्लिकेशन को दिखेगा.

यह तय करने के लिए कि आपको स्लैश कमांड सेट अप करने चाहिए या नहीं. साथ ही, यह समझने के लिए कि उपयोगकर्ता के इंटरैक्शन डिज़ाइन करें, देखें उपयोगकर्ता की सभी गतिविधियां तय करना.

ज़रूरी शर्तें

Node.js

Google Chat ऐप्लिकेशन, जिसमें इंटरैक्टिव सुविधाएं चालू हैं. बनाने के लिए इंटरैक्टिव चैट ऐप्लिकेशन के लिए एचटीटीपी सेवा का इस्तेमाल करें. इस क्विकस्टार्ट को पूरा करें.

Apps Script

Google Chat ऐप्लिकेशन, जिसमें इंटरैक्टिव सुविधाएं चालू हैं. बनाने के लिए Apps Script में इंटरैक्टिव चैट ऐप्लिकेशन के साथ, इस क्विकस्टार्ट की प्रोसेस को पूरा करें.

Python

Google Chat ऐप्लिकेशन, जिसमें इंटरैक्टिव सुविधाएं चालू हैं. बनाने के लिए इंटरैक्टिव चैट ऐप्लिकेशन के लिए एचटीटीपी सेवा का इस्तेमाल करें. इस क्विकस्टार्ट को पूरा करें.

स्लैश कमांड सेट अप करना

इस सेक्शन में, स्लैश सेट अप करने के लिए इन चरणों को पूरा करने का तरीका बताया गया है आदेश:

  1. अपने स्लैश कमांड को एक नाम दें.
  2. Google Chat API में स्लैश कमांड को कॉन्फ़िगर करें.

अपने स्लैश कमांड को नाम दें

स्लैश कमांड का नाम वही होता है जिसे उपयोगकर्ता, Chat मैसेज में टाइप करते हैं Gmail फिर से शुरू करने के लिए. कम शब्दों में जानकारी भी नाम के नीचे दिखाई देता है, ताकि उपयोगकर्ताओं को कमांड इस्तेमाल करने के तरीके के बारे में ज़्यादा जानकारी दी जा सके:

स्लैश कमांड का नाम और जानकारी
दूसरी इमेज: स्लैश कमांड का नाम और ब्यौरा.

अपने स्लैश कमांड का नाम और ब्यौरा चुनते समय, ये सुझाव अपनाएं:

  • अपने स्लैश कमांड का नाम रखने के लिए:

    • छोटे, जानकारी देने वाले, और कार्रवाई करने लायक शब्दों या वाक्यांशों का इस्तेमाल करके उपयोगकर्ता के लिए साफ़ और आसान निर्देश होते हैं. उदाहरण के लिए, /createAReminder, /remindMe का इस्तेमाल करें.
    • अगर आपके निर्देश में एक से ज़्यादा शब्द हैं, तो उपयोगकर्ताओं को निर्देश पढ़ने में मदद करें पहले शब्द के लिए सभी लोअरकेस का इस्तेमाल करें और फिर पहले अतिरिक्त शब्दों का पत्र. उदाहरण के लिए, /updatecontact के बजाय, /updateContact का इस्तेमाल करें.
    • विचार करें कि अपने आदेश के लिए किसी अद्वितीय या सामान्य नाम का उपयोग करें. अगर आपने आपके निर्देश किसी सामान्य बातचीत या सुविधा के बारे में बताते हैं, तो आप वह सामान्य नाम जिसे लोग पहचानते हैं और जिसकी उम्मीद करते हैं, जैसे कि /settingsया /feedback. आप चाहें, तो यूनीक कमांड नाम इस्तेमाल करें. ऐसा इसलिए, क्योंकि अगर आपके कमांड का नाम अन्य चैट ऐप्लिकेशन के लिए एक ही है, तो उपयोगकर्ता को मिलते-जुलते निर्देशों को फ़िल्टर करके, अपने निर्देश खोजें और उनका इस्तेमाल करें.
  • अपने स्लैश कमांड के बारे में बताने के लिए:

    • ब्यौरे को छोटा और साफ़ रखें, ताकि उपयोगकर्ताओं को पता हो कि उन्हें किस तरह की जानकारी चाहिए तो वे कमांड की शुरुआत करते हैं.
    • उपयोगकर्ताओं को बताएं कि निर्देश को फ़ॉर्मैट करने की कोई ज़रूरत है या नहीं. उदाहरण के लिए, अगर /remindMe ऐसा निर्देश बनाया जाता है जिसके लिए आर्ग्युमेंट ज़रूरी है टेक्स्ट के लिए, विवरण को कुछ इस तरह सेट करें Remind me to do [something] at [time].
    • उपयोगकर्ताओं को बताएं कि Chat ऐप्लिकेशन उनका जवाब देता है या नहीं स्पेस के सभी सदस्यों के साथ या निजी तौर पर, निर्देश शुरू करने वाले उपयोगकर्ता के साथ शेयर करें. उदाहरण के लिए, स्लैश कमांड /about के लिए, इसकी जानकारी इस तरह दी जा सकती है Learn about this app (Only visible to you). किसी स्लैश कमांड के तौर पर, निजी मैसेज के साथ जवाब दें सेक्शन देखें.

Google Chat API में अपने स्लैश कमांड को कॉन्फ़िगर करें

स्लैश कमांड बनाने के लिए, आपको Google Chat API के लिए, आपके Chat ऐप्लिकेशन का कॉन्फ़िगरेशन.

Google Chat API में स्लैश कमांड को कॉन्फ़िगर करने के लिए, इन चरणों को पूरा करें कदम:

  1. Google Cloud Console में, 'मेन्यू' पर क्लिक करें > एपीआई और सेवाएं > चालू किए गए एपीआई और सेवाएं > Google Chat API

    Google Chat API पेज पर जाएं

  2. कॉन्फ़िगरेशन पर क्लिक करें.

  3. स्लैश कमांड में जाकर, स्लैश कमांड जोड़ें पर क्लिक करें.

  4. कमांड के लिए कोई नाम, कमांड आईडी, और जानकारी डालें:

    1. नाम: निर्देश का डिसप्ले नेम और उपयोगकर्ता क्या टाइप करते हैं कई बार इस्तेमाल किया जा सकता है. स्लैश से शुरू होना चाहिए, इसमें सिर्फ़ टेक्स्ट होना चाहिए, और ज़्यादा से ज़्यादा 50 वर्ण होने चाहिए.
    2. जानकारी: वह टेक्स्ट जो इस्तेमाल और फ़ॉर्मैट करने का तरीका बताता है आदेश. ब्यौरे में ज़्यादा से ज़्यादा 50 वर्ण हो सकते हैं.
    3. Command ID: 1 से 1000 तक की कोई संख्या जो Chat ऐप्लिकेशन, स्लैश निर्देश को पहचानने के लिए इस्तेमाल करता है और जवाब दें.
  5. ज़रूरी नहीं: अगर आपको Chat ऐप्लिकेशन से जवाब पाना है, तो डायलॉग के साथ निर्देश देने के बाद, कोई डायलॉग बॉक्स खोलें.

  6. सेव करें पर क्लिक करें.

स्लैश कमांड को अब Chat ऐप्लिकेशन के लिए कॉन्फ़िगर कर दिया गया है.

स्लैश निर्देश का जवाब दें

जब लोग ऐसा Chat मैसेज बनाते हैं जिसमें स्लैश कमांड शामिल होता है, आपके Chat ऐप्लिकेशन को MESSAGE इंटरैक्शन इवेंट मिलेगा. इवेंट पेलोड में स्लैश कमांड, slashCommand सहित और slashCommandMetadata फ़ील्ड. आप इन फ़ील्ड का उपयोग कमांड आईडी की पहचान करने और जवाब.

यहां दिए गए उदाहरण में, MESSAGE इंटरैक्शन इवेंट के लिए JSON पेलोड दिखाया गया है जिसमें स्लैश कमांड /vote शामिल है:

    {
      ...
      "message": {
        ...
        "text": "/vote yes",
        "argumentText": " yes",
        "slashCommand": {
          "commandId": 2
        },
        "annotations": [
          {
            "length": 5,
            "startIndex": 0,
            "type": "SLASH_COMMAND",
            "slashCommand": {
              "commandName":"/vote",
              "commandId":1,
              "type": "INVOKE",
              "bot": {
                "avatarUrl": "https://www.example.com/images/vote-app-icon.png",
                "displayName": "Voter Chat App",
                "name": "users/1234567890987654321",
                "type": "BOT"
              }
            }
          }
        ]
      }
    }

स्लैश कमांड का जवाब देने के लिए, यह पता लगाया जा सकता है कि slashCommand फ़ील्ड में इवेंट पेलोड में मौजूद है. अगर ऐसा है, तो कमांड का रिस्पॉन्स दें. नीचे दिया गया कोड सैंपल, MESSAGE इंटरैक्शन इवेंट का जवाब देने का तरीका बताता है जिसमें एक स्लैश कमांड हो:

Node.js

/**
* Responds to a MESSAGE event in Google Chat.
*
* @param {Object} event the event object from Chat API.
*
* @return {object} function in response to a slash command.
*/

exports.onMessage = function onMessage(req, res) {

  // Stores the Google Chat event as a variable.
  var event = req.body;

  // Checks for the presence of event.message.slashCommand.
  if (event.message.slashCommand) {
    switch (event.message.slashCommand.commandId) {
      case ID: // The ID for your slash command
        res.json(runFunction); // The response to the slash command.
    }
  }

Apps Script

/**
* Responds to a MESSAGE event in Google Chat.
*
* @param {Object} event the event object from Chat API.
*
* @return {object} function in response to a slash command.
*/

function onMessage(event) {

  // Checks for the presence of event.message.slashCommand
  if (event.message.slashCommand) {
    switch (event.message.slashCommand.commandId) {
      case ID: // The ID for your slash command
        return runFunction; // The response to the slash command.
    }
  }
}

Python

from typing import Any, Mapping

import flask
import functions_framework

@functions_framework.http
def main(req: flask.Request) -> Mapping[str, Any]:
  """Responds to a MESSAGE event in Google Chat that includes a slash command.

  Args:
      req (flask.Request): the event object from Chat API.

  Returns:
      Mapping[str, Any]: function in response to a slash command.
  """
  if req.method == 'GET':
    return 'Sorry, this function must be called from a Google Chat.'

  request = req.get_json(silent=True)

  if slash_command := request.get('message', dict()).get('slashCommand'):
    command_id = slash_command['commandId']
    if command_id == ID:
      return runFunction

कोड का इस्तेमाल करने के लिए, इन्हें बदलें:

ज़रूरी नहीं: निजी मैसेज भेजकर जवाब दें

जिन मैसेज में स्लैश कमांड शामिल होते हैं वे सिर्फ़ उस उपयोगकर्ता को दिखते हैं जिसने मैसेज भेजने और पाने वाला Chat ऐप्लिकेशन. अगर आपने आपने स्पेस में जोड़े जाने के लिए, Chat ऐप्लिकेशन को कॉन्फ़िगर कर लिया है है, तो आप शायद स्लैश कमांड का इस्तेमाल करें निजी रखने के लिए, ताकि उपयोगकर्ता और चैट ऐप्लिकेशन.

उदाहरण के लिए, अगर कोई टीम ऐसे चैट ऐप्लिकेशन का इस्तेमाल कर रही है जो तो उपयोगकर्ता, स्लैश कमांड चालू कर सकते हैं जैसे इन्हें असाइन किए गए सहायता मामले देखने के लिए /myCases. अगर टीम, किसी स्पेस में चैट ऐप्लिकेशन जोड़ना. यह उपयोगकर्ता इस स्लैश कमांड का इस्तेमाल करता है हो सकता है कि Chat ऐप्लिकेशन सिर्फ़ उन मैसेज को जवाब दे उन्हें. उपयोगकर्ता के सहायता अनुरोधों को स्पेस में सभी के साथ पोस्ट करने से बचने के लिए, Chat ऐप्लिकेशन निजी तौर पर जवाब दे सकता है.

स्लैश कमांड का निजी तौर पर जवाब देने के लिए, यह देखें Google Chat के उपयोगकर्ताओं को निजी मैसेज भेजना.

उदाहरण के लिए: Rolodex Chat ऐप्लिकेशन का इस्तेमाल करके, संपर्कों को सेट अप करना

यहां दिए गए उदाहरण में, ऐसा Chat ऐप्लिकेशन दिखाया गया है जो मैसेज का जवाब देने के लिए ये स्लैश कमांड:

  • /help निर्देश, मैसेज पाने का तरीका बताता है का इस्तेमाल करने में Chat ऐप्लिकेशन का इस्तेमाल करें. कमांड आईडी सेट हो गया है 1 तक.
  • /createContact निर्देश से एक डायलॉग खुलता है, जहां उपयोगकर्ता मैसेज डाल सकते हैं संपर्क जानकारी देखें. कमांड आईडी, 2 पर सेट है.

इस सैंपल को चलाने से पहले, ये काम करें: Google Chat API में स्लैश कमांड कॉन्फ़िगर करें.

Node.js

/**
* Responds to messages that have links whose URLs
* match URL patterns configured for link previews.
*
* @param {Object} event The event object from Chat
* API.
*
* @return {Object} Response from the Chat app
* attached to the message with the previewed link.
*/
exports.onMessage = function onMessage(req, res) {

  // Store the Google Chat event as a variable.
  const event = req.body;

  if (req.method === "GET" || !event.message) {
    res.send("Hello! This function is meant to be used in a Google Chat " +
      "Space.");
  }

  // Checks for the presence of event.message.slashCommand.
  // If the slash command is "/help", responds with a text message.
  // If the slash command is "/createContact", opens a dialog.
  if (event.message.slashCommand) {
    switch (event.message.slashCommand.commandId) {
      case 1: // /help
        res.json({"text": "Contact bot helps you update your address book!"});
      case 2:  // /createContact
        res.json(openDialog(event));
    }
  }

  // If the Chat app doesn"t detect a slash command, it responds
  // with a card that prompts the user to add a contact
  else {
    res.json({
      "cardsV2": [{
        "cardId": "addContact",
        "card": {
          "header": {
            "title": "Rolodex",
            "subtitle": "Manage your contacts!",
            "imageUrl": "https://www.gstatic.com/images/branding/product/2x/contacts_48dp.png",
            "imageType": "CIRCLE"
          },
          "sections": [
            {
              "widgets": [
                {
                  "buttonList": {
                    "buttons": [
                      {
                        "text": "Add Contact",
                        "onClick": {
                          "action": {
                            "function": "openDialog",
                            "interaction": "OPEN_DIALOG"
                          }
                        }
                      }
                    ]
                  }
                }
              ]
            }
          ]
        }
      }]
    });
  }

  // Respond to button clicks on attached cards
  if (event.type === "CARD_CLICKED") {
    if (event.common.invokedFunction === "openDialog") {
      res.json(openDialog(event));
    }

    if (event.common.invokedFunction === "openSequentialDialog") {
      res.json(openSequentialDialog(event));
    }

    if (event.common.invokedFunction === "confirmDialogSuccess") {
      res.json(confirmDialogSuccess(event));
    }
  }
};

/**
* Opens and starts a dialog that lets users add details about a contact.
*
* @param {object} event the event object from Google Chat.
*
* @return {object} open a dialog.
*/
function openDialog(event) {
  return {
    "action_response": {
      "type": "DIALOG",
      "dialog_action": {
        "dialog": {
          "body": {
            "sections": [
              {
                "header": "Add new contact",
                "widgets": [
                  {
                    "textInput": {
                      "label": "Name",
                      "type": "SINGLE_LINE",
                      "name": "name"
                    }
                  },
                  {
                    "textInput": {
                      "label": "Address",
                      "type": "MULTIPLE_LINE",
                      "name": "address"
                    }
                  },
                  {
                    "decoratedText": {
                      "text": "Add to favorites",
                      "switchControl": {
                        "controlType": "SWITCH",
                        "name": "saveFavorite"
                      }
                    }
                  },
                  {
                    "decoratedText": {
                      "text": "Merge with existing contacts",
                      "switchControl": {
                        "controlType": "SWITCH",
                        "name": "mergeContact",
                        "selected": true
                      }
                    }
                  },
                  {
                    "buttonList": {
                      "buttons": [
                        {
                          "text": "Next",
                          "onClick": {
                            "action": {
                              "function": "openSequentialDialog"
                            }
                          }
                        }
                      ]
                    }
                  }
                ]
              }
            ]
          }
        }
      }
    }
  };
};

/**
* Opens a second dialog that lets users add more contact details.
*
* @param {object} event the event object from Google Chat.
*
* @return {object} open a dialog.
*/
function openSequentialDialog(event) {
  return {
    "action_response": {
      "type": "DIALOG",
      "dialog_action": {
        "dialog": {
          "body": {
            "sections": [
              {
                "header": "Add new contact",
                "widgets": [
                  {
                    "textInput": {
                      "label": "Notes",
                      "type": "MULTIPLE_LINE",
                      "name": "notes"
                    }
                  },
                  {
                    "selectionInput": {
                      "type": "RADIO_BUTTON",
                      "label": "Contact type",
                      "name": "contactType",
                      "items": [
                        {
                          "text": "Work",
                          "value": "Work",
                          "selected": false
                        },
                        {
                          "text": "Personal",
                          "value": "Personal",
                          "selected": false
                        }
                      ]
                    }
                  },
                  {
                    "buttonList": {
                      "buttons": [
                        {
                          "text": "Submit",
                          "onClick": {
                            "action": {
                              "function": "confirmDialogSuccess",
                              "parameters": [
                                {
                                  "key": "confirmDialogSuccess",
                                  "value": "confirmDialogSuccess"
                                }
                              ]
                            }
                          }
                        }
                      ]
                    },
                    "horizontalAlignment": "END"
                  }
                ]
              }
            ]
          }
        }
      }
    }
  };
}

/**
* Checks for a form input error, the absence of
* a "name" value, and returns an error if absent.
* Otherwise, confirms successful receipt of a dialog.
*
* Confirms successful receipt of a dialog.
*
* @param {Object} event the event object from Chat API.
*
* @return {object} open a Dialog in Google Chat.
*/
function receiveDialog(event) {

  // Checks to make sure the user entered a name
  // in a dialog. If no name value detected, returns
  // an error message.
  if (event.common.formInputs.contactName.stringInputs.value[0] === "") {
    return {
      "actionResponse": {
        "type": "DIALOG",
        "dialogAction": {
          "actionStatus": {
            "statusCode": "OK",
            "userFacingMessage": "Don't forget to name your new contact!"
          }
        }
      }
    };

    // Otherwise the app indicates that it received
    // form data from the dialog. Any value other than "OK"
    // gets returned as an error. "OK" is interpreted as
    // code 200, and the dialog closes.
  } else {
    return {
      "actionResponse": {
        "type": "DIALOG",
        "dialogAction": {
          "actionStatus": "OK"
        }
      }
    };
  }
}

Apps Script

यह उदाहरण वापस लौटकर एक कार्ड संदेश भेजता है card JSON. Google आपके यूआरएल पैरामीटर को कैसे इस्तेमाल करेगा, यह तय करने के लिए Apps Script कार्ड सेवा.

apps-script/dialogs/rolodex.gs
/**
* Responds to a MESSAGE event in Google Chat.
*
* @param {Object} event the event object from Chat API.
*
* @return {Object} open a Dialog in response to a slash command
* or a card"s button click.
*/
function onMessage(event) {

  // Checks for the presence of event.message.slashCommand.
  // If the slash command is "/help", responds with a text message.
  // If the slash command is "/createContact", opens a dialog.
  if (event.message.slashCommand) {
    switch (event.message.slashCommand.commandId) {
      case 1: // /help
        return {"text": "Contact bot helps you update your address book!"}
      case 2:  // /createContact
        return openDialog(event);
    }
  }

  // If the Chat app doesn"t detect a slash command, it responds
  // with a card that prompts the user to add a contact
  else {
    return {
      "cardsV2": [{
        "cardId": "addContact",
        "card": {
          "header": {
            "title": "Rolodex",
            "subtitle": "Manage your contacts!",
            "imageUrl": "https://www.gstatic.com/images/branding/product/2x/contacts_48dp.png",
            "imageType": "CIRCLE"
          },
          "sections": [
            {
              "widgets": [
                {
                  "buttonList": {
                    "buttons": [
                      {
                        "text": "Add Contact",
                        "onClick": {
                          "action": {
                            "function": "openDialog",
                            "interaction": "OPEN_DIALOG"
                          }
                        }
                      }
                    ]
                  }
                }
              ]
            }
          ]
        }
      }]

    };
  }
}

/**
* Responds to a CARD_CLICKED event in Google Chat.
*
* @param {Object} event the event object from Google Chat
*/
function onCardClick(event) {

  if (event.common.invokedFunction === "openDialog") {
    return openDialog(event);
  }

  if (event.common.invokedFunction === "openSequentialDialog") {
    const contactName = fetchFormValue(event, "contactName");
    const address = fetchFormValue(event, "address");
    return openSequentialDialog(contactName, address);
  }

  if (event.common.invokedFunction === "receiveDialog") {
    const parameters = event.common.parameters;
    parameters["contactType"] = fetchFormValue(event, "contactType");
    parameters["notes"] = fetchFormValue(event, "notes");
    return receiveDialog(parameters);
  }
}

/**
 * Extracts form input value for a given widget
 * 
 * @param {Object} event the event object from Google Chat
 * @param {String} widgetName the widget name
 * @returns the form input value for the widget
 */
function fetchFormValue(event, widgetName) {
  const widget = event.common.formInputs[widgetName];
  if (widget) {
    return widget[""]["stringInputs"]["value"][0];
  }
}

/**
* Opens and starts a dialog that lets users add details about a contact.
*
*
* @return {Object} open a dialog.
*/
function openDialog(event) {
  return {
    "action_response": {
      "type": "DIALOG",
      "dialog_action": {
        "dialog": {
          "body": {
            "sections": [
              {
                "header": "Add new contact",
                "widgets": [
                  {
                    "textInput": {
                      "label": "Name",
                      "type": "SINGLE_LINE",
                      "name": "contactName"
                    }
                  },
                  {
                    "textInput": {
                      "label": "Address",
                      "type": "MULTIPLE_LINE",
                      "name": "address"
                    }
                  },
                  {
                    "decoratedText": {
                      "text": "Add to favorites",
                      "switchControl": {
                        "controlType": "SWITCH",
                        "name": "saveFavorite"
                      }
                    }
                  },
                  {
                    "decoratedText": {
                      "text": "Merge with existing contacts",
                      "switchControl": {
                        "controlType": "SWITCH",
                        "name": "mergeContact",
                        "selected": true
                      }
                    }
                  },
                  {
                    "buttonList": {
                      "buttons": [
                        {
                          "text": "Next",
                          "onClick": {
                            "action": {
                              "function": "openSequentialDialog"
                            }
                          }
                        }
                      ]
                    }
                  }
                ]
              }
            ]
          }
        }
      }
    }
  };
}

/**
* Opens a second dialog that lets users add more contact details.
*
* @param {String} contactName the contact name from the previous dialog.
* @param {String} address the address from the previous dialog.
*
* @return {Object} open a dialog.
*/
function openSequentialDialog(contactName, address) {
  return {
    "action_response": {
      "type": "DIALOG",
      "dialog_action": {
        "dialog": {
          "body": {
            "sections": [
              {
                "header": "Add new contact",
                "widgets": [
                  {
                    "textInput": {
                      "label": "Notes",
                      "type": "MULTIPLE_LINE",
                      "name": "notes"
                    }
                  },
                  {
                    "selectionInput": {
                      "type": "RADIO_BUTTON",
                      "label": "Contact type",
                      "name": "contactType",
                      "items": [
                        {
                          "text": "Work",
                          "value": "Work",
                          "selected": false
                        },
                        {
                          "text": "Personal",
                          "value": "Personal",
                          "selected": false
                        }
                      ]
                    }
                  },
                  {
                    "buttonList": {
                      "buttons": [
                        {
                          "text": "Submit",
                          "onClick": {
                            "action": {
                              "function": "receiveDialog",
                              "parameters": [
                                {
                                  "key": "contactName",
                                  "value": contactName
                                },
                                {
                                  "key": "address",
                                  "value": address
                                }
                              ]
                            }
                          }
                        }
                      ]
                    },
                    "horizontalAlignment": "END"
                  }
                ]
              }
            ]
          }
        }
      }
    }
  };
}

/**
* Checks for a form input error, the absence of
* a "name" value, and returns an error if absent.
* Otherwise, confirms successful receipt of a dialog.
*
* Confirms successful receipt of a dialog.
*
* @param {Object} parameters the form input values.
*
* @return {Object} open a Dialog in Google Chat.
*/
function receiveDialog(parameters) {

  // Checks to make sure the user entered a name
  // in a dialog. If no name value detected, returns
  // an error message.
  if (!parameters.contactName) {
    return {
      "actionResponse": {
        "type": "DIALOG",
        "dialogAction": {
          "actionStatus": {
            "statusCode": "INVALID_ARGUMENT",
            "userFacingMessage": "Don't forget to name your new contact!"
          }
        }
      }
    };

    // Otherwise the Chat app indicates that it received
    // form data from the dialog. Any value other than "OK"
    // gets returned as an error. "OK" is interpreted as
    // code 200, and the dialog closes.
  } else {
    return {
      "actionResponse": {
        "type": "DIALOG",
        "dialogAction": {
          "actionStatus": {
            "statusCode": "OK",
            "userFacingMessage": "Success " + JSON.stringify(parameters)
          }
        }
      }
    };
  }
}

Python

from typing import Any, Mapping

import flask
import functions_framework

@functions_framework.http
def main(req: flask.Request) -> Mapping[str, Any]:
  """Responds to a MESSAGE event in Google Chat that includes the /createContact
     slash command by opening a dialog.

  Args:
      req (flask.Request): the event object from Chat API.

  Returns:
      Mapping[str, Any]: open a Dialog in response to a card's button click.
  """

  if req.method == 'GET':
    return 'Sorry, this function must be called from a Google Chat.'

  request = req.get_json(silent=True)

  if request.get('type') == 'CARD_CLICKED':
    invoked_function = request.get('common', dict()).get('invokedFunction')
    if invoked_function == 'open_dialog':
      return open_dialog(request)

    elif invoked_function == 'open_sequential_dialog':
      return open_dialog(request)

    elif invoked_function == "receive_dialog":
      return receive_dialog(request)

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

def open_dialog(request: Mapping[str, Any]) -> Mapping[str, Any]:
  """Opens a dialog in Google Chat.

  Args:
      request (Mapping[str, Any]): the event object from Chat API.

  Returns:
      Mapping[str, Any]: open a Dialog in response to a card's button click.
  """
  return {
    'action_response': {
      'type': 'DIALOG',
      'dialog_action': {
        'dialog': {
          'body': {
            'sections': [
              {
                'header': 'Add new contact',
                'widgets': [
                  {
                    'textInput': {
                      'label': 'Name',
                      'type': 'SINGLE_LINE',
                      'name': 'name'
                    }
                  },
                  {
                    'textInput': {
                      'label': 'Address',
                      'type': 'MULTIPLE_LINE',
                      'name': 'address'
                    }
                  },
                  {
                    'decoratedText': {
                      'text': 'Add to favorites',
                      'switchControl': {
                        'controlType': 'SWITCH',
                        'name': 'saveFavorite'
                      }
                    }
                  },
                  {
                    'decoratedText': {
                      'text': 'Merge with existing contacts',
                      'switchControl': {
                        'controlType': 'SWITCH',
                        'name': 'mergeContact',
                        'selected': True
                      }
                    }
                  },
                  {
                    'buttonList': {
                      'buttons': [
                        {
                          'text': 'Next',
                          'onClick': {
                            'action': {
                              'function': 'open_sequential_dialog'
                            }
                          }
                        }
                      ]
                    }
                  }
                ]
              }
            ]
          }
        }
      }
    }
  }

def open_sequential_dialog(request: Mapping[str, Any]) -> Mapping[str, Any]:
  """Opens a second dialog that lets users add more contact details.

  Args:
      request (Mapping[str, Any]): the event object from Chat API.

  Returns:
      Mapping[str, Any]: open a Dialog in response to a card's button click.
  """
  return {
    'action_response': {
      'type': 'DIALOG',
      'dialog_action': {
        'dialog': {
              'body': {
                'sections': [
                  {
                    'header': 'Add new contact',
                    'widgets': [
                      {
                        'textInput': {
                          'label': 'Notes',
                          'type': 'MULTIPLE_LINE',
                          'name': 'notes'
                        }
                      },
                      {
                        'selectionInput': {
                          'type': 'RADIO_BUTTON',
                          'label': 'Contact type',
                          'name': 'contactType',
                          'items': [
                            {
                              'text': 'Work',
                              'value': 'Work',
                              'selected': False
                            },
                            {
                              'text': 'Personal',
                              'value': 'Personal',
                              'selected': False
                            }
                          ]
                        }
                      },
                      {
                        'buttonList': {
                          'buttons': [
                            {
                              'text': 'Submit',
                              'onClick': {
                                'action': {
                                  'function': 'receive_dialog',
                                  'parameters': [
                                    {
                                      'key': 'receiveDialog',
                                      'value': 'receiveDialog'
                                    }
                                  ]
                                }
                              }
                            }
                          ]
                        },
                        'horizontalAlignment': 'END'
                      }
                    ]
                  }
                ]
              }
        }
      }
    }
  }

def receive_dialog(event: Mapping[str, Any]) -> Mapping[str, Any]:
  """Checks for a form input error, the absence of a "name" value, and returns
     an error if absent. Otherwise, confirms successful receipt of a dialog.

  Args:
      event (Mapping[str, Any]): the event object from Chat API.

  Returns:
      Mapping[str, Any]: the response.
  """

  if event.get('common', dict()) \
      .get('formInputs', dict()).get('contactName', dict()) \
          .get('stringInputs').get('value', list()):
    return {
      'actionResponse': {
        'type': 'DIALOG',
        'dialogAction': {
          'actionStatus': 'OK'
        }
      }
    }
  else:
    return {
      'actionResponse': {
        'type': 'DIALOG',
        'dialogAction': {
          'actionStatus': "Don't forget to name your new contact!"
        }
      }
    }