new(all): Custom Domain support per bot.

This commit is contained in:
rodrigorodriguez 2022-10-02 13:37:37 -03:00
parent be63b71fd9
commit 8909834b82
8 changed files with 34319 additions and 571 deletions

34802
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -144,6 +144,7 @@
"typescript": "3.6.4",
"url-join": "4.0.1",
"vbscript-to-typescript": "1.0.8",
"vhost": "^3.0.2",
"walk-promise": "0.2.0",
"washyourmouthoutwithsoap": "1.0.2",
"whatsapp-web.js": "1.17.0",

View file

@ -32,9 +32,8 @@
'use strict';
const puppeteer = require('puppeteer');
const pluginStealth = require('puppeteer-extra-plugin-stealth');
import { createBrowser } from '../../core.gbapp/services/GBSSR';
export class ChartServices {
@ -44,7 +43,7 @@ export class ChartServices {
* @param {string} path screenshot image full path with file name
*/
public static async screenshot(args, path) {
const browser = await puppeteer.launch({ headless: false });
const browser = await createBrowser(null);
const page = await browser.newPage();
// load billboard.js assets from CDN.

View file

@ -45,8 +45,6 @@ import { HubSpotServices } from '../../hubspot.gblib/services/HubSpotServices';
import { WhatsappDirectLine } from '../../whatsapp.gblib/services/WhatsappDirectLine';
import { GBAdminService } from '../../admin.gbapp/services/GBAdminService';
const DateDiff = require('date-diff');
const puppeteer = require('puppeteer');
const pluginStealth = require('puppeteer-extra-plugin-stealth');
const Path = require('path');
@ -132,17 +130,7 @@ export class DialogKeywords {
public async getPage(step, url, username, password) {
GBLog.info(`BASIC: Web Automation GET PAGE ${url}.`);
if (!this.browser) {
this.browser = await puppeteer.launch({
args: [
'--ignore-certificate-errors',
'--no-sandbox',
'--disable-setuid-sandbox',
'--window-size=1920,1080',
"--disable-accelerated-2d-canvas",
"--disable-gpu"],
ignoreHTTPSErrors: true,
headless: false,
});
this.browser =
// set the HTTP Basic Authentication credential

View file

@ -43,11 +43,9 @@ import { GBVMService } from './GBVMService';
import { ThisPath } from 'botbuilder-dialogs';
const Fs = require('fs');
const Excel = require('exceljs');
import { createBrowser } from '../../core.gbapp/services/GBSSR';
const urlJoin = require('url-join');
const url = require('url');
const puppeteer = require('puppeteer')
const pluginStealth = require('puppeteer-extra-plugin-stealth');
const { TwitterApi } = require('twitter-api-v2');
@ -246,7 +244,6 @@ export class SystemKeywords {
* @returns
*
* @see http://tabulator.info/examples/5.2
* @see puppeteer.
*/
private async renderTable(data, renderPDF, renderImage) {
@ -261,7 +258,7 @@ export class SystemKeywords {
const gbaiName = `${this.min.botId}.gbai`;
const browser = await puppeteer.launch({ headless: true });
const browser = await createBrowser(null);
const page = await browser.newPage();
// Includes the associated CSS related to current theme.

View file

@ -43,6 +43,7 @@ const express = require('express');
const child_process = require('child_process');
const rimraf = require('rimraf');
const request = require('request-promise-native');
const vhost = require('vhost')
import { GBError, GBLog, GBMinInstance, IGBCoreService, IGBDeployer, IGBInstance, IGBPackage } from 'botlib';
import { AzureSearch } from 'pragmatismo-io-framework';
import { CollectionUtil } from 'pragmatismo-io-framework';

View file

@ -39,7 +39,8 @@
const puppeteer = require('puppeteer');
const pluginStealth = require('puppeteer-extra-plugin-stealth');
import { NextFunction, Request, Response } from "express";
import { Browser } from "puppeteer";
const Path = require('path');
// https://hackernoon.com/tips-and-tricks-for-web-scraping-with-puppeteer-ed391a63d952
// Dont download all resources, we just need the HTML
@ -79,6 +80,30 @@ const skippedResources = [
const RENDER_CACHE = new Map();
async function createBrowser(profile): Promise<Browser> {
const gbaiName = `${this.min.botId}.gbai`;
let localName = Path.join('work', gbaiName, 'profile');
const browser = await puppeteer.launch({
args: [
'--ignore-certificate-errors',
'--no-sandbox',
'--disable-setuid-sandbox',
'--window-size=1920,1080',
"--disable-accelerated-2d-canvas",
"--disable-gpu",
"--disable-features=site-per-process",
`--user-data-dir=${localName}`
],
ignoreHTTPSErrors: true,
headless: false,
});
return browser
}
async function recursiveFindInFrames(inputFrame, selector) {
const frames = inputFrame.childFrames();
const results = await Promise.all(
@ -116,12 +141,7 @@ async function ssr(url: string, useCache: boolean, cacheRefreshRate: number) {
};
}
}
const browser = await puppeteer.launch({
headless: false,
args: ["--single-process", "--no-zygote", "--no-sandbox", "--disable-features=site-per-process"]
});
// browserWSEndpoint = await browserT.wsEndpoint();
// const browser = await puppeteer.connect({ browserWSEndpoint });
const browser = createBrowser(null);
const stylesheetContents = {};
try {
@ -304,4 +324,4 @@ function ssrForBots(
}
export { ssr, clearCache, ssrForBots };
export { createBrowser, ssr, clearCache, ssrForBots };

View file

@ -47,9 +47,13 @@ import { DialogKeywords } from '../../basic.gblib/services/DialogKeywords';
import { GBAdminService } from '../../admin.gbapp/services/GBAdminService';
import { GBMinService } from '../../core.gbapp/services/GBMinService';
import { GBConfigService } from '../../core.gbapp/services/GBConfigService';
import { createBrowser } from '../../core.gbapp/services/GBSSR';
const puppeteer = require('puppeteer');
const { MessageMedia, Client, LocalAuth } = require('whatsapp-web.js');
const qrcode = require('qrcode-terminal');
/**
* Support for Whatsapp.
*/
@ -77,6 +81,7 @@ export class WhatsappDirectLine extends GBService {
provider: any;
INSTANCE_URL = 'https://api.maytapi.com/api';
private customClient;
private browserWSEndpoint;
constructor(
min: GBMinInstance,
@ -130,27 +135,30 @@ export class WhatsappDirectLine extends GBService {
else {
// Initialize the browser using a local profile for each bot.
const gbaiName = `${this.min.botId}.gbai`;
let localName = Path.join('work', gbaiName, 'profile');
const browser = await createBrowser(null);
let client = this.customClient = new Client({
authStrategy: new LocalAuth({
clientId: this.min.botId,
dataPath: localName
}),
puppeteer: {
headless: false, args: ['--disable-features=site-per-process',
`--user-data-dir=${localName}`]
}
puppeteer: browser
});
client.initialize();
this.browserWSEndpoint = browser.wsEndpoint(); // store for later
var self = this;
client.on('disconnected', async () => {
client.browser = await puppeteer.connect({browserWSEndpoint: self.browserWSEndpoint});
}).bind(this);
// Dispatches messages to the received method.
client.on('message', (async message => {
client.on('message', async message => {
await this.WhatsAppCallback(message, null);
}).bind(this));
}).bind(this);
client.on('qr', (async (qr) => {