Skip to content

Commit 75ea0f7

Browse files
committed
Added pairing with code. Closes #161.
1 parent 44bc8de commit 75ea0f7

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

docs/commands.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Commands
22
You can use the following commands only in `#control-room` created by the bot. Note that all the commands are case-insensitive. So, `list`, `LIST`, and `lIsT` would evaluate the same way.
33

4+
## pairWithCode
5+
Pairing with your phone number
6+
- Format: `pairWithCode <number with country code>`
7+
- Examples:
8+
- `pairWithCode 18001231234`: This would give you a code for you to enter on your phone and pair the bot with your phone number.
9+
410
## start
511
Starts a new conversation. It can be used with a name or a phone number.
612
- Format: `start <number with country code or name>`

src/discordHandler.js

+9
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ const commands = {
127127
async ping(message) {
128128
controlChannel.send(`Pong ${Date.now() - message.createdTimestamp}ms!`);
129129
},
130+
async pairwithcode(_message, params) {
131+
if (params.length !== 1) {
132+
await controlChannel.send('Please enter your number. Usage: `pairWithCode <number>`. Don\'t use "+" or any other special characters.');
133+
return;
134+
}
135+
136+
const code = await state.waClient.requestPairingCode(params[0]);
137+
await controlChannel.send(`Your pairing code is: ${code}`);
138+
},
130139
async start(_message, params) {
131140
if (!params.length) {
132141
await controlChannel.send('Please enter a phone number or name. Usage: `start <number with country code or name>`.');

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const storage = require('./storage.js');
77
const whatsappHandler = require('./whatsappHandler.js');
88

99
(async () => {
10-
const version = 'v0.10.21';
10+
const version = 'v0.10.22';
1111
state.logger = pino({ mixin() { return { version }; } }, pino.destination('logs.txt'));
1212
let autoSaver = setInterval(() => storage.save(), 5 * 60 * 1000);
1313
['SIGINT', 'uncaughtException', 'SIGTERM'].forEach((eventName) => process.on(eventName, async (err) => {

src/whatsappHandler.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const connectToWhatsApp = async (retry = 1) => {
1919
markOnlineOnConnect: false,
2020
shouldSyncHistoryMessage: () => false,
2121
generateHighQualityLinkPreview: false,
22-
browser: ['WA2DC', 'Chrome', '4.0.0']
22+
browser: ["Firefox (Linux)", "", ""]
2323
});
2424
client.contacts = state.contacts;
2525

@@ -210,14 +210,16 @@ const connectToWhatsApp = async (retry = 1) => {
210210
).key.id;
211211
state.lastMessages[messageId] = true;
212212
});
213+
214+
return client;
213215
};
214216

215217
const actions = {
216218
async start() {
217219
const baileyState = await baileys.useMultiFileAuthState('./storage/baileys');
218220
authState = baileyState.state;
219221
saveState = baileyState.saveCreds;
220-
await connectToWhatsApp();
222+
state.waClient = await connectToWhatsApp();
221223
},
222224
}
223225

0 commit comments

Comments
 (0)