initGroupAttributes
, setGroupAttributes
, and deleteGroupAttributes
APIs together can be called by a logged-in user up to ten times every five seconds in the SDK, and the 2996 error code will be called back if the limit is exceeded.getGroupAttributes
API can be called by a logged-in user 20 times every five seconds in the SDK, and the 2996 error code will be called back if the limit is exceeded.getGroupAttributes
to pull the latest group attributes before you initiate the modification operation again.getGroupAttributes
to update the locally stored group attributes to the latest before you initiate the modification operation.chat.initGroupAttributes(options);
options
parameter is of the Object
type. It contains the following attribute values:Name | Type | Description |
groupID | String | Group ID |
groupAttributes | Object | Group attributes |
Promise
let promise = chat.initGroupAttributes({groupID: 'group1',groupAttributes: { key1: 'value1', key2: 'value2' }});promise.then(function(imResponse) {console.log(imResponse.data.groupAttributes); // Group attributes initialized successfully}).catch(function(imError) {console.warn('initGroupAttributes error:', imError); // Error information});
chat.setGroupAttributes(options);
options
parameter is of the Object
type. It contains the following attribute values:Name | Type | Description |
groupID | String | Group ID |
groupAttributes | Object | Group attributes |
Promise
let promise = chat.setGroupAttributes({groupID: 'group1',groupAttributes: { key1: 'value1', key2: 'value2' }});promise.then(function(imResponse) { // Set successfullyconsole.log(imResponse.data.groupAttributes); // Group attributes set successfully}).catch(function(imError) { // Setting failedconsole.warn('setGroupAttributes error:', imError); // Error information});
keyList
. To delete all group attributes, pass in an empty array for keyList
.chat.deleteGroupAttributes(options);
options
parameter is of the Object
type. It contains the following attribute values:Name | Type | Description |
groupID | String | Group ID |
keyList | Array | List of keys of the group attributes |
Promise
// Delete the `key-value` of the specified group attributeslet promise = chat.deleteGroupAttributes({groupID: 'group1',keyList: ['key1', 'key2']});promise.then(function(imResponse) {console.log(imResponse.data.keyList); // List of group attributes deleted successfully}).catch(function(imError) {console.warn('deleteGroupAttributes error:', imError); // Error information});
// Delete all group attributeslet promise = chat.deleteGroupAttributes({groupID: 'group1',keyList: []});promise.then(function(imResponse) {console.log(imResponse.data.keyList); // List of group attributes deleted successfully}).catch(function(imError) {console.warn('deleteGroupAttributes error:', imError); // Error information});
keyList
. To get all group attributes, pass in an empty array for keyList
.chat.getGroupAttributes(options);
options
parameter is of the Object
type. It contains the following attribute values:Name | Type | Description |
groupID | String | Group ID |
keyList | Array | List of keys of the group attributes |
Promise
// Get specified group attributeslet promise = chat.getGroupAttributes({groupID: 'group1',keyList: ['key1', 'key2']});promise.then(function(imResponse) { // Got successfullyconsole.log(imResponse.data.groupAttributes); // Specified group attributes}).catch(function(imError) { // Getting failedconsole.warn('getGroupAttributes error:', imError); // Error information});
// Get all group attributeslet promise = chat.getGroupAttributes({groupID: 'group1',keyList: []});promise.then(function(imResponse) { // Got successfullyconsole.log(imResponse.data.groupAttributes); // All group attributes}).catch(function(imError) { // Getting failedconsole.warn('getGroupAttributes error:', imError); // Error information});
let onGroupAttributesUpdated = function(event) {const groupID = event.data.groupID // Group IDconst groupAttributes = event.data.groupAttributes //Updated group propertiesconsole.log(event.data);};chat.on(TencentCloudChat.EVENT.GROUP_ATTRIBUTES_UPDATED, onGroupAttributesUpdated);
Was this page helpful?