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);});
Was this page helpful?