Merge branch 'master' of https://github.com/GeneralBots/BotServer
This commit is contained in:
commit
6aa86a17c2
5 changed files with 44 additions and 22 deletions
|
@ -634,6 +634,17 @@ export class DialogKeywords {
|
|||
this.user = user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the id generation policy.
|
||||
*
|
||||
* @example SET ID NUMBER
|
||||
*
|
||||
*/
|
||||
public async setIdGeneration(mode) {
|
||||
this['idGeneration'] = mode;
|
||||
this['id'] = await this.sys().getRandomId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the maximum lines to scan in spreedsheets.
|
||||
*
|
||||
|
|
|
@ -398,6 +398,14 @@ export class GBVMService extends GBService {
|
|||
return `${$1} = sys().download (${$2}, ${$3})`;
|
||||
});
|
||||
|
||||
code = code.replace(/(\w+)\s*\=\s*CREATE FOLDER\s*(.*)/gi, ($0, $1, $2) => {
|
||||
return `${$1} = sys().createFolder (${$2})`;
|
||||
});
|
||||
|
||||
code = code.replace(/SHARE FOLDER\s*(.*)/gi, ($0, $1) => {
|
||||
return `sys().shareFolder (${$1})`;
|
||||
});
|
||||
|
||||
code = code.replace(/(create a bot farm using)(\s)(.*)/gi, ($0, $1, $2, $3) => {
|
||||
return `sys().createABotFarmUsing (${$3})`;
|
||||
});
|
||||
|
|
|
@ -382,7 +382,17 @@ export class SystemKeywords {
|
|||
* Retrives a random id with a length of five, every time it is called.
|
||||
*/
|
||||
public async getRandomId() {
|
||||
return GBAdminService.getRndReadableIdentifier().substr(5);
|
||||
|
||||
const idGeneration = this.dk['idGeneration'];
|
||||
if (idGeneration.toLowerCase() === 'number')
|
||||
{
|
||||
return GBAdminService.getNumberIdentifier();
|
||||
}
|
||||
else
|
||||
{
|
||||
return GBAdminService.getRndReadableIdentifier().substr(5);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -467,10 +467,15 @@ export class KBService implements IGBKBService {
|
|||
GBLog.info(`[GBImporter] Answer is NULL related to Question '${question}'.`);
|
||||
answer =
|
||||
'Existe um problema na base de conhecimento. Fui treinado para entender sua pergunta, avise a quem me criou que a resposta não foi informada para esta pergunta.';
|
||||
} else if (answer.indexOf('.md') > -1) {
|
||||
} else if (answer.indexOf('.md') > -1 || answer.indexOf('.docx') > -1) {
|
||||
|
||||
const mediaFilename = urlJoin(path.dirname(filePath), '..', 'articles', answer);
|
||||
if (Fs.existsSync(mediaFilename)) {
|
||||
|
||||
// TODO: Convert DOCX to MD.
|
||||
|
||||
answer = Fs.readFileSync(mediaFilename, 'utf8');
|
||||
|
||||
format = '.md';
|
||||
media = path.basename(mediaFilename);
|
||||
} else {
|
||||
|
|
|
@ -34,6 +34,7 @@ const urlJoin = require('url-join');
|
|||
|
||||
const Swagger = require('swagger-client');
|
||||
const fs = require('fs');
|
||||
const Path = require('path');
|
||||
import { GBLog, GBMinInstance, GBService, IGBPackage } from 'botlib';
|
||||
import { CollectionUtil } from 'pragmatismo-io-framework';
|
||||
import * as request from 'request-promise-native';
|
||||
|
@ -42,8 +43,6 @@ import { GBConversationalService } from '../../core.gbapp/services/GBConversatio
|
|||
import { SecService } from '../../security.gbapp/services/SecService';
|
||||
import { Messages } from '../strings';
|
||||
import { GuaribasUser } from '../../security.gbapp/models';
|
||||
import { GBConfigService } from '../../core.gbapp/services/GBConfigService';
|
||||
import { GBAdminService } from '../../admin.gbapp/services/GBAdminService';
|
||||
import { DialogKeywords } from '../../basic.gblib/services/DialogKeywords';
|
||||
const { MessageMedia, Client, LocalAuth } = require('whatsapp-web.js');
|
||||
const qrcode = require('qrcode-terminal');
|
||||
|
@ -106,8 +105,7 @@ export class WhatsappDirectLine extends GBService {
|
|||
|
||||
this.directLineClient =
|
||||
new Swagger({
|
||||
spec: JSON.parse(fs.readFileSync('directline-3.0.json', 'utf8')),
|
||||
usePromise: true
|
||||
spec: JSON.parse(fs.readFileSync('directline-3.0.json', 'utf8')), usePromise: true
|
||||
});
|
||||
const client = await this.directLineClient;
|
||||
|
||||
|
@ -120,11 +118,10 @@ export class WhatsappDirectLine extends GBService {
|
|||
switch (this.provider) {
|
||||
case 'GeneralBots':
|
||||
|
||||
const Path = require('path');
|
||||
// Initialize the browser using a local profile for each bot.
|
||||
|
||||
const gbaiName = `${this.min.botId}.gbai`;
|
||||
let localName = Path.join('work', gbaiName, 'profile');
|
||||
|
||||
let client = this.customClient = new Client({
|
||||
authStrategy: new LocalAuth(),
|
||||
puppeteer: {
|
||||
|
@ -132,9 +129,10 @@ export class WhatsappDirectLine extends GBService {
|
|||
`--user-data-dir=${localName}`]
|
||||
}
|
||||
});
|
||||
|
||||
client.initialize();
|
||||
|
||||
// Dispatches messages to the received method.
|
||||
|
||||
client.on('message', (async message => {
|
||||
await this.received(message, null);
|
||||
}).bind(this));
|
||||
|
@ -200,7 +198,6 @@ export class WhatsappDirectLine extends GBService {
|
|||
|
||||
let phoneId = this.whatsappServiceNumber.split(';')[0];
|
||||
let productId = this.whatsappServiceNumber.split(';')[1]
|
||||
|
||||
let url = `${this.INSTANCE_URL}/${productId}/${phoneId}/config`;
|
||||
WhatsappDirectLine.phones[phoneId] = this.botId;
|
||||
|
||||
|
@ -230,9 +227,7 @@ export class WhatsappDirectLine extends GBService {
|
|||
} catch (error) {
|
||||
GBLog.error(`Error initializing 3rd party Whatsapp provider(1) ${error.message}`);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public async resetConversationId(botId, number, group = '') {
|
||||
|
@ -245,15 +240,12 @@ export class WhatsappDirectLine extends GBService {
|
|||
|
||||
const options = {
|
||||
url: urlJoin(this.whatsappServiceUrl, 'status') + `?token=${this.min.instance.whatsappServiceKey}`,
|
||||
method: 'GET'
|
||||
|
||||
};
|
||||
method: 'GET'};
|
||||
|
||||
const res = await request(options);
|
||||
const json = JSON.parse(res);
|
||||
|
||||
return json.accountStatus === 'authenticated';
|
||||
|
||||
}
|
||||
|
||||
public async received(req, res) {
|
||||
|
@ -383,8 +375,8 @@ export class WhatsappDirectLine extends GBService {
|
|||
await CollectionUtil.asyncForEach(this.min.appPackages, async (e: IGBPackage) => {
|
||||
await e.onExchangeData(this.min, 'whatsappMessage', message);
|
||||
});
|
||||
const sec = new SecService();
|
||||
|
||||
const sec = new SecService();
|
||||
const user = await sec.ensureUser(this.min.instance.instanceId, from,
|
||||
fromName, '', 'whatsapp', fromName, null);
|
||||
const locale = user.locale ? user.locale : 'pt';
|
||||
|
@ -416,10 +408,9 @@ export class WhatsappDirectLine extends GBService {
|
|||
`No momento estou apenas conseguindo ler mensagens de texto.`, null);
|
||||
}
|
||||
}
|
||||
|
||||
const conversationId = WhatsappDirectLine.conversationIds[botId + from + group];
|
||||
|
||||
const client = await this.directLineClient;
|
||||
|
||||
WhatsappDirectLine.lastMessage[botId + from] = message;
|
||||
|
||||
// Check if this message is from a Human Agent itself.
|
||||
|
@ -777,11 +768,8 @@ export class WhatsappDirectLine extends GBService {
|
|||
case 'maytapi':
|
||||
let phoneId = this.whatsappServiceNumber.split(';')[0];
|
||||
let productId = this.whatsappServiceNumber.split(';')[1]
|
||||
|
||||
|
||||
let url = `${this.INSTANCE_URL}/${productId}/${phoneId}/sendMessage`;
|
||||
|
||||
|
||||
options = {
|
||||
url: url,
|
||||
method: 'post',
|
||||
|
|
Loading…
Add table
Reference in a new issue