@acampagnaro/whatsapp-web.js 中文文档教程

发布于 3年前 浏览 12 项目主页 更新于 3年前

npmDepfuWhatsApp_Web 2.2126.14 Discord Chat

whatsapp-web.js

通过 WhatsApp Web 浏览器应用程序连接的 WhatsApp API 客户端

它使用 Puppeteer 运行 Whatsapp Web 的真实实例以避免被阻止。

注意:我不能保证您不会被阻止使用此方法,尽管它对我有用。 WhatsApp 不允许在其平台上使用机器人或非官方客户端,因此这不应被认为是完全安全的。

Installation

该模块现在在 npm 上可用! npm i whatsapp-web.js

请注意,需要 Node v12+。

Example usage

const { Client } = require('whatsapp-web.js');

const client = new Client();

client.on('qr', (qr) => {
    // Generate and scan this code with your phone
    console.log('QR RECEIVED', qr);
});

client.on('ready', () => {
    console.log('Client is ready!');
});

client.on('message', msg => {
    if (msg.body == '!ping') {
        msg.reply('pong');
    }
});

client.initialize();

查看 example.js 以获得更多用例的另一个示例。

Remote Access

您还可以连接到任何以前存在的浏览器实例:

const client = new Client({ 
    puppeteer: {
        browserWSEndpoint: `ws://localhost:3000`
    }
});

Docker

//docs.browserless.io/docs/docker-quickstart.html

docker run \
  --rm \
  -p 3000:3000 \
  -e "MAX_CONCURRENT_SESSIONS=1" \
  browserless/chrome:latest

1)使用无浏览器安装浏览器:参考:https:

Remote Debugging

2)运行启用了 websocket 远程调试的浏览器:

chrome .exe --remote-debugging-port=9222

之后检查以下网页并检查 http://127.0.0.1:9220/json 并获取 webSocketDebuggerUrl

Supported features

FeatureStatus
Send messages
Receive messages
Send media (images/audio/documents)
Send media (video)(requires google chrome)
Send stickers
Receive media (images/audio/video/documents)
Send contact cards
Send location
Receive location
Message replies
Join groups by invite
Get invite for group
Modify group info (subject, description)
Modify group settings (send messages, edit info)
Add group participants
Kick group participants
Promote/demote group participants
Mention users
Mute/unmute chats
Block/unblock contacts
Get contact info
Get profile pictures
Set user status message

缺少什么? 提出问题并告诉我们!

Contributing

欢迎请求请求! 如果您看到要添加的内容,请添加。 对于剧烈的变化,请先打开一个问题。

Donating

您可以通过以下链接支持该项目的维护者

Support via PayPal

Disclaimer

此项目不隶属于、关联、授权、认可或以任何方式正式连接 WhatsApp 或任何其子公司或其附属公司。 WhatsApp 官方网站可在 https://whatsapp.com 找到。 “WhatsApp”以及相关名称、标志、标志和图像是其各自所有者的注册商标。

License

版权所有 2019 Pedro S Lopez

,根据 Apache 许可证 2.0 版(“许可证”)获得许可; 除非遵守许可证,否则您不得使用该项目。 您可以在 http://www.apache.org/licenses/LICENSE-2.0 获得许可证的副本。

除非适用法律要求或书面同意,软件 根据许可证分发是在“按原样”的基础上分发的, 没有任何明示或暗示的保证或条件。 请参阅许可证以获取特定语言的管理权限和 许可证下的限制。

npmDepfuWhatsApp_Web 2.2126.14 Discord Chat

whatsapp-web.js

A WhatsApp API client that connects through the WhatsApp Web browser app

It uses Puppeteer to run a real instance of Whatsapp Web to avoid getting blocked.

NOTE: I can't guarantee you will not be blocked by using this method, although it has worked for me. WhatsApp does not allow bots or unofficial clients on their platform, so this shouldn't be considered totally safe.

Installation

The module is now available on npm! npm i whatsapp-web.js

Please note that Node v12+ is required.

Example usage

const { Client } = require('whatsapp-web.js');

const client = new Client();

client.on('qr', (qr) => {
    // Generate and scan this code with your phone
    console.log('QR RECEIVED', qr);
});

client.on('ready', () => {
    console.log('Client is ready!');
});

client.on('message', msg => {
    if (msg.body == '!ping') {
        msg.reply('pong');
    }
});

client.initialize();

Take a look at example.js for another example with more use cases.

Remote Access

You could also connect to any previously existing browser instance:

const client = new Client({ 
    puppeteer: {
        browserWSEndpoint: `ws://localhost:3000`
    }
});

Docker

1) Installing a browser using browserless:

docker run \
  --rm \
  -p 3000:3000 \
  -e "MAX_CONCURRENT_SESSIONS=1" \
  browserless/chrome:latest

Reference: https://docs.browserless.io/docs/docker-quickstart.html

Remote Debugging

2) Running a browser with websocket remote debugging enabled:

chrome.exe --remote-debugging-port=9222

After that check the following webpage and check http://127.0.0.1:9220/json and get the webSocketDebuggerUrl

Supported features

FeatureStatus
Send messages
Receive messages
Send media (images/audio/documents)
Send media (video)(requires google chrome)
Send stickers
Receive media (images/audio/video/documents)
Send contact cards
Send location
Receive location
Message replies
Join groups by invite
Get invite for group
Modify group info (subject, description)
Modify group settings (send messages, edit info)
Add group participants
Kick group participants
Promote/demote group participants
Mention users
Mute/unmute chats
Block/unblock contacts
Get contact info
Get profile pictures
Set user status message

Something missing? Make an issue and let us know!

Contributing

Pull requests are welcome! If you see something you'd like to add, please do. For drastic changes, please open an issue first.

Donating

You can support the maintainer of this project through the link below

Support via PayPal

Disclaimer

This project is not affiliated, associated, authorized, endorsed by, or in any way officially connected with WhatsApp or any of its subsidiaries or its affiliates. The official WhatsApp website can be found at https://whatsapp.com. "WhatsApp" as well as related names, marks, emblems and images are registered trademarks of their respective owners.

License

Copyright 2019 Pedro S Lopez

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this project except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文