new(all): Custom Domain support per bot.
This commit is contained in:
parent
be63b71fd9
commit
8909834b82
8 changed files with 34319 additions and 571 deletions
34802
package-lock.json
generated
34802
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -144,6 +144,7 @@
|
||||||
"typescript": "3.6.4",
|
"typescript": "3.6.4",
|
||||||
"url-join": "4.0.1",
|
"url-join": "4.0.1",
|
||||||
"vbscript-to-typescript": "1.0.8",
|
"vbscript-to-typescript": "1.0.8",
|
||||||
|
"vhost": "^3.0.2",
|
||||||
"walk-promise": "0.2.0",
|
"walk-promise": "0.2.0",
|
||||||
"washyourmouthoutwithsoap": "1.0.2",
|
"washyourmouthoutwithsoap": "1.0.2",
|
||||||
"whatsapp-web.js": "1.17.0",
|
"whatsapp-web.js": "1.17.0",
|
||||||
|
|
|
@ -32,9 +32,8 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const puppeteer = require('puppeteer');
|
|
||||||
const pluginStealth = require('puppeteer-extra-plugin-stealth');
|
|
||||||
|
|
||||||
|
import { createBrowser } from '../../core.gbapp/services/GBSSR';
|
||||||
|
|
||||||
export class ChartServices {
|
export class ChartServices {
|
||||||
|
|
||||||
|
@ -44,7 +43,7 @@ export class ChartServices {
|
||||||
* @param {string} path screenshot image full path with file name
|
* @param {string} path screenshot image full path with file name
|
||||||
*/
|
*/
|
||||||
public static async screenshot(args, path) {
|
public static async screenshot(args, path) {
|
||||||
const browser = await puppeteer.launch({ headless: false });
|
const browser = await createBrowser(null);
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
|
|
||||||
// load billboard.js assets from CDN.
|
// load billboard.js assets from CDN.
|
||||||
|
|
|
@ -45,8 +45,6 @@ import { HubSpotServices } from '../../hubspot.gblib/services/HubSpotServices';
|
||||||
import { WhatsappDirectLine } from '../../whatsapp.gblib/services/WhatsappDirectLine';
|
import { WhatsappDirectLine } from '../../whatsapp.gblib/services/WhatsappDirectLine';
|
||||||
import { GBAdminService } from '../../admin.gbapp/services/GBAdminService';
|
import { GBAdminService } from '../../admin.gbapp/services/GBAdminService';
|
||||||
const DateDiff = require('date-diff');
|
const DateDiff = require('date-diff');
|
||||||
const puppeteer = require('puppeteer');
|
|
||||||
const pluginStealth = require('puppeteer-extra-plugin-stealth');
|
|
||||||
|
|
||||||
|
|
||||||
const Path = require('path');
|
const Path = require('path');
|
||||||
|
@ -132,17 +130,7 @@ export class DialogKeywords {
|
||||||
public async getPage(step, url, username, password) {
|
public async getPage(step, url, username, password) {
|
||||||
GBLog.info(`BASIC: Web Automation GET PAGE ${url}.`);
|
GBLog.info(`BASIC: Web Automation GET PAGE ${url}.`);
|
||||||
if (!this.browser) {
|
if (!this.browser) {
|
||||||
this.browser = await puppeteer.launch({
|
this.browser =
|
||||||
args: [
|
|
||||||
'--ignore-certificate-errors',
|
|
||||||
'--no-sandbox',
|
|
||||||
'--disable-setuid-sandbox',
|
|
||||||
'--window-size=1920,1080',
|
|
||||||
"--disable-accelerated-2d-canvas",
|
|
||||||
"--disable-gpu"],
|
|
||||||
ignoreHTTPSErrors: true,
|
|
||||||
headless: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
// set the HTTP Basic Authentication credential
|
// set the HTTP Basic Authentication credential
|
||||||
|
|
||||||
|
|
|
@ -43,11 +43,9 @@ import { GBVMService } from './GBVMService';
|
||||||
import { ThisPath } from 'botbuilder-dialogs';
|
import { ThisPath } from 'botbuilder-dialogs';
|
||||||
const Fs = require('fs');
|
const Fs = require('fs');
|
||||||
const Excel = require('exceljs');
|
const Excel = require('exceljs');
|
||||||
|
import { createBrowser } from '../../core.gbapp/services/GBSSR';
|
||||||
const urlJoin = require('url-join');
|
const urlJoin = require('url-join');
|
||||||
const url = require('url');
|
const url = require('url');
|
||||||
const puppeteer = require('puppeteer')
|
|
||||||
const pluginStealth = require('puppeteer-extra-plugin-stealth');
|
|
||||||
const { TwitterApi } = require('twitter-api-v2');
|
const { TwitterApi } = require('twitter-api-v2');
|
||||||
|
|
||||||
|
|
||||||
|
@ -246,7 +244,6 @@ export class SystemKeywords {
|
||||||
* @returns
|
* @returns
|
||||||
*
|
*
|
||||||
* @see http://tabulator.info/examples/5.2
|
* @see http://tabulator.info/examples/5.2
|
||||||
* @see puppeteer.
|
|
||||||
*/
|
*/
|
||||||
private async renderTable(data, renderPDF, renderImage) {
|
private async renderTable(data, renderPDF, renderImage) {
|
||||||
|
|
||||||
|
@ -261,7 +258,7 @@ export class SystemKeywords {
|
||||||
|
|
||||||
|
|
||||||
const gbaiName = `${this.min.botId}.gbai`;
|
const gbaiName = `${this.min.botId}.gbai`;
|
||||||
const browser = await puppeteer.launch({ headless: true });
|
const browser = await createBrowser(null);
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
|
|
||||||
// Includes the associated CSS related to current theme.
|
// Includes the associated CSS related to current theme.
|
||||||
|
|
|
@ -43,6 +43,7 @@ const express = require('express');
|
||||||
const child_process = require('child_process');
|
const child_process = require('child_process');
|
||||||
const rimraf = require('rimraf');
|
const rimraf = require('rimraf');
|
||||||
const request = require('request-promise-native');
|
const request = require('request-promise-native');
|
||||||
|
const vhost = require('vhost')
|
||||||
import { GBError, GBLog, GBMinInstance, IGBCoreService, IGBDeployer, IGBInstance, IGBPackage } from 'botlib';
|
import { GBError, GBLog, GBMinInstance, IGBCoreService, IGBDeployer, IGBInstance, IGBPackage } from 'botlib';
|
||||||
import { AzureSearch } from 'pragmatismo-io-framework';
|
import { AzureSearch } from 'pragmatismo-io-framework';
|
||||||
import { CollectionUtil } from 'pragmatismo-io-framework';
|
import { CollectionUtil } from 'pragmatismo-io-framework';
|
||||||
|
|
|
@ -39,7 +39,8 @@
|
||||||
const puppeteer = require('puppeteer');
|
const puppeteer = require('puppeteer');
|
||||||
const pluginStealth = require('puppeteer-extra-plugin-stealth');
|
const pluginStealth = require('puppeteer-extra-plugin-stealth');
|
||||||
import { NextFunction, Request, Response } from "express";
|
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
|
// https://hackernoon.com/tips-and-tricks-for-web-scraping-with-puppeteer-ed391a63d952
|
||||||
// Dont download all resources, we just need the HTML
|
// Dont download all resources, we just need the HTML
|
||||||
|
@ -79,6 +80,30 @@ const skippedResources = [
|
||||||
|
|
||||||
const RENDER_CACHE = new Map();
|
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) {
|
async function recursiveFindInFrames(inputFrame, selector) {
|
||||||
const frames = inputFrame.childFrames();
|
const frames = inputFrame.childFrames();
|
||||||
const results = await Promise.all(
|
const results = await Promise.all(
|
||||||
|
@ -116,12 +141,7 @@ async function ssr(url: string, useCache: boolean, cacheRefreshRate: number) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const browser = await puppeteer.launch({
|
const browser = createBrowser(null);
|
||||||
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 stylesheetContents = {};
|
const stylesheetContents = {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -304,4 +324,4 @@ function ssrForBots(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export { ssr, clearCache, ssrForBots };
|
export { createBrowser, ssr, clearCache, ssrForBots };
|
||||||
|
|
|
@ -47,9 +47,13 @@ import { DialogKeywords } from '../../basic.gblib/services/DialogKeywords';
|
||||||
import { GBAdminService } from '../../admin.gbapp/services/GBAdminService';
|
import { GBAdminService } from '../../admin.gbapp/services/GBAdminService';
|
||||||
import { GBMinService } from '../../core.gbapp/services/GBMinService';
|
import { GBMinService } from '../../core.gbapp/services/GBMinService';
|
||||||
import { GBConfigService } from '../../core.gbapp/services/GBConfigService';
|
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 { MessageMedia, Client, LocalAuth } = require('whatsapp-web.js');
|
||||||
const qrcode = require('qrcode-terminal');
|
const qrcode = require('qrcode-terminal');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Support for Whatsapp.
|
* Support for Whatsapp.
|
||||||
*/
|
*/
|
||||||
|
@ -77,6 +81,7 @@ export class WhatsappDirectLine extends GBService {
|
||||||
provider: any;
|
provider: any;
|
||||||
INSTANCE_URL = 'https://api.maytapi.com/api';
|
INSTANCE_URL = 'https://api.maytapi.com/api';
|
||||||
private customClient;
|
private customClient;
|
||||||
|
private browserWSEndpoint;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
min: GBMinInstance,
|
min: GBMinInstance,
|
||||||
|
@ -130,27 +135,30 @@ export class WhatsappDirectLine extends GBService {
|
||||||
else {
|
else {
|
||||||
|
|
||||||
// Initialize the browser using a local profile for each bot.
|
// Initialize the browser using a local profile for each bot.
|
||||||
|
|
||||||
const gbaiName = `${this.min.botId}.gbai`;
|
const gbaiName = `${this.min.botId}.gbai`;
|
||||||
let localName = Path.join('work', gbaiName, 'profile');
|
let localName = Path.join('work', gbaiName, 'profile');
|
||||||
|
|
||||||
|
const browser = await createBrowser(null);
|
||||||
let client = this.customClient = new Client({
|
let client = this.customClient = new Client({
|
||||||
authStrategy: new LocalAuth({
|
authStrategy: new LocalAuth({
|
||||||
clientId: this.min.botId,
|
clientId: this.min.botId,
|
||||||
dataPath: localName
|
dataPath: localName
|
||||||
}),
|
}),
|
||||||
puppeteer: {
|
puppeteer: browser
|
||||||
headless: false, args: ['--disable-features=site-per-process',
|
|
||||||
`--user-data-dir=${localName}`]
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
client.initialize();
|
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.
|
// Dispatches messages to the received method.
|
||||||
|
|
||||||
|
|
||||||
client.on('message', (async message => {
|
client.on('message', async message => {
|
||||||
await this.WhatsAppCallback(message, null);
|
await this.WhatsAppCallback(message, null);
|
||||||
}).bind(this));
|
}).bind(this);
|
||||||
|
|
||||||
client.on('qr', (async (qr) => {
|
client.on('qr', (async (qr) => {
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue