fix(whatsapp.gblib): Web can show images again and working directory on startup being created.

This commit is contained in:
Rodrigo Rodriguez 2019-08-26 13:21:52 -03:00
parent 2b4fb68022
commit 8d512ca6a1
2 changed files with 26 additions and 11 deletions

View file

@ -388,23 +388,28 @@ export class KBService {
html = marked(answer.content);
if (channel === 'webchat' &&
GBConfigService.get('DISABLE_WEB') !== 'true') {
const locale = step.context.activity.locale;
await step.context.sendActivity(Messages[locale].will_answer_projector);
await conversationalService.sendEvent(step, 'play', {
playerType: 'markdown',
data: {
content: html,
answer: answer,
prevId: answer.prevId,
nextId: answer.nextId
}
});
await this.sendMarkdownToWeb(step, conversationalService, html, answer);
}
else if (channel === 'whatsapp') {
await this.sendMarkdownToMobile(step, answer, conversationalService, min);
}
}
private async sendMarkdownToWeb(step: GBDialogStep, conversationalService: IGBConversationalService, html: string, answer: GuaribasAnswer) {
const locale = step.context.activity.locale;
await step.context.sendActivity(Messages[locale].will_answer_projector);
html = html.replace(/src\=\"kb\//g, `src=\"../kb/`);
await conversationalService.sendEvent(step, 'play', {
playerType: 'markdown',
data: {
content: html,
answer: answer,
prevId: answer.prevId,
nextId: answer.nextId
}
});
}
private async sendMarkdownToMobile(step: GBDialogStep, answer: GuaribasAnswer, conversationalService: IGBConversationalService, min: GBMinInstance) {
let text = answer.content;

View file

@ -38,6 +38,8 @@
const express = require('express');
const bodyParser = require('body-parser');
import * as fs from 'fs';
var mkdirp = require('mkdirp');
import { GBLog, IGBCoreService, IGBInstance, IGBPackage, GBMinInstance } from 'botlib';
import { GBAdminService } from '../packages/admin.gbapp/services/GBAdminService';
@ -88,6 +90,14 @@ export class GBServer {
server.use(bodyParser.json());
server.use(bodyParser.urlencoded({ extended: true }));
// Creates working directory.
const workDir = 'workDir';
if (!fs.existsSync(workDir)){
mkdirp.sync(workDir);
}
server.listen(port, () => {
(async () => {
try {