mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-14 01:41:24 -06:00
Added connection functionality via pairing code
This commit is contained in:
parent
93a5d07f9a
commit
8f4d44a212
@ -1,3 +1,9 @@
|
|||||||
|
# 1.4.0 (homolog)
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* Added connection functionality via pairing code
|
||||||
|
|
||||||
# 1.3.2 (2023-07-21 17:19)
|
# 1.3.2 (2023-07-21 17:19)
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "evolution-api",
|
"name": "evolution-api",
|
||||||
"version": "1.3.2",
|
"version": "1.4.0",
|
||||||
"description": "Rest api for communication with WhatsApp",
|
"description": "Rest api for communication with WhatsApp",
|
||||||
"main": "./dist/src/main.js",
|
"main": "./dist/src/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -58,6 +58,7 @@ export const instanceNameSchema: JSONSchema7 = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
qrcode: { type: 'boolean', enum: [true, false] },
|
qrcode: { type: 'boolean', enum: [true, false] },
|
||||||
|
number: { type: 'string', pattern: '^\\d+[\\.@\\w-]+' },
|
||||||
token: { type: 'string' },
|
token: { type: 'string' },
|
||||||
},
|
},
|
||||||
...isNotEmpty('instanceName'),
|
...isNotEmpty('instanceName'),
|
||||||
|
@ -34,6 +34,7 @@ export class InstanceController {
|
|||||||
webhook_by_events,
|
webhook_by_events,
|
||||||
events,
|
events,
|
||||||
qrcode,
|
qrcode,
|
||||||
|
number,
|
||||||
token,
|
token,
|
||||||
chatwoot_account_id,
|
chatwoot_account_id,
|
||||||
chatwoot_token,
|
chatwoot_token,
|
||||||
@ -102,10 +103,16 @@ export class InstanceController {
|
|||||||
|
|
||||||
if (!chatwoot_account_id || !chatwoot_token || !chatwoot_url) {
|
if (!chatwoot_account_id || !chatwoot_token || !chatwoot_url) {
|
||||||
let getQrcode: wa.QrCode;
|
let getQrcode: wa.QrCode;
|
||||||
|
let getParingCode: string;
|
||||||
|
|
||||||
if (qrcode) {
|
if (qrcode) {
|
||||||
this.logger.verbose('creating qrcode');
|
this.logger.verbose('creating qrcode');
|
||||||
await instance.connectToWhatsapp();
|
await instance.connectToWhatsapp();
|
||||||
|
if (number) {
|
||||||
|
this.logger.verbose('creating number');
|
||||||
|
await delay(5000);
|
||||||
|
getParingCode = await instance.client.requestPairingCode(number);
|
||||||
|
}
|
||||||
await delay(2000);
|
await delay(2000);
|
||||||
getQrcode = instance.qrCode;
|
getQrcode = instance.qrCode;
|
||||||
}
|
}
|
||||||
@ -120,6 +127,7 @@ export class InstanceController {
|
|||||||
webhook,
|
webhook,
|
||||||
webhook_by_events,
|
webhook_by_events,
|
||||||
events: getEvents,
|
events: getEvents,
|
||||||
|
pairingCode: getParingCode,
|
||||||
qrcode: getQrcode,
|
qrcode: getQrcode,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -132,6 +140,7 @@ export class InstanceController {
|
|||||||
webhook,
|
webhook,
|
||||||
webhook_by_events,
|
webhook_by_events,
|
||||||
events: getEvents,
|
events: getEvents,
|
||||||
|
pairingCode: getParingCode,
|
||||||
qrcode: getQrcode,
|
qrcode: getQrcode,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -195,7 +204,7 @@ export class InstanceController {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public async connectToWhatsapp({ instanceName }: InstanceDto) {
|
public async connectToWhatsapp({ instanceName, number = null }: InstanceDto) {
|
||||||
try {
|
try {
|
||||||
this.logger.verbose(
|
this.logger.verbose(
|
||||||
'requested connectToWhatsapp from ' + instanceName + ' instance',
|
'requested connectToWhatsapp from ' + instanceName + ' instance',
|
||||||
@ -210,8 +219,17 @@ export class InstanceController {
|
|||||||
case 'close':
|
case 'close':
|
||||||
this.logger.verbose('connecting');
|
this.logger.verbose('connecting');
|
||||||
await instance.connectToWhatsapp();
|
await instance.connectToWhatsapp();
|
||||||
|
let pairingCode = null;
|
||||||
|
if (number) {
|
||||||
|
this.logger.verbose('creating pairing code');
|
||||||
|
await delay(5000);
|
||||||
|
pairingCode = await instance.client.requestPairingCode(number);
|
||||||
|
}
|
||||||
await delay(2000);
|
await delay(2000);
|
||||||
return instance.qrCode;
|
return {
|
||||||
|
pairingCode,
|
||||||
|
...instance.qrCode,
|
||||||
|
};
|
||||||
case 'connecting':
|
case 'connecting':
|
||||||
return instance.qrCode;
|
return instance.qrCode;
|
||||||
default:
|
default:
|
||||||
|
@ -4,6 +4,7 @@ export class InstanceDto {
|
|||||||
webhook_by_events?: boolean;
|
webhook_by_events?: boolean;
|
||||||
events?: string[];
|
events?: string[];
|
||||||
qrcode?: boolean;
|
qrcode?: boolean;
|
||||||
|
number?: string;
|
||||||
token?: string;
|
token?: string;
|
||||||
chatwoot_account_id?: string;
|
chatwoot_account_id?: string;
|
||||||
chatwoot_token?: string;
|
chatwoot_token?: string;
|
||||||
|
@ -60,7 +60,8 @@ export class InstanceRouter extends RouterBroker {
|
|||||||
request: req,
|
request: req,
|
||||||
schema: instanceNameSchema,
|
schema: instanceNameSchema,
|
||||||
ClassRef: InstanceDto,
|
ClassRef: InstanceDto,
|
||||||
execute: (instance) => instanceController.connectToWhatsapp(instance),
|
execute: (instance, data) =>
|
||||||
|
instanceController.connectToWhatsapp(instance, data),
|
||||||
});
|
});
|
||||||
|
|
||||||
return res.status(HttpStatus.OK).json(response);
|
return res.status(HttpStatus.OK).json(response);
|
||||||
|
@ -545,6 +545,11 @@ export class WAStartupService {
|
|||||||
return this.eventEmitter.emit('no.connection', this.instance.name);
|
return this.eventEmitter.emit('no.connection', this.instance.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pairing code
|
||||||
|
// await delay(5000);
|
||||||
|
// const code = await this.client.requestPairingCode('557499879409');
|
||||||
|
// console.log(`Pairing code: ${code}`);
|
||||||
|
|
||||||
this.logger.verbose('Incrementing QR code count');
|
this.logger.verbose('Incrementing QR code count');
|
||||||
this.instance.qrcode.count++;
|
this.instance.qrcode.count++;
|
||||||
|
|
||||||
|
@ -25,7 +25,11 @@ export enum Events {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export declare namespace wa {
|
export declare namespace wa {
|
||||||
export type QrCode = { count?: number; base64?: string; code?: string };
|
export type QrCode = {
|
||||||
|
count?: number;
|
||||||
|
base64?: string;
|
||||||
|
code?: string;
|
||||||
|
};
|
||||||
export type Instance = {
|
export type Instance = {
|
||||||
qrcode?: QrCode;
|
qrcode?: QrCode;
|
||||||
authState?: { state: AuthenticationState; saveCreds: () => void };
|
authState?: { state: AuthenticationState; saveCreds: () => void };
|
||||||
|
Loading…
Reference in New Issue
Block a user