उपयोगकर्ताओं से डाले गए प्रोसेस की जानकारी

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

  • TextInput फ़्री-फ़ॉर्म टेक्स्ट एंट्री के लिए, जो सुझाव भी देता है.
  • SelectionInput सूची आइटम और मेन्यू, जैसे चेकबॉक्स, रेडियो बटन, और ड्रॉप-डाउन मेन्यू के लिए.
  • DateTimePicker का इस्तेमाल करें.


Chat ऐप्लिकेशन के लिए, JSON कार्ड मैसेज डिज़ाइन करने और उनकी झलक देखने के लिए, Card Builder का इस्तेमाल करें:

कार्ड बिल्डर खोलें

उपयोगकर्ताओं से डेटा इनपुट मिलने पर, चैट ऐप्लिकेशन ये काम कर सकते हैं निम्न:

  • ग्राहक सेवा के मामलों को अपडेट करना.
  • काम के ऑर्डर बनाना.
  • वेब सेवाओं की मदद से पुष्टि करें.

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

Node.js

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

Apps Script

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

Python

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

डेटा पाने की सुविधा कैसे काम करती है

Chat ऐप्लिकेशन, उपयोगकर्ता को जानकारी संवाद या कार्ड संदेश क्लिक करें. इस उदाहरण में, एक डायलॉग बॉक्स में उपयोगकर्ता से पूछा गया है कि उसे उस संपर्क की जानकारी हो जिसका इस्तेमाल करके, TextInput और SelectionInput विजेट:

एक डायलॉग बॉक्स, जिसमें कई तरह के विजेट दिखाए गए हैं.

प्रोसेस पूरी होने के बाद, Chat ऐप्लिकेशन को वह डेटा मिलता है जो उपयोगकर्ताओं ने JSON फ़ॉर्मैट में डायलॉग बॉक्स में डाले और इंटरैक्शन इवेंट जहां:

  • EventType CARD_CLICKED है.
  • DialogEventType SUBMIT_DIALOG है (सिर्फ़ डायलॉग के लिए).

उपयोगकर्ताओं ने क्या डाला है, इस बारे में डेटा पाने के लिए Event.common.formInputs फ़ील्ड में डालें. formInputs फ़ील्ड एक मैप है, जहां कुंजियां होती हैं हर विजेट को असाइन किए गए स्ट्रिंग आईडी और वैल्यू, उपयोगकर्ता के इनपुट को दिखाती हैं शामिल करें. अलग-अलग ऑब्जेक्ट अलग-अलग तरह के इनपुट डेटा को दिखाते हैं. इसके लिए उदाहरण के लिए, Event.common.formInputs.stringInputs स्ट्रिंग इनपुट को दिखाता है.

आपका ऐप्लिकेशन, उपयोगकर्ता की ओर से डाले गए पहले मान को यहां ऐक्सेस कर सकता है: event.common.formInputs.NAME.stringInputs.value[0], जहां NAME, a का name फ़ील्ड है TextInput विजेट.

कार्ड से डेटा पाएं

जब कोई उपयोगकर्ता किसी कार्ड मैसेज में डेटा डालता है, तो आपके Chat ऐप्लिकेशन पर अब Chat ऐप्लिकेशन काम करेगा इंटरैक्शन इवेंट की जानकारी देता है, जैसे कि नीचे दिया गया उदाहरण:

JSON

{
  "type": enum (EventType),
  "eventTime": string,
  "threadKey": string,
  "message": {
    object (Message)
  },
  "user": {
    object (User)
  },
  "space": {
    object (Space)
  },
  "action": {
    object (FormAction)
  },
  "configCompleteRedirectUrl": string,
  "common": {

    // Represents user data entered in a card.
    "formInputs": {

      // Represents user data entered for a specific field in a card.
      "NAME": {

        // Represents string data entered in a card, like text input fields
        // and check boxes.
        "stringInputs": {

          // An array of strings entered by the user in a card.
          "value": [
            string
          ]
        }
      }
    },
    "parameters": {
      string: string,
      ...
    },
    "invokedFunction": string
  }
}

डायलॉग बॉक्स से डेटा पाएं

जब कोई उपयोगकर्ता किसी डायलॉग बॉक्स में डेटा सबमिट करता है, तो आपके Chat ऐप्लिकेशन में Chat ऐप्लिकेशन के साथ इंटरैक्शन का कोई दूसरा इवेंट मिलता है, जैसे कि नीचे दिया गया उदाहरण:

JSON

{
  "type": enum (EventType),
  "eventTime": string,
  "threadKey": string,
  "message": {
    object (Message)
  },
  "user": {
    object (User)
  },
  "space": {
    object (Space)
  },
  "action": {
    object (FormAction)
  },
  "configCompleteRedirectUrl": string,

  // Indicates that this event is dialog-related.
  "isDialogEvent": true,

  // Indicates that a user clicked a button, and all data
  // they entered in the dialog is included in Event.common.formInputs.
  "dialogEventType": "SUBMIT_DIALOG",
  "common": {
    "userLocale": string,
    "hostApp": enum (HostApp),
    "platform": enum (Platform),
    "timeZone": {
      object (TimeZone)
    },

    // Represents user data entered in a dialog.
    "formInputs": {

      // Represents user data entered for a specific field in a dialog.
      "NAME": {

        // Represents string data entered in a dialog, like text input fields
        // and check boxes.
        "stringInputs": {

          // An array of strings entered by the user in a dialog.
          "value": [
            string
          ]
        }
      }
    },
    "parameters": {
      string: string,
      ...
    },
    "invokedFunction": string
  }
}

कार्ड मैसेज या डायलॉग बॉक्स से इकट्ठा किए गए डेटा का जवाब देना

कार्ड मैसेज या डायलॉग बॉक्स से डेटा मिलने के बाद, चैट ऐप्लिकेशन, जवाब स्वीकार करने के बाद या तो कोई गड़बड़ी देता है, जो दोनों को ActionResponse:

  • मैसेज मिलने की पुष्टि करने के लिए, ActionResponse पैरामीटर जिसमें "actionStatus": "OK" है.
  • गड़बड़ी का पता लगाने के लिए, ActionResponse पैरामीटर जिसमें "actionStatus": "ERROR MESSAGE" है.

उदाहरण

यहां दिए गए उदाहरण में, name वैल्यू की मौजूदगी का पता लगाया गया है. अगर यह नहीं है, तो ऐप्लिकेशन कोई गड़बड़ी दिखाता है. अगर यह जानकारी मौजूद है, तो ऐप्लिकेशन स्वीकार करता है कि फ़ॉर्म का डेटा मिल गया है और डायलॉग बॉक्स को बंद कर देता है.

Node.js

/**
 * 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.WIDGET_NAME.stringInputs.value[0] == "") {
    res.json({
      "actionResponse": {
        "type": "DIALOG",
        "dialogAction": {
          "actionStatus": "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 {
    res.json({
      "actionResponse": {
        "type": "DIALOG",
        "dialogAction": {
          "actionStatus": "OK"
        }
      }
    });
  }
}

Apps Script

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

/**
 * 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.WIDGET_NAME[""].stringInputs.value[0] == "") {
    return {
      "actionResponse": {
        "type": "DIALOG",
        "dialogAction": {
          "actionStatus": "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"
        }
      }
    };
  }
}

Python

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 common := event.get('common'):
    if form_inputs := common.get('formInputs'):
      if contact_name := form_inputs.get('WIDGET_NAME'):
        if string_inputs := contact_name.get('stringInputs'):
          if name := string_inputs.get('value')[0]:
            return {
              'actionResponse': {
                'type': 'DIALOG',
                'dialogAction': {
                  'actionStatus': 'OK'
                }
              }
            }
          else:
            return {
              'actionResponse': {
                'type': 'DIALOG',
                'dialogAction': {
                  'actionStatus': 'Don\'t forget to name your new contact!'
                }
              }
            }

समस्या हल करें

जब Google Chat ऐप्लिकेशन या card कोई गड़बड़ी दिखाता है, Chat के इंटरफ़ेस पर, "कोई गड़बड़ी हुई" मैसेज दिखता है. या "आपका अनुरोध प्रोसेस नहीं किया जा सका." कभी-कभी Chat यूज़र इंटरफ़ेस (यूआई) गड़बड़ी का कोई मैसेज नहीं दिखाता है. हालांकि, Chat ऐप्लिकेशन या कार्ड से कोई अनचाहा नतीजा मिलता है; उदाहरण के लिए, कार्ड मैसेज शायद दिखाना चाहते हैं.

हालांकि, Chat के यूज़र इंटरफ़ेस (यूआई) में गड़बड़ी का मैसेज शायद न दिखे, गड़बड़ी ठीक करने में आपकी मदद करने के लिए, जानकारी देने वाले गड़बड़ी के मैसेज और लॉग डेटा उपलब्ध है जब चैट ऐप्लिकेशन के लिए गड़बड़ी लॉग करने की सेटिंग चालू हो. मदद के लिए, डीबग करने और गड़बड़ियां ठीक करने के लिए, देखें Google Chat से जुड़ी गड़बड़ियां हल करना और गड़बड़ियां ठीक करना.