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

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

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


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

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

लोगों से डेटा इनपुट मिलने पर, 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, TextInput विजेट का name फ़ील्ड है.

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

जब कोई उपयोगकर्ता किसी कार्ड मैसेज में डेटा डालता है, तो आपके 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
  }
}

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

कार्ड पर मैसेज या डायलॉग से डेटा मिलने के बाद, Chat ऐप्लिकेशन या तो रसीद स्वीकार करता है या गड़बड़ी का मैसेज दिखाता है. ये दोनों काम, 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

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

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