TencentCloudChat.EVENT.FRIEND_LIST_UPDATED
event.chat.getFriendList();
Promise
let promise = chat.getFriendList();promise.then(function(imResponse) {const friendList = imResponse.data; // Contacts}).catch(function(imError) {console.warn('getFriendList error:', imError); // Failed to obtain contacts});
chat.addFriend(options);
options
parameter is of the Object
type. It contains the following attribute values:Name | Type | Description |
to | String | User ID |
source | String | Friend source. It consists of two parts: the prefix and the keyword. The former is AddSource_Type_ , and the latter must be a string of up to 8 bytes. We recommend you use an English word or its abbreviation as the keyword. For example, if the keyword is Android , this field will be AddSource_Type_Android . |
wording | String | undefined | Friending remarks, which can contain up to 256 bytes. |
type | String | undefined | Friending method (two-way friending by default). Valid values: TencentCloudChat.TYPES.SNS_ADD_TYPE_SINGLE (one-way friending, where user B is in the friend list of user A but not vice versa)TencentCloudChat.TYPES.SNS_ADD_TYPE_BOTH (two-way friending, where user B is in the friend list of user A and vice versa) |
remark | String | undefined | Friend remarks, which can contain up to 96 bytes. |
groupName | String | undefined | List name, which can contain up to 30 bytes. |
Promise
// Add a friendlet promise = chat.addFriend({to: 'user1',source: 'AddSource_Type_Web',remark: 'Jane',groupName: 'Friend',wording: 'I'm user0',type: TencentCloudChat.TYPES.SNS_ADD_TYPE_BOTH,});promise.then(function(imResponse) {// Sent the friend request successfullyconst { code } = imResponse.data;if (code === 30539) {// 30539 indicates that user1 has set the friend request processing method// to manually accept friend requests received.// The SDK will trigger the TencentCloudChat.EVENT.FRIEND_APPLICATION_LIST_UPDATED event.} else if (code === 0) {// 0 indicates that user1 has set the friend request processing method// to automatically accept all friend requests received.// The SDK will trigger the TencentCloudChat.EVENT.FRIEND_LIST_UPDATED event.}}).catch(function(imError) {console.warn('addFriend error:', imError); // Failed to add the friend});
userID
values in the userIDList
at a time, as a large data packet may be rejected by the backend, which requires that a data packet not exceed 1 MB.chat.deleteFriend(options);
options
parameter is of the Object
type. It contains the following attribute values:Name | Type | Description |
userIDList | Array | List of userID values of the friends to be deleted. The number of userID values cannot exceed 100 per request. |
type | String | undefined | Deletion mode (two-way deletion by default). Valid values: TencentCloudChat.TYPES.SNS_DELETE_TYPE_SINGLE (one-way deletion, where user B is deleted from the friend list of user A but not vice versa)TencentCloudChat.TYPES.SNS_DELETE_TYPE_BOTH (two-way deletion, where user B is deleted from the friend list of user A and vice versa) |
Promise
let promise = chat.deleteFriend({userIDList: ['user1','user2'],type:TencentCloudChat
.TYPES.SNS_DELETE_TYPE_BOTH});promise.then(function(imResponse) {const { successUserIDList, failureUserIDList } = imResponse.data;// List of successfully deleted `userID` valuessuccessUserIDList.forEach((item) => {const { userID } = item;});// List of `userID` values failed to be deletedfailureUserIDList.forEach((item) => {const { userID, code, message } = item;});// If the contacts are updated,// the SDK will trigger theTencentCloudChat
.EVENT.FRIEND_LIST_UPDATED event.}).catch(function(imError) {console.warn('removeFromFriendList error:', imError);});
chat.checkFriend(options);
options
parameter is of the Object
type. It contains the following attribute values:Name | Type | Description |
userIDList | Array | List of the userID values to be verified. The number of userID values cannot exceed 1,000 per request. |
type | String | undefined | Verification mode (two-way verification by default). Valid values: TencentCloudChat.TYPES.SNS_CHECK_TYPE_SINGLE (one-way verification, where the friend list of user A is checked for user B but not vice versa)TencentCloudChat.TYPES.SNS_CHECK_TYPE_BOTH (two-way verification, where the friend list of user A is checked for user B and vice versa) |
Promise
let promise = chat.checkFriend({userIDList: ['user0','user1'],type:TencentCloudChat
.TYPES.SNS_CHECK_TYPE_BOTH,});promise.then(function(imResponse) {const { successUserIDList, failureUserIDList } = imResponse.data;// List of the `userID` values that passed the verificationsuccessUserIDList.forEach((item) => {const { userID, code, relation } = item; // The value of code is always 0.// Possible results of one-way friend verification are:// - relation:TencentCloudChat
.TYPES.SNS_TYPE_NO_RELATION// B is not on A's friend list, but it cannot determine whether A is on B's friend list.// - relation:TencentCloudChat
.TYPES.SNS_TYPE_A_WITH_B:// B is on A's friend list, but it cannot determine whether A is on B's friend list.// Possible results of two-way friend verification are:// - relation:TencentCloudChat
.TYPES.SNS_TYPE_NO_RELATION:// A and B are not on each other's friend list// - relation:TencentCloudChat
.TYPES.SNS_TYPE_A_WITH_B:// B is on A's friend list, but A is not on B's friend list// - relation:TencentCloudChat
.TYPES.SNS_TYPE_B_WITH_A:// B is not on A's friend list, but A is on B's friend list// - relation:TencentCloudChat
.TYPES.SNS_TYPE_BOTH_WAY:// A and B are on each other's friend list});// List of the `userID` values that failed the verificationfailureUserIDList.forEach((item) => {const { userID, code, message } = item;});}).catch(function(imError) {console.warn('checkFriend error:', imError);});
chat.getFriendProfile(options);
options
parameter is of the Object
type. It contains the following attribute values:Name | Type | Description |
userIDList | Array | List of userID values of the friends. |
Promise
let promise = chat.getFriendProfile({userIDList: ['user0','user1']});promise.then(function(imResponse) {const { friendList, failureUserIDList } = imResponse.data;friendList.forEach((friend) => {});failureUserIDList.forEach((item) => {const { userID, code, message } = item;});}).catch(function(imError) {console.warn('getFriendProfile error:', imError);});
remark
and friendCustomField
.chat.updateFriend(options);
options
parameter is of the Object
type. It contains the following attribute values:Name | Type | Description |
userID | String | userID value of a friend |
remark | String | Friend remarks, which can contain up to 96 bytes. |
friendCustomField | Array.<Object> | A collection of custom field key-value pairs, which can be used according to the needs of the business side. |
Promise
// update friend remarklet promise = chat.updateFriend({userID: 'user1',remark: 'helloworld'});promise.then(function(imResponse) {console.log(imResponse.data);}).catch(function(imError) {console.warn('getFriendProfile error:', imError);});
let promise = chat.updateFriend({userID: 'user1',friendCustomField: [{ key: 'Tag_SNS_Custom_test1', value: 'hello' },{ key: 'Tag_SNS_Custom_test2', value: 'world' },]});promise.then(function(imResponse) {console.log(imResponse.data);}).catch(function(imError) {console.warn('getFriendProfile error:', imError);});
allowType
in your profile (obtained through the getMyProfile
interface) is set to TencentCloudChat.TYPES.ALLOW_TYPE_ALLOW_ANY
(when being added as a friend: allowing anyone to add oneself as a friend), this interface will not be able to pull the friend request list.chat.getFriendApplicationList();
Promise
// update friend remarklet promise = chat.updateFriend({userID: 'user1',remark: 'helloworld'});promise.then(function(imResponse) {console.log(imResponse.data);}).catch(function(imError) {console.warn('getFriendProfile error:', imError);});
chat.acceptFriendApplication(options);
options
parameter is of the Object
type. It contains the following attribute values:Name | Type | Description |
userID | String | The userID of the pending friend request. |
remark | String | Friend remarks, which can contain up to 96 bytes. |
type | String | TencentCloudChat.TYPES.SNS_APPLICATION_AGREE - Agree to add as a one-way friend.TencentCloudChat.TYPES.SNS_APPLICATION_AGREE_AND_ADD - Agree and add as a two-way friend. |
Promise
let promise = chat.acceptFriendApplication({userID: 'user1',remark: 'My Customer Service 1',type: TencentCloudChat.TYPES.SNS_APPLICATION_AGREE_AND_ADD});promise.then(function(imResponse) {}).catch(function(imError) {console.warn('acceptFriendApplication error:', imError);});
chat.refuseFriendApplication(options);
options
parameter is of the Object
type. It contains the following attribute values:Name | Type | Description |
userID | String | The userID of the pending friend request. |
Promise
let promise = chat.refuseFriendApplication({userID: 'user1',});promise.then(function(imResponse) {}).catch(function(imError) {console.warn('refuseFriendApplication error:', imError);});
chat.deleteFriendApplication(options);
options
parameter is of the Object
type. It contains the following attribute values:Name | Type | Description |
userID | String | The userID of the pending friend request. |
type | String | TencentCloudChat.TYPES.SNS_APPLICATION_AGREE - Agree to add as a one-way friend.TencentCloudChat.TYPES.SNS_APPLICATION_AGREE_AND_ADD - Agree and add as a two-way friend. |
Promise
let promise = chat.refuseFriendApplication({userID: 'user1',});promise.then(function(imResponse) {}).catch(function(imError) {console.warn('refuseFriendApplication error:', imError);});
chat.setFriendApplicationRead();
Promise
let promise = chat.setFriendApplicationRead();promise.then(function(imResponse) {}).catch(function(imError) {console.warn('setFriendApplicationRead error:', imError);});
Was this page helpful?