Google Chat में कोई नाम वाला स्पेस बनाना

इस गाइड में, Google Chat API के Space रिसॉर्स पर create() तरीके का इस्तेमाल करके, नाम वाला स्पेस बनाने का तरीका बताया गया है.

नाम वाला स्पेस (जहां spaceType SPACE है) एक ऐसी जगह होती है जहां लोग मैसेज भेजते हैं, फ़ाइलें शेयर करते हैं, और साथ मिलकर काम करते हैं. नाम वाले स्पेस में Chat ऐप्लिकेशन शामिल किए जा सकते हैं. नाम वाले स्पेस के मैनेजर, एडमिन सेटिंग लागू कर सकते हैं. साथ ही, स्पेस के ब्यौरे में बदलाव कर सकते हैं. इसके अलावा, वे स्पेस में लोगों और ऐप्लिकेशन को जोड़ या हटा सकते हैं.

अलग-अलग तरह के Chat स्पेस (जैसे, डायरेक्ट मैसेज या ग्रुप मैसेज) बनाने के लिए, setUp() संसाधन पर Space तरीके का इस्तेमाल करें. इससे स्पेस बनाने के साथ-साथ सदस्यों को भी जोड़ा जा सकता है. ज़्यादा जानकारी के लिए, स्पेस सेट अप करें.

नाम वाला स्पेस बनाने के बाद, पुष्टि किया गया उपयोगकर्ता ही स्पेस का सदस्य होता है. स्पेस में सदस्यों को जोड़ने के लिए, आपको हर उस व्यक्ति या ऐप्लिकेशन के लिए Membership संसाधन पर create() तरीके को कॉल करना होगा जिसे आपको जोड़ना है. इसके अलावा, setUp() तरीके का इस्तेमाल करके, एक साथ कई सदस्यों को किसी स्पेस में जोड़ा जा सकता है.

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

Node.js

  • आपके पास Business या Enterprise वर्शन वाला Google Workspace खाता होना चाहिए. साथ ही, आपके पास Google Chat को ऐक्सेस करने की अनुमति होनी चाहिए.

Python

  • आपके पास Business या Enterprise वर्शन वाला Google Workspace खाता होना चाहिए. साथ ही, आपके पास Google Chat को ऐक्सेस करने की अनुमति होनी चाहिए.

Java

  • आपके पास Business या Enterprise वर्शन वाला Google Workspace खाता होना चाहिए. साथ ही, आपके पास Google Chat को ऐक्सेस करने की अनुमति होनी चाहिए.

Apps Script

  • आपके पास Business या Enterprise वर्शन वाला Google Workspace खाता होना चाहिए. साथ ही, आपके पास Google Chat को ऐक्सेस करने की अनुमति होनी चाहिए.

उपयोगकर्ता के तौर पर नाम वाला स्पेस बनाना

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

  • chat.spaces.create या chat.spaces ऑथराइज़ेशन स्कोप के बारे में बताएं.
  • CreateSpace() तरीके को कॉल करें. साथ ही, space को Space के इंस्टेंस के तौर पर पास करें. इसमें ये फ़ील्ड शामिल होने चाहिए:
    • spaceType को SPACE पर सेट करें.
    • displayName को स्पेस के उस नाम पर सेट किया जाता है जो लोगों को दिखता है.
    • इसके अलावा, अन्य एट्रिब्यूट भी सेट किए जा सकते हैं. जैसे:
      • spaceDetails- स्पेस के बारे में जानकारी और दिशा-निर्देश, जो लोगों को दिखते हैं.
      • predefinedPermissionSettings- स्पेस के लिए पहले से तय की गई अनुमतियां. उदाहरण के लिए, इसे इस तरह कॉन्फ़िगर किया जा सकता है कि सभी सदस्य या सिर्फ़ स्पेस मैनेजर मैसेज पोस्ट कर सकें.

यहां नाम वाला स्पेस बनाने का तरीका बताया गया है:

Node.js

chat/client-libraries/cloud/create-space-user-cred.js
import {createClientWithUserCredentials} from './authentication-utils.js';  const USER_AUTH_OAUTH_SCOPES = ['https://www.googleapis.com/auth/chat.spaces.create'];  // This sample shows how to create a named space with user credential async function main() {   // Create a client   const chatClient = await createClientWithUserCredentials(USER_AUTH_OAUTH_SCOPES);    // Initialize request argument(s)   const request = {     space: {       spaceType: 'SPACE',       // Replace DISPLAY_NAME here.       displayName: 'DISPLAY_NAME'     }   };    // Make the request   const response = await chatClient.createSpace(request);    // Handle the response   console.log(response); }  main().catch(console.error);

Python

chat/client-libraries/cloud/create_space_user_cred.py
from authentication_utils import create_client_with_user_credentials from google.apps import chat_v1 as google_chat  SCOPES = ["https://www.googleapis.com/auth/chat.spaces.create"]  def create_space_with_user_cred():     # Create a client     client = create_client_with_user_credentials(SCOPES)      # Initialize request argument(s)     request = google_chat.CreateSpaceRequest(         space = {             "space_type": 'SPACE',             # Replace DISPLAY_NAME here.             "display_name": 'DISPLAY_NAME'         }     )      # Make the request     response = client.create_space(request)      # Handle the response     print(response)  create_space_with_user_cred()

Java

chat/client-libraries/cloud/src/main/java/com/google/workspace/api/chat/samples/CreateSpaceUserCred.java
import com.google.chat.v1.ChatServiceClient; import com.google.chat.v1.CreateSpaceRequest; import com.google.chat.v1.Space;  // This sample shows how to create space with user credential. public class CreateSpaceUserCred {    private static final String SCOPE =     "https://www.googleapis.com/auth/chat.spaces.create";    public static void main(String[] args) throws Exception {     try (ChatServiceClient chatServiceClient =         AuthenticationUtils.createClientWithUserCredentials(           ImmutableList.of(SCOPE))) {       CreateSpaceRequest.Builder request = CreateSpaceRequest.newBuilder()         .setSpace(Space.newBuilder()           .setSpaceType(Space.SpaceType.SPACE)           // Replace DISPLAY_NAME here.           .setDisplayName("DISPLAY_NAME"));       Space response = chatServiceClient.createSpace(request.build());        System.out.println(JsonFormat.printer().print(response));     }   } }

Apps Script

chat/advanced-service/Main.gs
/**  * This sample shows how to create space with user credential  *   * It relies on the OAuth2 scope 'https://www.googleapis.com/auth/chat.spaces.create'  * referenced in the manifest file (appsscript.json).  */ function createSpaceUserCred() {   // Initialize request argument(s)   const space = {     spaceType: 'SPACE',     // TODO(developer): Replace DISPLAY_NAME here     displayName: 'DISPLAY_NAME'   };    // Make the request   const response = Chat.Spaces.create(space);    // Handle the response   console.log(response); }

Chat ऐप्लिकेशन के तौर पर नाम वाला स्पेस बनाना

ऐप्लिकेशन की पुष्टि करने के लिए, एडमिन की एक बार की अनुमति ज़रूरी है.

ऐप्लिकेशन की पुष्टि की सुविधा वाले स्पेस में किसी उपयोगकर्ता को न्योता भेजने या उसे जोड़ने के लिए, अपने अनुरोध में यह जानकारी शामिल करें:

  • chat.app.spaces.create या chat.app.spaces अनुमति का दायरा तय करें.
  • Space संसाधन पर create तरीके को कॉल करें.
  • spaceType को SPACE पर सेट करें.
  • स्पेस का वह नाम सेट करें जो लोगों को दिखता है displayName. यहां दिए गए उदाहरण में, displayName को API-made पर सेट किया गया है.
  • customer फ़ील्ड का इस्तेमाल करके, Google Workspace डोमेन का ग्राहक आईडी डालें.
  • इसके अलावा, स्पेस के अन्य एट्रिब्यूट भी सेट किए जा सकते हैं. जैसे, spaceDetails (उपयोगकर्ता को दिखने वाला ब्यौरा और स्पेस के लिए दिशा-निर्देशों का सेट).

Chat API को कॉल करने वाली स्क्रिप्ट लिखना

यहां नाम वाला स्पेस बनाने का तरीका बताया गया है:

Python

  1. अपनी वर्किंग डायरेक्ट्री में, chat_space_create_named_app.py नाम की एक फ़ाइल बनाएं.
  2. chat_space_create_named_app.py में यह कोड शामिल करें:

    from google.oauth2 import service_account from apiclient.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.app.spaces.create"]  def main():     '''     Authenticates with Chat API using app authentication,     then creates a Chat space.     '''      # Specify service account details.     creds = (         service_account.Credentials.from_service_account_file('credentials.json')         .with_scopes(SCOPES)     )      # Build a service endpoint for Chat API.     chat = build('chat', 'v1', credentials=creds)      # Use the service endpoint to call Chat API.     result = chat.spaces().create(        # Details about the space to create.       body = {          # To create a named space, set spaceType to SPACE.         'spaceType': 'SPACE',          # The user-visible name of the space.         'displayName': 'API-made',          # The customer ID of the Workspace domain.         'customer': 'CUSTOMER'       }        ).execute()      # Prints details about the created space.     print(result)  if __name__ == '__main__':     main() 
  3. कोड में, इनकी जगह ये डालें:

    • CUSTOMER: यह स्पेस के डोमेन का ग्राहक आईडी है. यह customer/{customer} फ़ॉर्मैट में होता है. इसमें {customer}, Admin SDK customer resource का ID होता है. Chat ऐप्लिकेशन के साथ-साथ Google Workspace संगठन में स्पेस बनाने के लिए, customers/my_customer का इस्तेमाल करें.
  4. अपनी वर्किंग डायरेक्ट्री में, सैंपल बनाएं और उसे चलाएं:

    python3 chat_space_create_named_app.py

Google Chat में स्पेस खोलना

स्पेस पर जाने के लिए, स्पेस के संसाधन आईडी का इस्तेमाल करके स्पेस का यूआरएल बनाएं. Google Chat के जवाब में, स्पेस name का संसाधन आईडी देखा जा सकता है. उदाहरण के लिए, अगर आपके स्पेस का name spaces/1234567 है, तो स्पेस पर जाने के लिए इस यूआरएल का इस्तेमाल करें: https://mail.google.com/chat/u/0/#chat/space/1234567.

सीमाएं और ज़रूरी बातें

  • ऐप्लिकेशन की पुष्टि करने की सुविधा का इस्तेमाल करके स्पेस बनाने पर, पुष्टि करने वाले Chat ऐप्लिकेशन को स्पेस के सदस्य के तौर पर जोड़ा जाता है. हालांकि, उपयोगकर्ता की पुष्टि करने की सुविधा के उलट, इसे स्पेस मैनेजर के तौर पर नहीं जोड़ा जाता. डिफ़ॉल्ट रूप से, स्पेस के सभी सदस्य Chat ऐप्लिकेशन को हटा सकते हैं. अगर आपको सिर्फ़ स्पेस मैनेजर को Chat ऐप्लिकेशन हटाने की अनुमति देनी है, तो permissionSettings.manageApps को managersAllowed पर सेट करें.