Support search new friends by phone number or user name.
Created by: su-chang
Is your feature request related to a problem? Please describe.
Wechaty have bot.Friendship.add()
method for add new friend, but we can not make sure the new friend is who we want to add, so we hope Wechaty could support search friend, and then we could check the new friend by this API.
Describe the solution you'd like
Base
In primary level, the add()
method has two steps :
- search friends and get the
v1
andv2
attributes for add friends - add friends by
v1
andv2
(v1
changeless,v2
has expire time)
Design
So let's make search()
as a static method for Friendship
.
wechaty
public static search (contact: Contact): Promise<Contact>
wechaty-puppet
public abstract friendshipSearch (contactId: string): Promise<void>
wechaty-puppet-padplus
In friendshipSearch()
method, there has two important things to do:
- save
v1
,v2
data to cache - abstract data to generate one contact and save it to cache as not friend
There's no need to request v1
, v2
again if they are in cache, so we could get them from cache and use them in add()
method.
Example
const _contact = bot.Contact.load('phone number')
const contact: Contact = await bot.Friendship.search(_contact)
if (contact.name() === 'nick name') {
await bot.Friendship.add(contact, 'hello')
}
Question
-
For the type of param in
search()
, I thinkstring
is better thanContact
, easy to use indeed. -
After we searched new friend, it will generate one
Contact
which is not friend, so we should delete thisContact
whenadd()
method finished. Or we should save it for 24 hours (maybe it due to the expire time ofv2
) for one case :If the friend has not accept friend request, and the bot want to add again.
Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.
Additional context Add any other context or screenshots about the feature request here.
[enhancement]