UNPKG

@zamudio/wwebjs-aws-s3

Version:

A plugin for remote authentication on whatsapp-web.js and store session data on AWS S3.

57 lines (46 loc) 1.48 kB
const { AwsS3Store } = require('../src/AwsS3Store'); const { S3Client, PutObjectCommand, HeadObjectCommand, GetObjectCommand, DeleteObjectCommand } = require('@aws-sdk/client-s3'); 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' } }); const putObjectCommand = PutObjectCommand; const headObjectCommand = HeadObjectCommand; const getObjectCommand = GetObjectCommand; const deleteObjectCommand = DeleteObjectCommand; const store = new AwsS3Store({ bucketName: 'example-bucket', remoteDataPath: 'example/dir', s3Client: s3, putObjectCommand, headObjectCommand, getObjectCommand, deleteObjectCommand }); const client = new Client({ authStrategy: new RemoteAuth({ clientId: 'session-123', dataPath: './.wwebjs_auth', store: store, backupSyncIntervalMs: 600000 // in milliseconds }) }); 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!'); }); client.on('message', msg => { if (msg.body == '!ping') { msg.reply('pong'); } }); client.initialize();