Skip to content

This is a library based on whatsapp androd latest version, you can use it build your own app.

Notifications You must be signed in to change notification settings

hrferoz/whatsapp-nodejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

This is a library based on whatsapp androd latest version, you can use it build your own app.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published