Merge branch 'master' of
This commit is contained in:
commit
25342e90fe
3 changed files with 32 additions and 26 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
## [2.0.178](https://github.com/GeneralBots/BotServer/compare/2.0.177...2.0.178) (2022-10-09)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **whatsapp.gblib:** SEND FILE and WPP providers. ([3f7e024](https://github.com/GeneralBots/BotServer/commit/3f7e024b58660d0be0734dc5f3a3cd7884df3727))
|
||||||
|
|
||||||
## [2.0.177](https://github.com/GeneralBots/BotServer/compare/2.0.176...2.0.177) (2022-10-04)
|
## [2.0.177](https://github.com/GeneralBots/BotServer/compare/2.0.176...2.0.177) (2022-10-04)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "botserver",
|
"name": "botserver",
|
||||||
"version": "2.0.177",
|
"version": "2.0.178",
|
||||||
"description": "General Bot Community Edition open-core server.",
|
"description": "General Bot Community Edition open-core server.",
|
||||||
"main": "./boot.js",
|
"main": "./boot.js",
|
||||||
"bugs": "https://github.com/pragmatismo-io/BotServer/issues",
|
"bugs": "https://github.com/pragmatismo-io/BotServer/issues",
|
||||||
|
|
|
@ -141,7 +141,8 @@ export class WhatsappDirectLine extends GBService {
|
||||||
const gbaiName = `${this.min.botId}.gbai`;
|
const gbaiName = `${this.min.botId}.gbai`;
|
||||||
const localName = Path.join('work', gbaiName, 'profile');
|
const localName = Path.join('work', gbaiName, 'profile');
|
||||||
|
|
||||||
const createClient = (browserWSEndpoint) => {
|
|
||||||
|
const createClient = async (browserWSEndpoint) => {
|
||||||
let puppeteer: any = {
|
let puppeteer: any = {
|
||||||
headless: false, args: [
|
headless: false, args: [
|
||||||
'--disable-setuid-sandbox',
|
'--disable-setuid-sandbox',
|
||||||
|
@ -161,7 +162,8 @@ export class WhatsappDirectLine extends GBService {
|
||||||
puppeteer: puppeteer
|
puppeteer: puppeteer
|
||||||
});
|
});
|
||||||
|
|
||||||
client.initialize();
|
await client.initialize();
|
||||||
|
this.browserWSEndpoint = client.pupBrowser.wsEndpoint();
|
||||||
|
|
||||||
client.on('message', (async message => {
|
client.on('message', (async message => {
|
||||||
await this.WhatsAppCallback(message, null);
|
await this.WhatsAppCallback(message, null);
|
||||||
|
@ -202,7 +204,6 @@ export class WhatsappDirectLine extends GBService {
|
||||||
|
|
||||||
client.on('authenticated', async () => {
|
client.on('authenticated', async () => {
|
||||||
this.browserWSEndpoint = client.pupBrowser.wsEndpoint();
|
this.browserWSEndpoint = client.pupBrowser.wsEndpoint();
|
||||||
|
|
||||||
const chats = await client.getChats();
|
const chats = await client.getChats();
|
||||||
await CollectionUtil.asyncForEach(chats, async chat => {
|
await CollectionUtil.asyncForEach(chats, async chat => {
|
||||||
|
|
||||||
|
@ -219,21 +220,12 @@ export class WhatsappDirectLine extends GBService {
|
||||||
|
|
||||||
GBLog.info(`WhatsApp QR Code authenticated for ${this.botId}.`);
|
GBLog.info(`WhatsApp QR Code authenticated for ${this.botId}.`);
|
||||||
});
|
});
|
||||||
|
client.pupBrowser.on('disconnected', (async () => {
|
||||||
|
GBLog.info(`Browser terminated. Restarting ${this.min.botId} WhatsApp native provider.`);
|
||||||
|
await (createClient.bind(this))(null);
|
||||||
|
}).bind(this));
|
||||||
};
|
};
|
||||||
|
await (createClient.bind(this))(this.browserWSEndpoint);
|
||||||
client.pupBrowser.on('disconnected', (async () => {
|
|
||||||
GBLog.info(`Browser crashed. Restarting ${this.min.botId} WhatsApp native provider.`);
|
|
||||||
await (createClient.bind(this))(null);
|
|
||||||
}).bind(this));
|
|
||||||
client.pupPage.on('error', (async () => {
|
|
||||||
GBLog.info(`Page crashed. Restarting ${this.min.botId} WhatsApp native provider.`);
|
|
||||||
if (!client.pupPage.isClosed()) {
|
|
||||||
client.pupPage.close();
|
|
||||||
} await (createClient.bind(this))(null);
|
|
||||||
}).bind(this));
|
|
||||||
|
|
||||||
(createClient.bind(this))(this.browserWSEndpoint);
|
|
||||||
|
|
||||||
|
|
||||||
setUrl = false;
|
setUrl = false;
|
||||||
}
|
}
|
||||||
|
@ -300,16 +292,23 @@ export class WhatsappDirectLine extends GBService {
|
||||||
public async check() {
|
public async check() {
|
||||||
|
|
||||||
GBLog.info(`GBWhatsapp: Checking server...`);
|
GBLog.info(`GBWhatsapp: Checking server...`);
|
||||||
|
switch (this.provider) {
|
||||||
|
case 'GeneralBots':
|
||||||
|
const info = await this.customClient.getState();
|
||||||
|
GBLog.info(`GBWhatsapp: ${info.WAState}.`);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
const options = {
|
||||||
|
url: urlJoin(this.whatsappServiceUrl, 'status') + `?token=${this.min.instance.whatsappServiceKey}`,
|
||||||
|
method: 'GET'
|
||||||
|
};
|
||||||
|
|
||||||
const options = {
|
const res = await request(options);
|
||||||
url: urlJoin(this.whatsappServiceUrl, 'status') + `?token=${this.min.instance.whatsappServiceKey}`,
|
const json = JSON.parse(res);
|
||||||
method: 'GET'
|
|
||||||
};
|
|
||||||
|
|
||||||
const res = await request(options);
|
return json.accountStatus === 'authenticated';
|
||||||
const json = JSON.parse(res);
|
break;
|
||||||
|
}
|
||||||
return json.accountStatus === 'authenticated';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static providerFromRequest(req) {
|
public static providerFromRequest(req) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue