tencent cloud

Chat

제품 소개
제품 개요
Basic Concepts
응용 시나리오
기능 소개
계정 시스템
사용자 정보 및 관계망
메시지 관리
그룹 시스템
Official Account
Audio/Video Call
사용 제한
구매 가이드
과금 개요
요금 안내
Purchase Instructions
Renewal Guide
연체 안내
Refund Policy
다운로드 센터
SDK & Demo 소스 코드
업데이트 로그
시나리오 솔루션
Live Streaming Setup Guide
AI Chatbot
대규모 엔터테인먼트 협업 커뮤니티
Discord 구현 가이드
IM을 게임에 통합하는 방법
WhatsApp Channel-style Official Account Integration Solution
Send Red Packet
Firewall Restrictions
클라이언트 APIs
SDK API(Web)
Android
iOS & macOS
Swift
Flutter
Electron
Unity
React Native
C APIs
C++
서버 APIs
Secure authentication with UserSig
RESTful APIs
Webhooks
콘솔 가이드
New Console Introduction
애플리케이션 생성 및 업그레이드
기본 설정
기능 설정
계정 관리
그룹 관리
Official Channel Management
콜백 설정
모니터링 대시보드
Viewing Guide for Resource Packages
Real-Time Monitor
개발 보조 툴
액세스 관리
Advanced Features
FAQ
uni-app FAQs
구매
SDK 관련 질문
계정 인증
사용자 정보 및 관계망
메시지
그룹
라이브 방송 그룹
닉네임 및 프로필 사진
협약 및 인증
Service Level Agreement
컴플라이언스 인증
IM 정책
개인 정보 보호 정책
데이터 개인 정보 보호 및 보안 계약
에러 코드
문의하기
문서Chat

React Native

포커스 모드
폰트 크기
마지막 업데이트 시간: 2025-01-07 16:09:07

Feature Overview

Chat SDK provides the group counter feature, allowing a certain number of counters to be set for each group.
Unlike Group Custom Attributes, group counters are mainly used to store integer-type data. You can use group counters to store additional group-related information, such as the cumulative number of viewers, the number of views, the number of likes received by the host, and the total number of gifts given by the audience to the host in a live group.
Note:
1. Group counters support all types of groups, excluding topic-enabled community groups.
2. This feature is only supported in the Premium edition.
Keep the following in mind for group counters:
1. A single group can support up to 20 group counters, meaning the number of keys in a single group should not exceed 20.
2. The key for a single group counter cannot exceed 128 characters, and the value must be an integer (up to 64-bit signed integers).
3. 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.
4. 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.

UI Display





Setting Group Counters

After the counter is successfully set, the TencentCloudChat.EVENT.GROUP_COUNTER_UPDATED event is triggered.
Note:
1. If the key of the counter you are about to set exists, then the value of the counter will be updated directly; if not, then a new key-value will be added.
2. If multiple users set the same counter at the same time, the final value of the counter will be used. It's recommended that the group owner performs counter setting operations.
API
chat.setGroupCounters(options);
Parameters
The options parameter is of the Objecttype, and contains the following attribute values:
Name
Type
Description
groupID
String
Group ID
counters
Object
Group Counter key-value
Return value
Promise
Examples
// Set the values of counters key1 and key2 to 0
let promise = chat.setGroupCounters({
groupID: 'group1',
counters: { key1: 0, key2: 0 }
});
promise.then(function(imResponse) { // Set successfully
console.log(imResponse.data.counters); // Group counters set successfully
}).catch(function(imError) { // Setting failed
console.warn('setGroupCounters error:', imError); // Error information
});

Incrementing the Value of a Group Counter

After the counter is successfully set, the TencentCloudChat.EVENT.GROUP_COUNTER_UPDATED event is triggered.
Note:
1. The value in the interface parameters is the change amount; after calling the interface, the incoming change amount will be added to the current value.
2. If the counter key you are about to set already exists, the system will directly increment the current value based on the incoming value; otherwise, it will add the key and increment based on the incoming value starting from a default value of 0.
API
chat.increaseGroupCounter(options);
Parameters
The options parameter is of the Object type, and contains the following attribute values:
Name
Type
Description
groupID
String
Group ID
key
String
Group Counter Key
value
Number
Incremental Change Amount of the Group Counter Key
Return value
Promise
Examples
// 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 successful
console.log(imResponse.data);
const { groupID, key, value } = imResponse.data;
}).catch(function(imError) { // Increment failed
console.warn('increaseGroupCounter error:', imError);
});

Decrementing the Value of a Group Counter

After the counter is successfully set, the TencentCloudChat.EVENT.GROUP_COUNTER_UPDATED event is triggered.
Note:
1. The value in the interface parameters is a change amount; after calling the interface, the incoming change amount will be subtracted from the current value.
2. If the counter key you are about to set already exists, the system will directly decrement the current value based on the incoming value; otherwise, it will add the key and decrement based on the incoming value starting from a default value of 0.
API
chat.decreaseGroupCounter(options);
Parameters
The options parameter is of the Objecttype, and contains the following attribute values:
Name
Type
Description
groupID
String
Group ID
key
String
Group Counter Key
value
Number
Incremental Change Amount of the Group Counter Key
Return value
Promise
Examples
// 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 successful
console.log(imResponse.data);
const { groupID, key, value } = imResponse.data;
}).catch(function(imError) { // Setting failed
console.warn('decreaseGroupCounter error:', imError);
});

Getting Group Counters

Note:
If no keyList is passed, all group counters are returned.
API
chat.getGroupCounter(options);
Parameters
The options parameter is of the Object type, and contains the following attribute values:
Name
Type
Description
groupID
String
Group ID
keyList
Array | undefined
List of keys of the group counters
Return value
Promise
Examples
// Get values of group counters key1 and key2
let promise = chat.getGroupCounters({
groupID: 'group1',
keyList: ['key1', 'key2']
});
promise.then(function(imResponse) { // Got successfully
console.log(imResponse.data.counters);
}).catch(function(imError) {
console.warn('getGroupCounters error:', imError); // Error information
});
// Get all counters of a group
let promise = chat.getGroupCounters({
groupID: 'group1'
});
promise.then(function(imResponse) { // Got successfully
console.log(imResponse.data.counters);
}).catch(function(imError) {
console.warn('getGroupCounters error:', imError); // Error information
});

Group Counter Change Notification

When you call the 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.
Examples
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);



도움말 및 지원

문제 해결에 도움이 되었나요?

피드백