यह गाइड बताती है किupdateSpaceReadState
स्पेस को 'पढ़ा गया' या 'नहीं पढ़ा गया' के तौर पर मार्क करने के लिए, Google Chat API का SpaceReadState
संसाधन.
कॉन्टेंट बनाने
SpaceReadState
संसाधन
एक सिंगलटन संसाधन है, जो
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
की अनुमति के दायरे के बारे में बताएं.- कॉल करें
updateSpaceReadState
तरीका पूरी तरह कैसेSpaceReadState
संसाधन. - मैसेज पाने के लिए, स्पेस का
name
पास करें. इसमें यूज़र आईडी या उपनाम और स्पेस आईडी. स्पेस का रीड ओनली स्टेटस सेट करने पर, सिर्फ़ उस टेक्स्ट को पढ़ा जा सकता है कॉल करने वाले उपयोगकर्ता की स्थिति, जिसे किसी एक फ़ॉलो किया जा रहा है:me
का दूसरा ईमेल पता. उदाहरण के लिए,users/me/spaces/SPACE/spaceReadState
.- कॉल करने वाले उपयोगकर्ता का Workspace ईमेल पता. उदाहरण के लिए,
users/user@example.com/spaces/SPACE/spaceReadState
. - कॉल करने वाले उपयोगकर्ता का यूज़र आईडी. उदाहरण के लिए,
users/USER/spaces/SPACE/spaceReadState
.
updateMask
को पास करें. इससे, स्पेस के पढ़े जाने की स्थिति के बारे में पता चलता है अपडेट का इस्तेमाल करें, जो नीचे दिए गए फ़ील्ड पाथ के साथ काम करता है:lastReadTime
: वह समय जब उपयोगकर्ता के स्पेस को पढ़ने की स्थिति को अपडेट किया गया था. आम तौर पर, यह या तो आखिरी बार पढ़े गए मैसेज के टाइमस्टैंप से मेल खाता है, या उपयोगकर्ता के बताए गए टाइमस्टैंप से, स्पेस. जबlastReadTime
, नए मैसेज बनाने के समय से पहले होता है, तो यूज़र इंटरफ़ेस में स्पेस 'नहीं पढ़ा गया' के तौर पर दिखता है. स्पेस को 'पढ़ा गया' के तौर पर मार्क करने के लिए, इसे सेट करेंlastReadTime
का इस्तेमाल, नए मैसेज बनाने के बाद की वैल्यू के मुकाबले (ज़्यादा) किया गया समय.lastReadTime
को नए मैसेज बनाने के समय के हिसाब से तय किया गया है. ध्यान दें कि स्पेस में पढ़ने की स्थिति से, सिर्फ़ उन मैसेज की पढ़ने की स्थिति पर असर पड़ता है जिनमें वे स्पेस की टॉप-लेवल की बातचीत में मौजूद हों. थ्रेड में दिए गए जवाब इन पर इस टाइमस्टैंप का कोई असर नहीं होता. इसके बजाय, थ्रेड के पढ़े गए स्टेटस पर भरोसा करें.
नीचे दिए गए उदाहरण में, स्पेस में शामिल होने के लिए, कॉल करने वाले व्यक्ति की स्थिति को अपडेट किया गया है:
Python
- अपनी वर्किंग डायरेक्ट्री में,
chat_spaceReadState_update.py
. chat_spaceReadState_update.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"] def main(): ''' Authenticates with Chat API via user credentials, then updates 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().updateSpaceReadState( # The space read state to update. # # 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', updateMask='lastReadTime', body={'lastReadTime': f'{datetime.datetime(2000, 1, 3).isoformat()}Z'} ).execute() # Prints the API's response. print(result) if __name__ == '__main__': main()
कोड में, इन्हें बदलें:
SPACE
: स्पेस का नाम, जो तो आपको यहां सेspaces.list
तरीका या स्पेस के यूआरएल से मिलेगी.
अपनी वर्किंग डायरेक्ट्री में, सैंपल बनाएं और चलाएं:
python3 chat_spaceReadState_update.py
Node.js
- अपनी वर्किंग डायरेक्ट्री में,
chat_spaceReadState_update.js
. chat_spaceReadState_update
में यह कोड शामिल करें:const chat = require('@googleapis/chat'); const {authenticate} = require('@google-cloud/local-auth'); /** * Authenticates with Chat API via user credentials, * then updates the space read state for the calling user. * @return {!Promise<!Object>} */ async function updateSpaceReadState() { /** * Authenticate with Google Workspace * and get user authorization. */ const scopes = [ 'https://www.googleapis.com/auth/chat.users.readstate', ]; 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.updateSpaceReadState({ /** * The space read state to update. * * 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', updateMask: 'lastReadTime', requestBody: { lastReadTime: '{datetime.datetime(2000, 1, 3).isoformat()}Z' } }); } /** * Use the service endpoint to call Chat API. */ getSpaceReadState().then(console.log);
कोड में, इन्हें बदलें:
SPACE
: स्पेस का नाम, जो तो आपको यहां सेspaces.list
तरीका या स्पेस के यूआरएल से मिलेगी.
अपनी वर्किंग डायरेक्ट्री में, सैंपल बनाएं और चलाएं:
node chat_spaceReadState_update.js
Apps Script
इस उदाहरण में, Chat API को बेहतर चैट सेवा.
chat.users.readstate
की अनुमति का स्कोप जोड़ें Apps Script प्रोजेक्ट कीappsscript.json
फ़ाइल:"oauthScopes": [ "https://www.googleapis.com/auth/chat.users.readstate" ]
Apps Script प्रोजेक्ट के लिए, इस तरह का फ़ंक्शन जोड़ें कोड:
/** * Authenticates with Chat API via user credentials, * then updates the space read state for the calling user. * @param {string} spaceReadStateName The resource name of the space read state. */ function updateSpaceReadState(spaceReadStateName) { try { const time = new Date('January 1, 2000')).toJSON(); const body = {'lastReadTime': time}; Chat.Users.Spaces.updateSpaceReadState(spaceReadStateName, body); } catch (err) { // TODO (developer) - Handle exception console.log('Failed to update read state with error %s', err.message); } }
Google Chat API, स्पेस के लिए तय किए गए रीड स्टेटस को अपडेट करता है और उसे अपडेट करता है
इसका एक इंस्टेंस
SpaceReadState
संसाधन.
मिलते-जुलते विषय
- कॉल करने वाले उपयोगकर्ता के स्पेस का डेटा पढ़ने की स्थिति जानना.
- कॉल करने वाले उपयोगकर्ता की थ्रेड को पढ़ने की स्थिति जानना.