Skip to content

Support search new friends by phone number or user name. #1892

@su-chang

Description

@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 and v2 attributes for add friends
  • add friends by v1 and v2 (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

  1. For the type of param in search(), I think string is better than Contact, easy to use indeed.

  2. After we searched new friend, it will generate one Contact which is not friend, so we should delete this Contact when add() method finished. Or we should save it for 24 hours (maybe it due to the expire time of v2) 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]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions