mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-14 01:41:24 -06:00
Merge pull request #380 from drauber/qr_translation
Add translate capabilities to QRMessages in CW
This commit is contained in:
commit
94aa3067f6
3
.gitignore
vendored
3
.gitignore
vendored
@ -44,4 +44,5 @@ docker-compose.yaml
|
|||||||
/temp/*
|
/temp/*
|
||||||
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
*.DS_Store
|
*.DS_Store
|
||||||
|
.tool-versions
|
||||||
|
@ -63,6 +63,7 @@
|
|||||||
"fast-levenshtein": "^3.0.0",
|
"fast-levenshtein": "^3.0.0",
|
||||||
"hbs": "^4.2.0",
|
"hbs": "^4.2.0",
|
||||||
"https-proxy-agent": "^7.0.2",
|
"https-proxy-agent": "^7.0.2",
|
||||||
|
"i18next": "^23.7.19",
|
||||||
"jimp": "^0.16.13",
|
"jimp": "^0.16.13",
|
||||||
"join": "^3.0.0",
|
"join": "^3.0.0",
|
||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^4.1.0",
|
||||||
|
@ -127,6 +127,8 @@ export type Auth = {
|
|||||||
|
|
||||||
export type DelInstance = number | boolean;
|
export type DelInstance = number | boolean;
|
||||||
|
|
||||||
|
export type Language = string | 'en';
|
||||||
|
|
||||||
export type GlobalWebhook = {
|
export type GlobalWebhook = {
|
||||||
URL: string;
|
URL: string;
|
||||||
ENABLED: boolean;
|
ENABLED: boolean;
|
||||||
@ -164,6 +166,7 @@ export interface Env {
|
|||||||
WEBSOCKET: Websocket;
|
WEBSOCKET: Websocket;
|
||||||
LOG: Log;
|
LOG: Log;
|
||||||
DEL_INSTANCE: DelInstance;
|
DEL_INSTANCE: DelInstance;
|
||||||
|
LANGUAGE: Language;
|
||||||
WEBHOOK: Webhook;
|
WEBHOOK: Webhook;
|
||||||
CONFIG_SESSION_PHONE: ConfigSessionPhone;
|
CONFIG_SESSION_PHONE: ConfigSessionPhone;
|
||||||
QRCODE: QrCode;
|
QRCODE: QrCode;
|
||||||
|
@ -183,3 +183,6 @@ AUTHENTICATION:
|
|||||||
JWT:
|
JWT:
|
||||||
EXPIRIN_IN: 0 # seconds - 3600s === 1h | zero (0) - never expires
|
EXPIRIN_IN: 0 # seconds - 3600s === 1h | zero (0) - never expires
|
||||||
SECRET: L=0YWt]b2w[WF>#>:&E`
|
SECRET: L=0YWt]b2w[WF>#>:&E`
|
||||||
|
|
||||||
|
|
||||||
|
LANGUAGE: "pt-BR" # pt-BR, en
|
36
src/utils/i18n.ts
Normal file
36
src/utils/i18n.ts
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import fs from 'fs';
|
||||||
|
import i18next from 'i18next';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
import { ConfigService, Language } from '../config/env.config';
|
||||||
|
|
||||||
|
// export class i18n {
|
||||||
|
// constructor(private readonly configService: ConfigService) {
|
||||||
|
const languages = ['en', 'pt-BR'];
|
||||||
|
const translationsPath = path.join(__dirname, 'translations');
|
||||||
|
const configService: ConfigService = new ConfigService();
|
||||||
|
|
||||||
|
const resources: any = {};
|
||||||
|
|
||||||
|
languages.forEach((language) => {
|
||||||
|
const languagePath = path.join(translationsPath, `${language}.json`);
|
||||||
|
if (fs.existsSync(languagePath)) {
|
||||||
|
resources[language] = {
|
||||||
|
translation: require(languagePath),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
i18next.init({
|
||||||
|
resources,
|
||||||
|
fallbackLng: 'en',
|
||||||
|
lng: configService.get<Language>('LANGUAGE'),
|
||||||
|
debug: false,
|
||||||
|
|
||||||
|
interpolation: {
|
||||||
|
escapeValue: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
export default i18next;
|
5
src/utils/translations/en.json
Normal file
5
src/utils/translations/en.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"qrgeneratedsuccesfully": "QRCode successfully generated!",
|
||||||
|
"scanqr": "Scan this QR code within the next 40 seconds.",
|
||||||
|
"qrlimitreached": "QRCode generation limit reached, to generate a new QRCode, send the 'init' message again."
|
||||||
|
}
|
5
src/utils/translations/pt-BR.json
Normal file
5
src/utils/translations/pt-BR.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"qrgeneratedsuccesfully": "QRCode gerado com sucesso!",
|
||||||
|
"scanqr": "Escanei o QRCode com o Whatsapp nos próximos 40 segundos.",
|
||||||
|
"qrlimitreached": "Limite de geração de QRCode atingido! Para gerar um novo QRCode, envie o texto 'init' nesta conversa."
|
||||||
|
}
|
@ -9,6 +9,7 @@ import path from 'path';
|
|||||||
|
|
||||||
import { ConfigService, HttpServer, ChatWoot} from '../../config/env.config';
|
import { ConfigService, HttpServer, ChatWoot} from '../../config/env.config';
|
||||||
import { Logger } from '../../config/logger.config';
|
import { Logger } from '../../config/logger.config';
|
||||||
|
import i18next from '../../utils/i18n';
|
||||||
import { ICache } from '../abstract/abstract.cache';
|
import { ICache } from '../abstract/abstract.cache';
|
||||||
import { ChatwootDto } from '../dto/chatwoot.dto';
|
import { ChatwootDto } from '../dto/chatwoot.dto';
|
||||||
import { InstanceDto } from '../dto/instance.dto';
|
import { InstanceDto } from '../dto/instance.dto';
|
||||||
@ -1998,7 +1999,8 @@ export class ChatwootService {
|
|||||||
this.logger.verbose('event qrcode.updated');
|
this.logger.verbose('event qrcode.updated');
|
||||||
if (body.statusCode === 500) {
|
if (body.statusCode === 500) {
|
||||||
this.logger.verbose('qrcode error');
|
this.logger.verbose('qrcode error');
|
||||||
const erroQRcode = `🚨 QRCode generation limit reached, to generate a new QRCode, send the 'init' message again.`;
|
|
||||||
|
const erroQRcode = `🚨 ${i18next.t('qrlimitreached')}`;
|
||||||
|
|
||||||
this.logger.verbose('send message to chatwoot');
|
this.logger.verbose('send message to chatwoot');
|
||||||
return await this.createBotMessage(instance, erroQRcode, 'incoming');
|
return await this.createBotMessage(instance, erroQRcode, 'incoming');
|
||||||
@ -2014,9 +2016,9 @@ export class ChatwootService {
|
|||||||
writeFileSync(fileName, fileData, 'utf8');
|
writeFileSync(fileName, fileData, 'utf8');
|
||||||
|
|
||||||
this.logger.verbose('send qrcode to chatwoot');
|
this.logger.verbose('send qrcode to chatwoot');
|
||||||
await this.createBotQr(instance, 'QRCode successfully generated!', 'incoming', fileName);
|
await this.createBotQr(instance, i18next.t('qrgeneratedsuccesfully'), 'incoming', fileName);
|
||||||
|
|
||||||
let msgQrCode = `⚡️ QRCode successfully generated!\n\nScan this QR code within the next 40 seconds.`;
|
let msgQrCode = `⚡️${i18next.t('qrgeneratedsuccesfully')}\n\n${i18next.t('scanqr')}`;
|
||||||
|
|
||||||
if (body?.qrcode?.pairingCode) {
|
if (body?.qrcode?.pairingCode) {
|
||||||
msgQrCode =
|
msgQrCode =
|
||||||
|
@ -274,7 +274,7 @@ export class TypebotService {
|
|||||||
const types = {
|
const types = {
|
||||||
conversation: msg.conversation,
|
conversation: msg.conversation,
|
||||||
extendedTextMessage: msg.extendedTextMessage?.text,
|
extendedTextMessage: msg.extendedTextMessage?.text,
|
||||||
responseRowId: msg.listResponseMessage.singleSelectReply?.selectedRowId,
|
responseRowId: msg.listResponseMessage?.singleSelectReply?.selectedRowId,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.logger.verbose('type message: ' + types);
|
this.logger.verbose('type message: ' + types);
|
||||||
@ -413,7 +413,13 @@ export class TypebotService {
|
|||||||
text += element.text;
|
text += element.text;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element.children && (element.type === 'p' || element.type === 'a' || element.type === 'inline-variable' || element.type === 'variable')) {
|
if (
|
||||||
|
element.children &&
|
||||||
|
(element.type === 'p' ||
|
||||||
|
element.type === 'a' ||
|
||||||
|
element.type === 'inline-variable' ||
|
||||||
|
element.type === 'variable')
|
||||||
|
) {
|
||||||
for (const child of element.children) {
|
for (const child of element.children) {
|
||||||
text += applyFormatting(child);
|
text += applyFormatting(child);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user