Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加群成员为好友 #2142

Closed
1 of 5 tasks
su-chang opened this issue Feb 22, 2021 · 8 comments
Closed
1 of 5 tasks

添加群成员为好友 #2142

su-chang opened this issue Feb 22, 2021 · 8 comments

Comments

@su-chang
Copy link
Member

su-chang commented Feb 22, 2021

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
支持添加群内联系人为好友,可以便于针对群内不同用户进行针对性沟通。

Describe the solution you'd like
A clear and concise description of what you want to happen.
在任意群聊内,指定群成员添加为好友,并可附带一段好友验证消息。

底层实现所需参数

data: { 
  user_id: "78813xxxxx", // 传入user_id
  room_conversation_id: "R:1222121", //  用户所在群聊会话ID
  verify: "朋友推荐" // 验证消息
}

接口设计

// user/room.ts
public async addFriends (contact: Contact, hello: string): Promise<void>
const room = bot.Room.load('roomId')
room.addFriends(contact, 'hello')

待讨论

  • 是否需要支持批量添加群成员的功能,可能会涉及到频率相关的问题
  • 该方法基于哪个类进行实现
    • Friendship
    • Contact
    • Room
  • 方法命名
    • addMemberFriends()
    • memberFriends()
@huan
Copy link
Member

huan commented Feb 22, 2021

Could you explain why did you not consider the following API in your request?

wechaty.Friendship.add(contact, 'hello')

@padlocal
Copy link
Contributor

agree, because roomid is required while adding contact from room.

@su-chang
Copy link
Member Author

出于以下几点考虑:

  1. 添加群内成员为好友需要提供群ID,以联系人反查群ID相对复杂
  2. Friendship.add() 方法一般配合 Friendship.search() 的结果来使用
  3. 从添加群成员的使用场景考虑:
    • 接收到入群事件,直接通过当前room来调用memberFriends()方法
    • 接收到群成员消息,直接通过当前room来调用memberFriends()方法

@windmemory
Copy link
Member

Maybe there is another alternative:

wechaty.Friendship.add(contact, 'hello', room);

The third parameter is optional.

@huan
Copy link
Member

huan commented Feb 23, 2021

Yes, it will be better for us to keep all Friendship related operations encapsulating in the Friendship class.

I'd like to contribute a little more based on Yuan's version, by changing the second argument to an optional options.

interface FriendshipAddOptionsObj {
  room?: Room,
  contact?: Contact,
  hello?: string,
}

type FriendshipAddOptions = string | FriendshipAddOptionsObj

class Friendship {
  add (contact: Contact, options?: FriendshipAddOptions)
}

@su-chang
Copy link
Member Author

FriendshipAddOptionsObj中的contact参数的作用是什么呢?

@huan
Copy link
Member

huan commented Feb 23, 2021

You can safely ignore it for now, because it's optional.

And I believe it's not hard to guess the scenario in which it is required.

This was referenced Mar 19, 2021
@su-chang
Copy link
Member Author

This feature has supported in wechaty@0.57.19.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants