-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (48 loc) · 1.77 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// require('dotenv').config()
//Since using modules(used type : module in package.json), that's why used import instead of require
import 'dotenv/config'
import Bard from 'bard-ai'
//insert the token from the bard page, press f12-> go to application tab -> in cookies section -> __Secure-1PSID
await Bard.init(process.env.TOKEN);
// to continue the conversation, not just take only 1 prompt
let myChat = new Bard.Chat();
// import { Client, LegacySessionAuth } from 'whatsapp-web.js'
import pkg from 'whatsapp-web.js';
const { Client, LegacySessionAuth, RemoteAuth } = pkg;
// const { Client } = require('whatsapp-web.js');
import qrcode from 'qrcode-terminal'
// import fs from 'fs'
// const fs = require('fs');
//used remoteAuth instead of legacyAuth,
// Require database
import {MongoStore} from 'wwebjs-mongo';
// const { MongoStore } = require('wwebjs-mongo');
import mongoose from 'mongoose'
// const mongoose = require('mongoose');
// Load the session data
mongoose.connect(process.env.MONGODB_URI).then(() => {
const store = new MongoStore({ mongoose: mongoose });
const client = new Client({
authStrategy: new RemoteAuth({
store: store,
backupSyncIntervalMs: 300000
})
});
client.on('qr',(qr) => {
qrcode.generate(qr,{small:true})
})
client.on('message', async(message) => {
console.log(`message to `, message.to,`message from `, message.from)
const final = ` ${message.body}`
if(message.body === '!ping') {
message.reply('pong');
}else{
// console.log(await myChat.ask(final))
message.reply(await myChat.ask(final))
}
});
client.on('ready',() => {
console.log(`Client is ready`)
})
client.initialize();
});