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

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

कॉन्टेंट बनाने ThreadReadState संसाधन एक सिंगलटन संसाधन है, जो 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 बताएं अनुमति का दायरा.
  • कॉल करें getThreadReadState तरीका पूरी तरह कैसे ThreadReadState संसाधन.
  • मैसेज पाने के लिए, थ्रेड के रीड स्टेटस का name पास करें. इसमें यूज़र आईडी या उपनाम और स्पेस आईडी. थ्रेड को पढ़े जाने की स्थिति से सिर्फ़ उसे पढ़ा जा सकता है कॉल करने वाले उपयोगकर्ता की स्थिति, जिसे किसी एक फ़ॉलो किया जा रहा है:
    • me का दूसरा ईमेल पता. उदाहरण के लिए, users/me/spaces/SPACE/threads/THREAD/threadReadState.
    • कॉल करने वाले उपयोगकर्ता का Workspace ईमेल पता. उदाहरण के लिए, users/user@example.com/spaces/SPACEthreads/THREAD/threadReadState.
    • कॉल करने वाले उपयोगकर्ता का यूज़र आईडी. उदाहरण के लिए, users/USER/spaces/SPACE/threads/THREAD/threadReadState.

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

Python

  1. अपनी वर्किंग डायरेक्ट्री में, chat_threadReadState_get.py.
  2. chat_threadReadState_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 thread 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().threads().getThreadReadState(
    
            # The thread 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.
            #
            # Replace THREAD with a thread name.
            # Obtain the thread name from the messages resource of Chat API.
            name='users/me/spaces/SPACE/threads/THREAD/threadReadState'
    
          ).execute()
    
        # Prints the API's response.
        print(result)
    
    if __name__ == '__main__':
        main()
    
  3. कोड में, इन्हें बदलें:

    • SPACE: स्पेस का नाम, जो तो आपको यहां से spaces.list तरीका या स्पेस के यूआरएल से मिलेगी.

    • THREAD: उस थ्रेड का नाम जो तो आपको यहां से spaces.messages.get तरीका Chat API में.

  4. अपनी वर्किंग डायरेक्ट्री में, सैंपल बनाएं और चलाएं:

    python3 chat_threadReadState_get.py
    

Node.js

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

    const chat = require('@googleapis/chat');
    const {authenticate} = require('@google-cloud/local-auth');
    
    /**
    * Authenticates with Chat API via user credentials,
    * then gets the thread read state for the calling user.
    * @return {!Promise<!Object>}
    */
    async function getThreadReadState() {
    
      /**
      * 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.threads.getThreadReadState({
    
        /**
        * The thread 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/threads/THREADS/threadReadState'
      });
    }
    
    /**
    * Use the service endpoint to call Chat API.
    */
    getThreadReadState().then(console.log);
    
  3. कोड में, इन्हें बदलें:

    • SPACE: स्पेस का नाम, जो तो आपको यहां से spaces.list तरीका या स्पेस के यूआरएल से मिलेगी.

    • THREAD: उस थ्रेड का नाम जो तो आपको यहां से spaces.messages.get तरीका Chat API में.

  4. अपनी वर्किंग डायरेक्ट्री में, सैंपल बनाएं और चलाएं:

    node chat_threadReadState_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 thread read state for the calling user.
    * @param {string} threadReadStateName The resource name of the thread read state.
    */
    function getThreadReadState(threadReadStateName) {
      try {
        Chat.Users.Spaces.Threads.getThreadReadState(threadReadStateName);
      } catch (err) {
        // TODO (developer) - Handle exception
        console.log('Failed to get read state with error %s', err.message);
      }
    }
    

Google Chat API, तय की गई थ्रेड के बारे में पढ़े जाने की स्थिति के बारे में बताता है और उसे वापस भेजता है इसका एक इंस्टेंस ThreadReadState संसाधन.