setGroupCounters
, increaseGroupCounter
, and decreaseGroupCounter
APIs combine computations, with an SDK limit of 20 calls per 5 seconds per log in to user. If exceeded, the interface returns error code 2996.getGroupCounters
interface calculates independently. The SDK limits a single user to a maximum of 20 calls within 5 seconds per log in. If the limit is exceeded, the interface returns error code 2996.TencentCloudChat.EVENT.GROUP_COUNTER_UPDATED
in the Group Counter Change Notification section below.chat.setGroupCounters(options);
Name | Type | Description |
groupID | String | Group ID |
counters | Object | Group Counter key-value |
Promise
// Set the values of counters key1 and key2 to 0let promise = chat.setGroupCounters({groupID: 'group1',counters: { key1: 0, key2: 0 }});promise.then(function(imResponse) { // Set successfullyconsole.log(imResponse.data.counters); // Group counters set successfully}).catch(function(imError) { // Setting failedconsole.warn('setGroupCounters error:', imError); // Error information});
TencentCloudChat.EVENT.GROUP_COUNTER_UPDATED
.chat.increaseGroupCounter(options);
Name | Type | Description |
groupID | String | Group ID |
key | String | Group Counter Key |
value | Number | Incremental Change Amount of the Group Counter Key |
Promise
// Assuming the current value of counter key1 is 8. After calling the increaseGroupCounter interface and passing the incremental change amount value of 2, the final value of key1 becomes 10.let promise = chat.increaseGroupCounter({groupID: 'group1',key: 'key1',value: 2,});promise.then(function(imResponse) { // Increment successfulconsole.log(imResponse.data);const { groupID, key, value } = imResponse.data;}).catch(function(imError) { // Increment failedconsole.warn('increaseGroupCounter error:', imError);});
TencentCloudChat.EVENT.GROUP_COUNTER_UPDATED
in the Group Counter Change Notification section below.chat.decreaseGroupCounter(options);
Name | Type | Description |
groupID | String | Group ID |
key | String | Group Counter Key |
value | Number | Incremental Change Amount of the Group Counter Key |
Promise
// Assuming the current value of the counter key1 is 8.// After calling the decreaseGroupCounter API with a decrement value of 2// The final value of key1 becomes 6.let promise = chat.decreaseGroupCounter({groupID: 'group1',key: 'key1',value: 2});promise.then(function(imResponse) { // Decrement successfulconsole.log(imResponse.data);const { groupID, key, value } = imResponse.data;}).catch(function(imError) { // Setting failedconsole.warn('decreaseGroupCounter error:', imError);});
chat.getGroupCounter(options);
Name | Type | Description |
groupID | String | Group ID |
keyList | Array | undefined | List of keys of the group counters |
Promise
// Get values of group counters key1 and key2let promise = chat.getGroupCounters({groupID: 'group1',keyList: ['key1', 'key2']});promise.then(function(imResponse) { // Got successfullyconsole.log(imResponse.data.counters);}).catch(function(imError) {console.warn('getGroupCounters error:', imError); // Error information});
// Get all counters of a grouplet promise = chat.getGroupCounters({groupID: 'group1'});promise.then(function(imResponse) { // Got successfullyconsole.log(imResponse.data.counters);}).catch(function(imError) {console.warn('getGroupCounters error:', imError); // Error information});
setGroupCounters
, increaseGroupCounter
, or decreaseGroupCounter
interfaces to modify the group counters, the TencentCloudChat.EVENT.GROUP_COUNTER_UPDATED
event will be triggered and the updated value will be returned.let onGroupCounterUpdated = function(event) {const { groupID, key, value } = event.data;// groupID - Group ID// key - Group counter key// value - Value corresponding to the group counter key};chat.on(TencentCloudChat
.EVENT.GROUP_COUNTER_UPDATED, onGroupCounterUpdated);
Was this page helpful?