mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-14 09:51:24 -06:00
fix: Now it's getting the API URL directly in the request, no longer need the variable in the env file
This commit is contained in:
parent
64e19699fb
commit
ec7ad70458
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
* Fixed error to send message in large groups
|
* Fixed error to send message in large groups
|
||||||
* Docker files adjusted
|
* Docker files adjusted
|
||||||
|
* Fixed in the postman collection the webhookByEvent parameter by webhook_by_events
|
||||||
|
* Now it's getting the API URL directly in the request, no longer need the variable in the env file
|
||||||
|
|
||||||
# 1.2.2 (2023-07-15 09:36)
|
# 1.2.2 (2023-07-15 09:36)
|
||||||
|
|
||||||
|
@ -15,8 +15,6 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- evolution_mongodb_data:/data/db
|
- evolution_mongodb_data:/data/db
|
||||||
- evolution_mongodb_configdb:/data/configdb
|
- evolution_mongodb_configdb:/data/configdb
|
||||||
networks:
|
|
||||||
- evolution-net
|
|
||||||
expose:
|
expose:
|
||||||
- 27017
|
- 27017
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "evolution-api",
|
"name": "evolution-api",
|
||||||
"version": "1.2.2",
|
"version": "1.2.3",
|
||||||
"description": "Rest api for communication with WhatsApp",
|
"description": "Rest api for communication with WhatsApp",
|
||||||
"main": "./dist/src/main.js",
|
"main": "./dist/src/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -160,8 +160,6 @@ export abstract class RouterBroker {
|
|||||||
|
|
||||||
const v = validate(ref, schema);
|
const v = validate(ref, schema);
|
||||||
|
|
||||||
console.log(v, '@checkei aqui');
|
|
||||||
|
|
||||||
if (!v.valid) {
|
if (!v.valid) {
|
||||||
const message: any[] = v.errors.map(({ property, stack, schema }) => {
|
const message: any[] = v.errors.map(({ property, stack, schema }) => {
|
||||||
let message: string;
|
let message: string;
|
||||||
@ -203,8 +201,6 @@ export abstract class RouterBroker {
|
|||||||
|
|
||||||
const v = validate(ref, schema);
|
const v = validate(ref, schema);
|
||||||
|
|
||||||
console.log(v, '@checkei aqui');
|
|
||||||
|
|
||||||
if (!v.valid) {
|
if (!v.valid) {
|
||||||
const message: any[] = v.errors.map(({ property, stack, schema }) => {
|
const message: any[] = v.errors.map(({ property, stack, schema }) => {
|
||||||
let message: string;
|
let message: string;
|
||||||
|
@ -12,6 +12,7 @@ import { ChatwootService } from '../services/chatwoot.service';
|
|||||||
import { Logger } from '../../config/logger.config';
|
import { Logger } from '../../config/logger.config';
|
||||||
import { wa } from '../types/wa.types';
|
import { wa } from '../types/wa.types';
|
||||||
import { RedisCache } from '../../db/redis.client';
|
import { RedisCache } from '../../db/redis.client';
|
||||||
|
import { isURL } from 'class-validator';
|
||||||
|
|
||||||
export class InstanceController {
|
export class InstanceController {
|
||||||
constructor(
|
constructor(
|
||||||
@ -27,7 +28,8 @@ export class InstanceController {
|
|||||||
|
|
||||||
private readonly logger = new Logger(InstanceController.name);
|
private readonly logger = new Logger(InstanceController.name);
|
||||||
|
|
||||||
public async createInstance({
|
public async createInstance(
|
||||||
|
{
|
||||||
instanceName,
|
instanceName,
|
||||||
webhook,
|
webhook,
|
||||||
webhook_by_events,
|
webhook_by_events,
|
||||||
@ -38,7 +40,9 @@ export class InstanceController {
|
|||||||
chatwoot_token,
|
chatwoot_token,
|
||||||
chatwoot_url,
|
chatwoot_url,
|
||||||
chatwoot_sign_msg,
|
chatwoot_sign_msg,
|
||||||
}: InstanceDto) {
|
}: InstanceDto,
|
||||||
|
apiURL: string,
|
||||||
|
) {
|
||||||
this.logger.verbose('requested createInstance from ' + instanceName + ' instance');
|
this.logger.verbose('requested createInstance from ' + instanceName + ' instance');
|
||||||
|
|
||||||
const mode = this.configService.get<Auth>('AUTHENTICATION').INSTANCE.MODE;
|
const mode = this.configService.get<Auth>('AUTHENTICATION').INSTANCE.MODE;
|
||||||
@ -82,6 +86,9 @@ export class InstanceController {
|
|||||||
let getEvents: string[];
|
let getEvents: string[];
|
||||||
|
|
||||||
if (webhook) {
|
if (webhook) {
|
||||||
|
if (!isURL(webhook, { require_tld: false })) {
|
||||||
|
throw new BadRequestException('Invalid "url" property in webhook');
|
||||||
|
}
|
||||||
this.logger.verbose('creating webhook');
|
this.logger.verbose('creating webhook');
|
||||||
try {
|
try {
|
||||||
this.webhookService.create(instance, {
|
this.webhookService.create(instance, {
|
||||||
@ -132,7 +139,11 @@ export class InstanceController {
|
|||||||
throw new BadRequestException('url is required');
|
throw new BadRequestException('url is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
if (!isURL(chatwoot_url, { require_tld: false })) {
|
||||||
|
throw new BadRequestException('Invalid "url" property in chatwoot');
|
||||||
|
}
|
||||||
|
|
||||||
|
const urlServer = apiURL;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.chatwootService.create(instance, {
|
this.chatwootService.create(instance, {
|
||||||
@ -203,6 +214,10 @@ export class InstanceController {
|
|||||||
let getEvents: string[];
|
let getEvents: string[];
|
||||||
|
|
||||||
if (webhook) {
|
if (webhook) {
|
||||||
|
if (!isURL(webhook, { require_tld: false })) {
|
||||||
|
throw new BadRequestException('Invalid "url" property in webhook');
|
||||||
|
}
|
||||||
|
|
||||||
this.logger.verbose('creating webhook');
|
this.logger.verbose('creating webhook');
|
||||||
try {
|
try {
|
||||||
this.webhookService.create(instance, {
|
this.webhookService.create(instance, {
|
||||||
@ -266,7 +281,11 @@ export class InstanceController {
|
|||||||
throw new BadRequestException('url is required');
|
throw new BadRequestException('url is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
if (!isURL(chatwoot_url, { require_tld: false })) {
|
||||||
|
throw new BadRequestException('Invalid "url" property in chatwoot');
|
||||||
|
}
|
||||||
|
|
||||||
|
const urlServer = apiURL;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.chatwootService.create(instance, {
|
this.chatwootService.create(instance, {
|
||||||
|
@ -14,6 +14,7 @@ const webhookSchema = new Schema<WebhookRaw>({
|
|||||||
url: { type: String, required: true },
|
url: { type: String, required: true },
|
||||||
enabled: { type: Boolean, required: true },
|
enabled: { type: Boolean, required: true },
|
||||||
events: { type: [String], required: true },
|
events: { type: [String], required: true },
|
||||||
|
webhook_by_events: { type: Boolean, required: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
export const WebhookModel = dbserver?.model(WebhookRaw.name, webhookSchema, 'webhook');
|
export const WebhookModel = dbserver?.model(WebhookRaw.name, webhookSchema, 'webhook');
|
||||||
|
@ -23,11 +23,15 @@ export class InstanceRouter extends RouterBroker {
|
|||||||
|
|
||||||
logger.verbose('request query: ');
|
logger.verbose('request query: ');
|
||||||
logger.verbose(req.query);
|
logger.verbose(req.query);
|
||||||
|
|
||||||
|
const apiURL = req.headers.host || req.hostname;
|
||||||
|
logger.verbose('API URL: ' + apiURL);
|
||||||
|
|
||||||
const response = await this.dataValidate<InstanceDto>({
|
const response = await this.dataValidate<InstanceDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: instanceNameSchema,
|
schema: instanceNameSchema,
|
||||||
ClassRef: InstanceDto,
|
ClassRef: InstanceDto,
|
||||||
execute: (instance) => instanceController.createInstance(instance),
|
execute: (instance) => instanceController.createInstance(instance, apiURL),
|
||||||
});
|
});
|
||||||
|
|
||||||
return res.status(HttpStatus.CREATED).json(response);
|
return res.status(HttpStatus.CREATED).json(response);
|
||||||
|
Loading…
Reference in New Issue
Block a user