এই নির্দেশিকাটি ব্যাখ্যা করে যে কীভাবে Google Chat API এর SpaceReadState
রিসোর্সে getSpaceReadState
পদ্ধতি ব্যবহার করতে হয় একটি স্পেসের মধ্যে ব্যবহারকারীর পড়ার অবস্থা সম্পর্কে বিশদ পেতে। একটি বার্তা থ্রেডে একটি বার্তার পঠিত অবস্থা পেতে, ব্যবহারকারীর থ্রেড পড়ার অবস্থা সম্পর্কে বিশদ বিবরণ পান দেখুন৷
SpaceReadState
রিসোর্স হল একটি সিঙ্গলটন রিসোর্স যা Google চ্যাট স্পেসে একজন নির্দিষ্ট ব্যবহারকারীর শেষ পঠিত বার্তার বিবরণ উপস্থাপন করে।
পূর্বশর্ত
পাইথন
- Google Chat অ্যাক্সেস সহ একটি ব্যবসা বা এন্টারপ্রাইজ Google Workspace অ্যাকাউন্ট।
- আপনার পরিবেশ সেট আপ করুন:
- একটি Google ক্লাউড প্রকল্প তৈরি করুন ।
- OAuth সম্মতি স্ক্রিন কনফিগার করুন ।
- আপনার চ্যাট অ্যাপের জন্য একটি নাম, আইকন এবং বিবরণ সহ Google Chat API সক্রিয় এবং কনফিগার করুন ।
- পাইথন গুগল এপিআই ক্লায়েন্ট লাইব্রেরি ইনস্টল করুন।
- একটি ডেস্কটপ অ্যাপ্লিকেশনের জন্য OAuth ক্লায়েন্ট আইডি শংসাপত্র তৈরি করুন । এই নির্দেশিকায় নমুনাটি চালানোর জন্য, আপনার স্থানীয় ডিরেক্টরিতে
client_secrets.json
নামে একটি JSON ফাইল হিসাবে শংসাপত্রগুলি সংরক্ষণ করুন৷
- ব্যবহারকারীর প্রমাণীকরণ সমর্থন করে এমন একটি অনুমোদনের সুযোগ বেছে নিন ।
Node.js
- Google Chat অ্যাক্সেস সহ একটি ব্যবসা বা এন্টারপ্রাইজ Google Workspace অ্যাকাউন্ট।
- আপনার পরিবেশ সেট আপ করুন:
- একটি Google ক্লাউড প্রকল্প তৈরি করুন ।
- OAuth সম্মতি স্ক্রিন কনফিগার করুন ।
- আপনার চ্যাট অ্যাপের জন্য একটি নাম, আইকন এবং বিবরণ সহ Google Chat API সক্রিয় এবং কনফিগার করুন ।
- Node.js Google API ক্লায়েন্ট লাইব্রেরি ইনস্টল করুন।
- একটি ডেস্কটপ অ্যাপ্লিকেশনের জন্য OAuth ক্লায়েন্ট আইডি শংসাপত্র তৈরি করুন । এই নির্দেশিকায় নমুনাটি চালানোর জন্য, আপনার স্থানীয় ডিরেক্টরিতে
client_secrets.json
নামে একটি JSON ফাইল হিসাবে শংসাপত্রগুলি সংরক্ষণ করুন৷
- ব্যবহারকারীর প্রমাণীকরণ সমর্থন করে এমন একটি অনুমোদনের সুযোগ বেছে নিন ।
অ্যাপস স্ক্রিপ্ট
- Google Chat অ্যাক্সেস সহ একটি ব্যবসা বা এন্টারপ্রাইজ Google Workspace অ্যাকাউন্ট।
- আপনার পরিবেশ সেট আপ করুন:
- একটি Google ক্লাউড প্রকল্প তৈরি করুন ।
- OAuth সম্মতি স্ক্রিন কনফিগার করুন ।
- আপনার চ্যাট অ্যাপের জন্য একটি নাম, আইকন এবং বিবরণ সহ Google Chat API সক্রিয় এবং কনফিগার করুন ।
- একটি স্বতন্ত্র অ্যাপস স্ক্রিপ্ট প্রকল্প তৈরি করুন এবং উন্নত চ্যাট পরিষেবা চালু করুন।
- ব্যবহারকারীর প্রমাণীকরণ সমর্থন করে এমন একটি অনুমোদনের সুযোগ বেছে নিন ।
কলিং ব্যবহারকারীর স্থান পড়ার অবস্থা পান
একটি স্থানের মধ্যে একজন ব্যবহারকারীর পড়ার অবস্থা সম্পর্কে বিশদ বিবরণ পেতে, আপনার অনুরোধে নিম্নলিখিতগুলি অন্তর্ভুক্ত করুন:
-
chat.users.readstate
বাchat.users.readstate.readonly
অনুমোদনের সুযোগ নির্দিষ্ট করুন। -
SpaceReadState
রিসোর্সেgetSpaceReadState
পদ্ধতিতে কল করুন। - পাওয়ার জন্য স্পেস রিড স্টেটের
name
পাস করুন, যার মধ্যে একটি ইউজার আইডি বা উপনাম এবং একটি স্পেস আইডি রয়েছে। স্পেস রিড স্টেট পাওয়া শুধুমাত্র কলিং ব্যবহারকারীর রিড স্টেট পাওয়াকে সমর্থন করে, যা নিম্নলিখিতগুলির একটি সেট করে নির্দিষ্ট করা যেতে পারে:-
me
উপনাম. উদাহরণস্বরূপ,users/me/spaces/ SPACE /spaceReadState
। - কলিং ব্যবহারকারীর ওয়ার্কস্পেস ইমেল ঠিকানা। উদাহরণস্বরূপ,
users/user@example.com/spaces/ SPACE /spaceReadState
। - কলিং ব্যবহারকারীর ব্যবহারকারী আইডি। উদাহরণস্বরূপ,
users/ USER /spaces/ SPACE /spaceReadState
।
-
নিম্নলিখিত উদাহরণটি কলিং ব্যবহারকারীর স্থান পড়ার অবস্থা পায়:
পাইথন
- আপনার কাজের ডিরেক্টরিতে,
chat_spaceReadState_get.py
নামে একটি ফাইল তৈরি করুন। 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()
কোডে, নিম্নলিখিতগুলি প্রতিস্থাপন করুন:
-
SPACE
: একটি স্থানের নাম, যা আপনি Chat API-এরspaces.list
পদ্ধতি থেকে বা একটি স্থানের URL থেকে পেতে পারেন।
-
আপনার কাজের ডিরেক্টরিতে, নমুনা তৈরি করুন এবং চালান:
python3 chat_spaceReadState_get.py
Node.js
- আপনার কাজের ডিরেক্টরিতে,
chat_spaceReadState_get.js
নামে একটি ফাইল তৈরি করুন। 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);
কোডে, নিম্নলিখিতগুলি প্রতিস্থাপন করুন:
-
SPACE
: একটি স্থানের নাম, যা আপনি Chat API-এরspaces.list
পদ্ধতি থেকে বা একটি স্থানের URL থেকে পেতে পারেন।
-
আপনার কাজের ডিরেক্টরিতে, নমুনা তৈরি করুন এবং চালান:
node chat_spaceReadState_get.js
অ্যাপস স্ক্রিপ্ট
এই উদাহরণটি উন্নত চ্যাট পরিষেবা ব্যবহার করে চ্যাট API-কে কল করে।
Apps Script প্রকল্পের
appsscript.json
ফাইলেchat.users.readstate.readonly
অনুমোদনের সুযোগ যোগ করুন:"oauthScopes": [ "https://www.googleapis.com/auth/chat.users.readstate.readonly" ]
অ্যাপস স্ক্রিপ্ট প্রকল্পের কোডে এইরকম একটি ফাংশন যোগ করুন:
/** * 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
রিসোর্সের একটি উদাহরণ প্রদান করে।