यह गाइड बताती है किgetThreadReadState
किसी उपयोगकर्ता की गतिविधि के बारे में जानकारी पाने के लिए, Google Chat API का ThreadReadState
संसाधन
मैसेज थ्रेड में 'पढ़ा गया' स्टेटस सेट करें. किसी मैसेज में मैसेज की स्थिति जानने के लिए
अंतरिक्ष, देखें
उपयोगकर्ता के स्पेस के पढ़े जाने की स्थिति के बारे में जानकारी पाएं.
कॉन्टेंट बनाने
ThreadReadState
संसाधन
एक सिंगलटन संसाधन है, जो
Google Chat के मैसेज थ्रेड में, उपयोगकर्ता का आखिरी बार पढ़ा गया मैसेज.
ज़रूरी शर्तें
Python
- कारोबार या एंटरप्राइज़ Google Workspace खाता, जिसके पास इसका ऐक्सेस है Google Chat.
- अपना एनवायरमेंट सेट अप करें:
- Google Cloud प्रोजेक्ट बनाएं.
- उस स्क्रीन को कॉन्फ़िगर करें जहां OAuth के लिए सहमति दी जाती है.
- Google Chat API को चालू और कॉन्फ़िगर करें. आइकॉन और ब्यौरा जोड़ें.
- इंस्टॉल करें Python Google API क्लाइंट लाइब्रेरी.
-
डेस्कटॉप ऐप्लिकेशन के लिए OAuth क्लाइंट आईडी क्रेडेंशियल बनाएं. सैंपल को चलाने के लिए
गाइड के साथ क्रेडेंशियल को
client_secrets.json
नाम वाली JSON फ़ाइल के तौर पर लोकल डायरेक्ट्री.
- अनुमति देने का ऐसा स्कोप चुनें जो उपयोगकर्ता की पुष्टि करने की सुविधा देता हो.
Node.js
- कारोबार या एंटरप्राइज़ Google Workspace खाता, जिसके पास इसका ऐक्सेस है Google Chat.
- अपना एनवायरमेंट सेट अप करें:
- Google Cloud प्रोजेक्ट बनाएं.
- उस स्क्रीन को कॉन्फ़िगर करें जहां OAuth के लिए सहमति दी जाती है.
- Google Chat API को चालू और कॉन्फ़िगर करें. आइकॉन और ब्यौरा जोड़ें.
- इंस्टॉल करें Node.js Google API क्लाइंट लाइब्रेरी.
-
डेस्कटॉप ऐप्लिकेशन के लिए OAuth क्लाइंट आईडी क्रेडेंशियल बनाएं. सैंपल को चलाने के लिए
गाइड के साथ क्रेडेंशियल को
client_secrets.json
नाम वाली JSON फ़ाइल के तौर पर लोकल डायरेक्ट्री.
- अनुमति देने का ऐसा स्कोप चुनें जो उपयोगकर्ता की पुष्टि करने की सुविधा देता हो.
Apps Script
- कारोबार या एंटरप्राइज़ Google Workspace खाता, जिसके पास इसका ऐक्सेस है Google Chat.
- अपना एनवायरमेंट सेट अप करें:
- Google Cloud प्रोजेक्ट बनाएं.
- उस स्क्रीन को कॉन्फ़िगर करें जहां OAuth के लिए सहमति दी जाती है.
- Google Chat API को चालू और कॉन्फ़िगर करें. आइकॉन और ब्यौरा जोड़ें.
- स्टैंडअलोन Apps Script प्रोजेक्ट बनाना, और बेहतर चैट सेवा चालू करें.
- अनुमति देने का ऐसा स्कोप चुनें जो उपयोगकर्ता की पुष्टि करने की सुविधा देता हो.
कॉल करने वाले व्यक्ति की थ्रेड को पढ़ने की स्थिति देखना
मैसेज थ्रेड में उपयोगकर्ता के पढ़े जाने की स्थिति के बारे में जानकारी पाने के लिए, जिन्हें आपके अनुरोध में शामिल किया गया है:
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
- अपनी वर्किंग डायरेक्ट्री में,
chat_threadReadState_get.py
. 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()
कोड में, इन्हें बदलें:
SPACE
: स्पेस का नाम, जो तो आपको यहां सेspaces.list
तरीका या स्पेस के यूआरएल से मिलेगी.THREAD
: उस थ्रेड का नाम जो तो आपको यहां सेspaces.messages.get
तरीका Chat API में.
अपनी वर्किंग डायरेक्ट्री में, सैंपल बनाएं और चलाएं:
python3 chat_threadReadState_get.py
Node.js
- अपनी वर्किंग डायरेक्ट्री में,
chat_threadReadState_get.js
. 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);
कोड में, इन्हें बदलें:
SPACE
: स्पेस का नाम, जो तो आपको यहां सेspaces.list
तरीका या स्पेस के यूआरएल से मिलेगी.THREAD
: उस थ्रेड का नाम जो तो आपको यहां सेspaces.messages.get
तरीका Chat API में.
अपनी वर्किंग डायरेक्ट्री में, सैंपल बनाएं और चलाएं:
node chat_threadReadState_get.js
Apps Script
इस उदाहरण में, Chat API को बेहतर चैट सेवा.
chat.users.readstate.readonly
की अनुमति का स्कोप जोड़ें Apps Script प्रोजेक्ट कीappsscript.json
फ़ाइल:"oauthScopes": [ "https://www.googleapis.com/auth/chat.users.readstate.readonly" ]
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
संसाधन.
मिलते-जुलते विषय
- कॉल करने वाले उपयोगकर्ता के लिए, स्पेस का डेटा पढ़ने की स्थिति अपडेट करना.
- कॉल करने वाले उपयोगकर्ता के स्पेस का डेटा पढ़ने की स्थिति जानना.