किसी उपयोगकर्ता के स्पेस को पढ़े जाने की स्थिति के बारे में जानकारी पाएं

यह गाइड बताती है किgetSpaceReadState उपयोगकर्ता ने क्या पढ़ा है, इसकी जानकारी पाने के लिए Google Chat API का SpaceReadState संसाधन राज्य के अंदर वैल्यू दिखाता है. किसी मैसेज थ्रेड में मौजूद मैसेज की स्थिति जानने के लिए, देखें उपयोगकर्ता के थ्रेड पढ़ने की स्थिति के बारे में जानकारी पाना.

कॉन्टेंट बनाने SpaceReadState संसाधन एक सिंगलटन संसाधन है, जो Google Chat पर मौजूद किसी स्पेस में उपयोगकर्ता का आखिरी बार पढ़ा गया मैसेज.

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

Python

  • कारोबार या एंटरप्राइज़ Google Workspace खाता, जिसके पास इसका ऐक्सेस है Google Chat.
  • Python 3.6 या इससे नया वर्शन
  • पीआईपी पैकेज मैनेजमेंट टूल
  • Google की नई क्लाइंट लाइब्रेरी. उन्हें इंस्टॉल या अपडेट करने के लिए, अपने कमांड-लाइन इंटरफ़ेस में यह कमांड चलाएं:
    pip3 install --upgrade google-api-python-client google-auth-oauthlib
    

Node.js

  • कारोबार या एंटरप्राइज़ Google Workspace खाता, जिसके पास इसका ऐक्सेस है Google Chat.
  • Node.js 14 या उसके बाद का वर्शन
  • npm पैकेज मैनेजमेंट टूल
  • Google की नई क्लाइंट लाइब्रेरी. उन्हें इंस्टॉल या अपडेट करने के लिए, अपने कमांड-लाइन इंटरफ़ेस में यह कमांड चलाएं:
    npm install @google-cloud/local-auth @googleapis/chat
    

Apps Script

  • कारोबार या एंटरप्राइज़ Google Workspace खाता, जिसके पास इसका ऐक्सेस है Google Chat.

कॉल करने वाले उपयोगकर्ता के स्पेस को पढ़ने की स्थिति जानना

स्पेस में, उपयोगकर्ता के पढ़े जाने की स्थिति के बारे में जानकारी पाने के लिए, यह जानकारी शामिल करें आपके अनुरोध में:

  • chat.users.readstate या chat.users.readstate.readonly बताएं अनुमति का दायरा.
  • कॉल करें getSpaceReadState तरीका पूरी तरह कैसे SpaceReadState संसाधन.
  • मैसेज पाने के लिए, स्पेस का name पास करें. इसमें यूज़र आईडी या उपनाम और स्पेस आईडी. स्पेस का रीड ओनली स्टेटस सेट करने पर, सिर्फ़ उस टेक्स्ट को पढ़ा जा सकता है कॉल करने वाले उपयोगकर्ता की स्थिति, जिसे किसी एक फ़ॉलो किया जा रहा है:
    • me का दूसरा ईमेल पता. उदाहरण के लिए, users/me/spaces/SPACE/spaceReadState.
    • कॉल करने वाले उपयोगकर्ता का Workspace ईमेल पता. उदाहरण के लिए, users/user@example.com/spaces/SPACE/spaceReadState.
    • कॉल करने वाले उपयोगकर्ता का यूज़र आईडी. उदाहरण के लिए, users/USER/spaces/SPACE/spaceReadState.

नीचे दिए गए उदाहरण में, स्पेस में कॉल करने वाले व्यक्ति की रीड स्टेट की जानकारी दी गई है:

Python

  1. अपनी वर्किंग डायरेक्ट्री में, chat_spaceReadState_get.py.
  2. chat_spaceReadState_get.py में यह कोड शामिल करें:

    from google_auth_oauthlib.flow import InstalledAppFlow
    from googleapiclient.discovery import build
    
    # Define your app's authorization scopes.
    # When modifying these scopes, delete the file token.json, if it exists.
    SCOPES = ["https://www.googleapis.com/auth/chat.users.readstate.readonly"]
    
    def main():
        '''
        Authenticates with Chat API via user credentials,
        then gets the space read state for the calling user.
        '''
    
        # Authenticate with Google Workspace
        # and get user authorization.
        flow = InstalledAppFlow.from_client_secrets_file(
                          'client_secrets.json', SCOPES)
        creds = flow.run_local_server()
    
        # Build a service endpoint for Chat API.
        chat = build('chat', 'v1', credentials=creds)
    
        # Use the service endpoint to call Chat API.
        result = chat.users().spaces().getSpaceReadState(
    
            # The space read state to get.
            #
            # Replace USER with the calling user's ID, Workspace email,
            # or the alias me.
            #
            # Replace SPACE with a space name.
            # Obtain the space name from the spaces resource of Chat API,
            # or from a space's URL.
            name='users/me/spaces/SPACE/spaceReadState'
    
          ).execute()
    
        # Prints the API's response.
        print(result)
    
    if __name__ == '__main__':
        main()
    
  3. कोड में, इन्हें बदलें:

    • SPACE: स्पेस का नाम, जो तो आपको यहां से spaces.list तरीका या स्पेस के यूआरएल से मिलेगी.
  4. अपनी वर्किंग डायरेक्ट्री में, सैंपल बनाएं और चलाएं:

    python3 chat_spaceReadState_get.py
    

Node.js

  1. अपनी वर्किंग डायरेक्ट्री में, chat_spaceReadState_get.js.
  2. chat_spaceReadState_get में यह कोड शामिल करें:

    const chat = require('@googleapis/chat');
    const {authenticate} = require('@google-cloud/local-auth');
    
    /**
    * Authenticates with Chat API via user credentials,
    * then gets the space read state for the calling user.
    * @return {!Promise<!Object>}
    */
    async function getSpaceReadState() {
    
      /**
      * Authenticate with Google Workspace
      * and get user authorization.
      */
      const scopes = [
        'https://www.googleapis.com/auth/chat.users.readstate.readonly',
      ];
    
      const authClient =
          await authenticate({scopes, keyfilePath: 'client_secrets.json'});
    
      /**
      * Build a service endpoint for Chat API.
      */
      const chatClient = await chat.chat({version: 'v1', auth: authClient});
    
      /**
      * Use the service endpoint to call Chat API.
      */
      return await chatClient.users.spaces.getSpaceReadState({
    
        /**
        * The space read state to get.
        *
        * Replace USER with the calling user's ID, Workspace email,
        * or the alias me.
        *
        * Replace SPACE with a space name.
        * Obtain the space name from the spaces resource of Chat API,
        * or from a space's URL.
        */
        name: 'users/me/spaces/SPACE/spaceReadState'
      });
    }
    
    /**
    * Use the service endpoint to call Chat API.
    */
    getSpaceReadState().then(console.log);
    
  3. कोड में, इन्हें बदलें:

    • SPACE: स्पेस का नाम, जो तो आपको यहां से spaces.list तरीका या स्पेस के यूआरएल से मिलेगी.
  4. अपनी वर्किंग डायरेक्ट्री में, सैंपल बनाएं और चलाएं:

    node chat_spaceReadState_get.js
    

Apps Script

इस उदाहरण में, Chat API को बेहतर चैट सेवा.

  1. chat.users.readstate.readonly की अनुमति का स्कोप जोड़ें Apps Script प्रोजेक्ट की appsscript.json फ़ाइल:

    "oauthScopes": [
      "https://www.googleapis.com/auth/chat.users.readstate.readonly"
    ]
    
  2. Apps Script प्रोजेक्ट के लिए, इस तरह का फ़ंक्शन जोड़ें कोड:

    /**
    * Authenticates with Chat API via user credentials,
    * then gets the space read state for the calling user.
    * @param {string} spaceReadStateName The resource name of the space read state.
    */
    function getSpaceReadState(spaceReadStateName) {
      try {
        Chat.Users.Spaces.getSpaceReadState(spaceReadStateName);
      } catch (err) {
        // TODO (developer) - Handle exception
        console.log('Failed to get read state with error %s', err.message);
      }
    }
    

Google Chat API, स्पेस के लिए तय की गई स्थिति पढ़ता है और उसे पढ़ता है इसका एक इंस्टेंस SpaceReadState संसाधन.