Skip to content

Latest commit

 

History

History
159 lines (121 loc) · 3.15 KB

README.md

File metadata and controls

159 lines (121 loc) · 3.15 KB

For business cooperation or customization needs, please contact the following email: [email protected]

About

中文

English

This is a WhatsApp communication protocol SDK based on WhatsApp Android client, which means that you can build any WhatsApp client based on this SDK, or complete some specific requirements.

The latest official version: https://www.whatsapp.com/android/

Latest SDK version: 2.22.21.71

TODO:

  • login 2022.10.15
  • register 2022.10.31
  • send message 2022.11.15

Usage

Installation

requires:

  • nodejs >= 14.11.0
  • mongodb >= 4.0.28

You can use npm or yarn to install:

# npm install whatsapp-nodejs

For some reasons, the package is removed by npm, so you need to clone the local repository, and then use the npm link command to use this sdk.

git clone [email protected]:yisbug/whatsapp-nodejs.git
cd whatsapp-nodejs
npm install
cd ../your project
npm link ../whatsapp-nodejs

Get SMS

const { Whatsapp } = require('whatsapp-nodejs');

const main = async () => {
  const whatsapp = new Whatsapp({
    mongodb: 'mongodb://localhost:27017/whatsapp',
  });
  await whatsapp.init({
    mobile: '8613888888888', // cc is required, for example, china is +86
    proxy: {
      host: '127.0.0.1',
      port: 1080,
      userId: 'test',
      password: 'test',
    },
  });

  const res = await whatsapp.sms();
  // {status:'success'}
  // {status:'error'}
};

main();

Use SMS Code to register

const { Whatsapp } = require('whatsapp-nodejs');

const main = async () => {
  const whatsapp = new Whatsapp({
    mongodb: 'mongodb://localhost:27017/whatsapp',
  });
  await whatsapp.init({
    mobile: '8613888888888', // cc is required, for example, china is +86
    proxy: {
      host: '127.0.0.1',
      port: 1080,
      userId: 'test',
      password: 'test',
    },
  });

  const res = await whatsapp.register({ code: '352-002' });
  // {status:'success'}
  // {status:'error'}
};

main();

Login

const { Whatsapp } = require('whatsapp-nodejs');

const main = async () => {
  const whatsapp = new Whatsapp({
    mongodb: 'mongodb://localhost:27017/whatsapp',
  });
  await whatsapp.init({
    mobile: '8613888888888', // cc is required, for example, china is +86
    proxy: {
      host: '127.0.0.1',
      port: 1080,
      userId: 'test',
      password: 'test',
    },
  });

  const res = await whatsapp.login();
  // {status:'success'}
  // {status:'error'}
};

main();

Send Text Message

const { Whatsapp } = require('whatsapp-nodejs');

const main = async () => {
  const whatsapp = new Whatsapp({
    mongodb: 'mongodb://localhost:27017/whatsapp',
  });
  await whatsapp.init({
    mobile: '8613888888888', // cc is required, for example, china is +86
    proxy: {
      host: '127.0.0.1',
      port: 1080,
      userId: 'test',
      password: 'test',
    },
  });

  const res = await whatsapp.login();
  // {status:'success'}
  // {status:'error'}

  res = await whatsapp.sendContactTextMessage({
    jid: '8613666666666',
    message: 'hello world.',
  });
};

main();

More example: test/whatsapp.test.js