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

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

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

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

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

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

Node.js

  • कारोबारी या एंटरप्राइज़ Google Workspace खाता, जिसमें Google Chat का ऐक्सेस हो.

Python

  • कारोबारी या एंटरप्राइज़ Google Workspace खाता, जिसमें Google Chat का ऐक्सेस हो.

Java

  • कारोबारी या एंटरप्राइज़ Google Workspace खाता, जिसमें Google Chat का ऐक्सेस हो.

Apps Script

  • कारोबारी या एंटरप्राइज़ 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);
}

await main();

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 अनुमति का दायरा तय करें.
  • create तरीका संसाधन पर Space कॉल करें.
  • 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} की वैल्यू, ID Admin SDK के ग्राहक संसाधन से मिला है. 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.

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