GithubHelp home page GithubHelp logo

arbisyarifudin / wwebjs-aws-s3 Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 3.0 27 KB

A remote authentication plugin for whatsapp-web.js. Use the AWS S3 to keep your WhatsApp MultiDevice session data safe and secure.

License: MIT License

JavaScript 100.00%
aws-s3 whatsapp-web-js aws whatsapp

wwebjs-aws-s3's Introduction

wwebjs-aws-s3

A remote authentication plugin for whatsapp-web.js. Use the AWS S3 to keep your WhatsApp MultiDevice session data safe and secure.

GitHub license npm version npm downloads GitHub issues

Quick Links

Installation

The module is now available on npm! npm i wwebjs-aws-s3

DEBUG mode

To see detailed logs about object health, set the environment variable STORE_DEBUG to "true".

# linux
$ export STORE_DEBUG=true

# windows
$ SET STORE_DEBUG=true

Example usage

const { AwsS3Store, S3Client } = require('../src/AwsS3Store');
const { Client, RemoteAuth } = require('whatsapp-web.js');
const qrcode = require('qrcode-terminal');

const s3 = new S3Client({
    region: 'AWS_REGION',
    credentials: {
        accessKeyId: 'AWS_ACCESS_KEY_ID',
        secretAccessKey: 'AWS_SECRET_ACCESS_KEY'
    },
    httpOptions: {
        timeout: 600000, // 10 minutes <-- increase this value for large file uploads
    },
});

const store = new AwsS3Store({
    bucketName: 'example-bucket',
    remoteDataPath: 'example/dir',
    s3Client: s3
});

const client = new Client({
    authStrategy: new RemoteAuth({
        clientId: 'yourSessionName',
        dataPath: './.wwebjs_auth',
        store: store,
        backupSyncIntervalMs: 600000 // in milliseconds (10 minutes) <-- decrease this value if you want to test the backup feature
    })
});


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

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

    // trigger whatsapp client is started and ready
});

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

// it will done early (so use event 'ready' listener to know when the whatsapp client is ready & started)
client.initialize();

Delete Remote Session

How to force delete a specific remote session on the Database:

await store.delete({session: 'yourSessionName'});

wwebjs-aws-s3's People

Contributors

arbisyarifudin avatar pedrorioja avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

wwebjs-aws-s3's Issues

Not loading session from remote

After a succesfull login, the zip file is saved on my S3.

When I restart my app, I can see the session file is downloaded from S3, but the whatsapp client is not logged, it keep asking for the QR Code.

2024-01-24T12:54:55.665Z [STORE_DEBUG] [METHOD: sessionExists] Triggered.
2024-01-24T12:54:56.067Z [STORE_DEBUG] [METHOD: sessionExists] File found. PATH='active/RemoteAuth-my-session.zip'.
2024-01-24T12:54:56.240Z [STORE_DEBUG] [METHOD: extract] Triggered.
2024-01-24T12:54:57.558Z [STORE_DEBUG] [METHOD: extract] File extracted. REMOTE_PATH='active/RemoteAuth-my-session.zip', LOCAL_PATH='RemoteAuth-my-session.zip'.

Is there anything missing to use the session saved in the bucket?

Empty zip is being uploaded

Reprocedure: I am currently following your example.
But after running, only empty folder is being uploaded (folder name: Default inside this zip file)
I am running on Windows, Node 18
image

Cant extract instance clients

While accesing the extract function, i am getting the following error:

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received undefined

I have added some logs to see the value of the session passed and the type of the remotePath variable and i get the correct values

2024-02-07T22:36:30.831Z [STORE_DEBUG] /RemoteAuth-a5eac9c5-5b51-4f02-9bcf-439e0bd59cc1
2024-02-07T22:36:30.831Z [STORE_DEBUG] string

I am trying to understand what is happening.

Error when trying to save remote session

`async function initializeClient(user){
const { Client, RemoteAuth } = require('whatsapp-web.js');
const { AwsS3Store } = require('wwebjs-aws-s3');
const {
PutObjectCommand,
HeadObjectCommand,
GetObjectCommand,
DeleteObjectCommand
} = require('@aws-sdk/client-s3')
const s3 = await getS3client()
const putObjectCommand = PutObjectCommand;
const headObjectCommand = HeadObjectCommand;
const getObjectCommand = GetObjectCommand;
const deleteObjectCommand = DeleteObjectCommand;

const store = new AwsS3Store({
    bucketName: 'YYYYY',
    remoteDataPath: 'whatsapp/credentials/',
    s3Client: s3,
    putObjectCommand,
    headObjectCommand,
    getObjectCommand,
    deleteObjectCommand
});

const client =  new Client({
    authStrategy: new RemoteAuth({
        clientId: user,
        dataPath: `./.${user}`,
        store: store,
        backupSyncIntervalMs: 600000
    }),
    puppeteer: {
        headless: false
    }
});

client.on('qr', (qr) => {
    console.log('QR RECEIVED', qr);
    qrcode.generate(qr, { small: true });
    
});

client.on('ready', async() => {
    console.log('Client is ready!');
    await store.save({session: user})
});
await client.initialize();

`

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.