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

通过手机号添加成功,通过微信号添加失败 #2690

Open
aqpmzngldh opened this issue May 10, 2024 · 4 comments
Open

通过手机号添加成功,通过微信号添加失败 #2690

aqpmzngldh opened this issue May 10, 2024 · 4 comments

Comments

@aqpmzngldh
Copy link

const phone =12345678901
const targetContact = await bot.Friendship.search({ phone })
// console.log(phone, 'queryTaskUserXfj')
if (targetContact) {
// console.log(${targetContact} is ready)
await bot.Friendship.add(targetContact, {
hello: "您好"
})
}

Copy link

dosubot bot commented May 10, 2024

To add a contact by WeChat ID using a bot, follow these steps:

  1. Search for the Contact by WeChat ID: Use the Friendship.search() method with the weixin option to search for the contact. Here's an example:
const friend_weixin = await bot.Friendship.search({weixin: 'weixin_account'});
  1. Add the Contact: If the contact is found, use the Friendship.add() method to send a friend request, like so:
if (friend_weixin) {
    await bot.Friendship.add(friend_weixin, 'Hello! I would like to add you as a friend.');
}

Ensure your code handles cases where the contact might not be found (undefined result from the search). Also, be mindful of rate limits and best practices to avoid your account being blocked.

Here's a combined example:

async function addContactByWeChatID(bot, weixinId) {
    const friend_weixin = await bot.Friendship.search({weixin: weixinId});
    if (friend_weixin) {
        await bot.Friendship.add(friend_weixin, 'Hello! I would like to add you as a friend.');
        console.log('Friend request sent!');
    } else {
        console.log('Contact not found!');
    }
}

Replace 'weixin_account' with the actual WeChat ID. This approach should help you add contacts by WeChat ID successfully.

Details

Sources


About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

@aqpmzngldh
Copy link
Author

要使用机器人通过微信ID添加联系人,请按照以下步骤操作:

  1. 通过微信ID搜索联系人:使用Friendship.search()带有weixin选项的方法来搜索联系人。这是一个例子:
const friend_weixin = await bot.Friendship.search({weixin: 'weixin_account'});
  1. 添加联系人:如果找到联系人,请使用该Friendship.add()方法发送好友请求,如下所示:
if (friend_weixin) {
    await bot.Friendship.add(friend_weixin, 'Hello! I would like to add you as a friend.');
}

确保您的代码能够处理可能找不到联系人的情况(undefined搜索结果)。此外,请注意速率限制和最佳实践,以避免您的帐户被阻止。

这是一个组合示例:

async function addContactByWeChatID(bot, weixinId) {
    const friend_weixin = await bot.Friendship.search({weixin: weixinId});
    if (friend_weixin) {
        await bot.Friendship.add(friend_weixin, 'Hello! I would like to add you as a friend.');
        console.log('Friend request sent!');
    } else {
        console.log('Contact not found!');
    }
}

替换'weixin_account'为实际的微信ID。此方法应该可以帮助您成功通过微信ID添加联系人。

细节

要继续对话,请提及@dosu

通过手机号添加的时候没问题,当我换成通过微信号添加的时候然后报错const contact2 = await wechaty.Friendship.search({ weixin: "CZ" });
12:04:06 WARN Puppet friendshipSearch() { weixin: ... } is deprecated. use { handle: ... } instead.
Error
然后我试图改成const contact2 = await wechaty.Friendship.search({ handle: "CZ" });还是不行。报错
TypeError: this.friendshipSearchHandle is not a function,这是什么情况@dosu@dosu.

Copy link

dosubot bot commented May 10, 2024

It seems you're encountering issues with the Friendship.search() method in Wechaty, specifically with the transition from using { weixin: ... } to { handle: ... } due to deprecation warnings and errors like TypeError: this.friendshipSearchHandle is not a function. This suggests there might be a discrepancy in the Wechaty documentation or a potential bug in the library itself.

The error message you're seeing indicates that the method expected for searching by handle isn't implemented or recognized by your version of Wechaty. This could be due to several reasons, such as using an outdated version of the library or a mismatch between the library's documentation and its current implementation.

Here's a step you can take to troubleshoot and potentially resolve your issue:

  1. Verify Your Wechaty Version: Ensure you're using the latest version of Wechaty. If not, consider updating it, as the issue might have been addressed in a more recent release.

  2. Consult the Latest Documentation: Check the latest Wechaty documentation or GitHub repository for any updates or migration guides related to the Friendship.search() method. There might be new or changed methods for searching by WeChat ID.

  3. Reach Out to the Community: If the problem persists, consider reaching out to the Wechaty community or support channels. They might offer more specific guidance or workarounds for the issue you're facing.

Unfortunately, without direct access to the latest Wechaty API changes or internal implementation details, I can't provide a more specific solution. However, following these steps should help you move forward in resolving the issue.

Details

Sources


About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

@aqpmzngldh
Copy link
Author

已解决

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

1 participant