इस गाइड में बताया गया है कि उन ग्रुप चैट को कैसे खोजें जिनमें कॉल करने वाला व्यक्ति और अन्य लोगों की तय की गई सूची शामिल है. Google Chat API में, ग्रुप चैट Space ऐसे संसाधन होते हैं जिनमें spaceType को GROUP_CHAT पर सेट किया जाता है. ग्रुप चैट ढूंढने के लिए, Space रिसोर्स पर findGroupChats(RPC, REST) तरीके का इस्तेमाल करें.
ज़रूरी शर्तें
Node.js
- आपके पास Business या Enterprise वर्शन वाला Google Workspace खाता होना चाहिए. साथ ही, आपके पास Google Chat को ऐक्सेस करने की अनुमति होनी चाहिए.
- अपना एनवायरमेंट सेट अप करें:
- Google Cloud प्रोजेक्ट बनाएं.
- उस स्क्रीन को कॉन्फ़िगर करें जहां OAuth के लिए सहमति दी जाती है.
- अपने Chat ऐप्लिकेशन के लिए, नाम, आइकॉन, और जानकारी के साथ Google Chat API चालू करें और उसे कॉन्फ़िगर करें.
- Node.js Cloud Client Library इंस्टॉल करें.
- ऑथराइज़ेशन स्कोप चुनें.
Python
- आपके पास Business या Enterprise वर्शन वाला Google Workspace खाता होना चाहिए. साथ ही, आपके पास Google Chat को ऐक्सेस करने की अनुमति होनी चाहिए.
- अपना एनवायरमेंट सेट अप करें:
- Google Cloud प्रोजेक्ट बनाएं.
- उस स्क्रीन को कॉन्फ़िगर करें जहां OAuth के लिए सहमति दी जाती है.
- अपने Chat ऐप्लिकेशन के लिए, नाम, आइकॉन, और जानकारी के साथ Google Chat API चालू करें और उसे कॉन्फ़िगर करें.
- Python Cloud Client Library इंस्टॉल करें.
- ऑथराइज़ेशन स्कोप चुनें.
Java
- आपके पास Business या Enterprise वर्शन वाला Google Workspace खाता होना चाहिए. साथ ही, आपके पास Google Chat को ऐक्सेस करने की अनुमति होनी चाहिए.
- अपना एनवायरमेंट सेट अप करें:
- Google Cloud प्रोजेक्ट बनाएं.
- उस स्क्रीन को कॉन्फ़िगर करें जहां OAuth के लिए सहमति दी जाती है.
- अपने Chat ऐप्लिकेशन के लिए, नाम, आइकॉन, और जानकारी के साथ Google Chat API चालू करें और उसे कॉन्फ़िगर करें.
- Java Cloud Client Library इंस्टॉल करें.
- ऑथराइज़ेशन स्कोप चुनें.
Apps Script
- आपके पास Business या Enterprise वर्शन वाला Google Workspace खाता होना चाहिए. साथ ही, आपके पास Google Chat को ऐक्सेस करने की अनुमति होनी चाहिए.
- अपना एनवायरमेंट सेट अप करें:
- Google Cloud प्रोजेक्ट बनाएं.
- उस स्क्रीन को कॉन्फ़िगर करें जहां OAuth के लिए सहमति दी जाती है.
- अपने Chat ऐप्लिकेशन के लिए, नाम, आइकॉन, और जानकारी के साथ Google Chat API चालू करें और उसे कॉन्फ़िगर करें.
- Apps Script का स्टैंडअलोन प्रोजेक्ट बनाएं और ऐडवांस चैट सेवा चालू करें.
- ऑथराइज़ेशन स्कोप चुनें.
कोई ग्रुप चैट ढूंढना
Google Chat में ग्रुप चैट ढूंढने के लिए, अपने अनुरोध में यह जानकारी शामिल करें:
- अनुमति का दायरा:
chat.memberships.readonlyयाchat.memberships. - अन्य उपयोगकर्ताओं के संसाधन नाम पास करके,
findGroupChats(RPC, REST) तरीके को कॉल करें.
यहां, कुछ खास सदस्यों के साथ की गई ग्रुप चैट ढूंढने का तरीका बताया गया है:
Node.js
/**
* This sample shows how to find a group chat with specific members.
*
* It relies on the @google-apps/chat npm package.
*/
// Read the documentation for more details:
// https://developers.google.com/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.FindGroupChats
const {ChatServiceClient} = require('@google-apps/chat');
const {auth} = require('google-auth-library');
async function main() {
// Create a client
const chatClient = new ChatServiceClient({
authClient: await auth.getClient({
scopes: ['https://www.googleapis.com/auth/chat.memberships.readonly']
})
});
// The users to find a group chat with.
// Don't include the caller.
const user = [
'users/123456789',
'users/987654321'
];
// Create the request
const request = {
user: user
};
// Call the API
const response = await chatClient.findGroupChats(request);
// Handle the response
if (response.spaces && response.spaces.length > 0) {
console.log('Found group chat:', response.spaces[0].name);
} else {
console.log('No group chat found.');
}
}
main().catch(console.error);
Python
"""
This sample shows how to find a group chat with specific members.
"""
from google.apps import chat_v1
import google.auth
# Read the documentation for more details:
# https://developers.google.com/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.FindGroupChats
def find_group_chat():
# Create a client
scopes = ["https://www.googleapis.com/auth/chat.memberships.readonly"]
credentials, _ = google.auth.default(scopes=scopes)
client = chat_v1.ChatServiceClient(credentials=credentials)
# The users to find a group chat with.
# Don't include the caller.
user_list = [
"users/123456789",
"users/987654321"
]
# Create the request
request = chat_v1.FindGroupChatsRequest(
user=user_list
)
# Call the API
response = client.find_group_chats(request)
# Handle the response
if response.spaces:
print(f"Found group chat: {response.spaces[0].name}")
else:
print("No group chat found.")
if __name__ == "__main__":
find_group_chat()
Java
/**
* This sample shows how to find a group chat with specific members.
*/
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.chat.v1.ChatServiceClient;
import com.google.chat.v1.ChatServiceSettings;
import com.google.chat.v1.FindGroupChatsRequest;
import com.google.chat.v1.FindGroupChatsResponse;
import java.util.Arrays;
import java.util.List;
// Read the documentation for more details:
// https://developers.google.com/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.FindGroupChats
public class FindGroupChat {
public static void main(String[] args) throws Exception {
GoogleCredentials credentials = GoogleCredentials.getApplicationDefault()
.createScoped(Arrays.asList("https://www.googleapis.com/auth/chat.memberships.readonly"));
ChatServiceSettings settings = ChatServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credentials))
.build();
try (ChatServiceClient chatServiceClient = ChatServiceClient.create(settings)) {
List<String> users = Arrays.asList(
"users/123456789",
"users/987654321"
);
FindGroupChatsRequest request = FindGroupChatsRequest.newBuilder()
.addAllUser(users)
.build();
FindGroupChatsResponse response = chatServiceClient.findGroupChats(request);
if (!response.getSpacesList().isEmpty()) {
System.out.printf("Found group chat: %s\n", response.getSpacesList().get(0).getName());
} else {
System.out.println("No group chat found.");
}
}
}
}
Apps Script
/**
* This sample shows how to find a group chat with specific members.
*/
// Read the documentation for more details:
// https://developers.google.com/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.FindGroupChats
function findGroupChat() {
// The users to find a group chat with.
// Don't include the caller.
const users = [
'users/123456789',
'users/987654321'
];
try {
// Call the API
// In Apps Script, query parameters are passed as optional arguments
const response = Chat.Spaces.findGroupChats({
user: users
});
if (response.spaces && response.spaces.length > 0) {
console.log('Found group chat: ' + response.spaces[0].name);
} else {
console.log('No group chat found.');
}
} catch (err) {
// Handle error
console.log('Failed to find group chat: ' + err.message);
}
}
इस सैंपल को चलाने के लिए, उपयोगकर्ता के संसाधन के नामों को मान्य उपयोगकर्ता आईडी से बदलें. People API या Directory API से, उपयोगकर्ता आईडी पाए जा सकते हैं.
Chat API, FindGroupChatsResponse (RPC, REST) का एक इंस्टेंस दिखाता है. इसमें मिले स्पेस की सूची होती है.
जानकारी के साथ कोई ग्रुप चैट ढूंढना
डिफ़ॉल्ट रूप से, findGroupChats
(RPC,
REST) Space ऑब्जेक्ट दिखाता है. इनमें सिर्फ़ name फ़ील्ड होता है. यह फ़ील्ड, spaces/SPACE_NAME फ़ॉर्मैट में होता है. स्पेस के बारे में ज़्यादा जानकारी पाने के लिए, जैसे कि displayName, spaceType या createTime, spaceView पैरामीटर को SPACE_VIEW_EXPANDED के तौर पर सेट करें.
SPACE_VIEW_EXPANDED का इस्तेमाल करने के लिए, अनुमति के एक और स्कोप की ज़रूरत होती है:
https://www.googleapis.com/auth/chat.spaces या
https://www.googleapis.com/auth/chat.spaces.readonly.
ग्रुप चैट ढूंढने और उसकी जानकारी वापस पाने का तरीका यहां बताया गया है:
Node.js
/**
* This sample shows how to find a group chat with specific members and return details.
*
* It relies on the @google-apps/chat npm package.
*/
// Read the documentation for more details:
// https://developers.google.com/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.FindGroupChats
const {ChatServiceClient} = require('@google-apps/chat');
const {auth} = require('google-auth-library');
async function main() {
// Create a client
const chatClient = new ChatServiceClient({
authClient: await auth.getClient({
scopes: [
'https://www.googleapis.com/auth/chat.spaces.readonly',
'https://www.googleapis.com/auth/chat.memberships.readonly'
]
})
});
// The users to find a group chat with.
// Don't include the caller.
const user = [
'users/123456789',
'users/987654321'
];
// Create the request
const request = {
user: user,
spaceView: 'SPACE_VIEW_EXPANDED'
};
// Call the API
const response = await chatClient.findGroupChats(request);
// Handle the response
if (response.spaces && response.spaces.length > 0) {
console.log('Found group chat:', response.spaces[0].displayName);
} else {
console.log('No group chat found.');
}
}
main().catch(console.error);
Python
"""
This sample shows how to find a group chat with specific members and return details.
"""
from google.apps import chat_v1
import google.auth
# Read the documentation for more details:
# https://developers.google.com/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.FindGroupChats
def find_group_chat_with_details():
# Create a client
scopes = [
"https://www.googleapis.com/auth/chat.memberships.readonly",
"https://www.googleapis.com/auth/chat.spaces.readonly"
]
credentials, _ = google.auth.default(scopes=scopes)
client = chat_v1.ChatServiceClient(credentials=credentials)
# The users to find a group chat with.
# Don't include the caller.
user_list = [
"users/123456789",
"users/987654321"
]
# Create the request
request = chat_v1.FindGroupChatsRequest(
user=user_list,
space_view=chat_v1.SpaceView.SPACE_VIEW_EXPANDED
)
# Call the API
response = client.find_group_chats(request)
# Handle the response
if response.spaces:
print(f"Found group chat: {response.spaces[0].display_name}")
else:
print("No group chat found.")
if __name__ == "__main__":
find_group_chat_with_details()
Java
/**
* This sample shows how to find a group chat with specific members and return details.
*/
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.chat.v1.ChatServiceClient;
import com.google.chat.v1.ChatServiceSettings;
import com.google.chat.v1.FindGroupChatsRequest;
import com.google.chat.v1.FindGroupChatsResponse;
import com.google.chat.v1.SpaceView;
import java.util.Arrays;
import java.util.List;
// Read the documentation for more details:
// https://developers.google.com/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.FindGroupChats
public class FindGroupChatWithDetails {
public static void main(String[] args) throws Exception {
GoogleCredentials credentials = GoogleCredentials.getApplicationDefault()
.createScoped(Arrays.asList(
"https://www.googleapis.com/auth/chat.memberships.readonly",
"https://www.googleapis.com/auth/chat.spaces.readonly"
));
ChatServiceSettings settings = ChatServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credentials))
.build();
try (ChatServiceClient chatServiceClient = ChatServiceClient.create(settings)) {
List<String> users = Arrays.asList(
"users/123456789",
"users/987654321"
);
FindGroupChatsRequest request = FindGroupChatsRequest.newBuilder()
.addAllUser(users)
.setSpaceView(SpaceView.SPACE_VIEW_EXPANDED)
.build();
FindGroupChatsResponse response = chatServiceClient.findGroupChats(request);
if (!response.getSpacesList().isEmpty()) {
System.out.printf("Found group chat: %s\n", response.getSpacesList().get(0).getDisplayName());
} else {
System.out.println("No group chat found.");
}
}
}
}
Apps Script
/**
* This sample shows how to find a group chat with specific members and return details.
*/
// Read the documentation for more details:
// https://developers.google.com/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.FindGroupChats
function findGroupChatWithDetails() {
// The users to find a group chat with.
// Don't include the caller.
const users = [
'users/123456789',
'users/987654321'
];
try {
// Call the API
// In Apps Script, query parameters are passed as optional arguments
const response = Chat.Spaces.findGroupChats({
user: users,
spaceView: 'SPACE_VIEW_EXPANDED'
});
if (response.spaces && response.spaces.length > 0) {
console.log('Found group chat: ' + response.spaces[0].displayName);
} else {
console.log('No group chat found.');
}
} catch (err) {
// Handle error
console.log('Failed to find group chat: ' + err.message);
}
}
इस सैंपल को चलाने के लिए, उपयोगकर्ता के संसाधन के नामों को मान्य उपयोगकर्ता आईडी से बदलें. People API या Directory API से, उपयोगकर्ता आईडी पाए जा सकते हैं.
Chat API, FindGroupChatsResponse (RPC, REST) का एक इंस्टेंस दिखाता है. इसमें मिले हुए स्पेस की सूची के साथ-साथ, spaceView के बारे में ज़्यादा जानकारी भी शामिल होती है.
मिलते-जुलते विषय
- कोई स्पेस बनाना
- कोई स्पेस सेट अप करना
- स्पेस की सूची
- स्पेस अपडेट करना
- किसी स्पेस को मिटाना
- डायरेक्ट मैसेज ढूंढना