[core] Add metadata
This commit is contained in:
1 parent
1fe0e69914
commit
ba120024a6
5 files changed
+64
No files matched your search
@@ -60,6 +60,7 @@ export abstract class SessionManager implements BeforeApplicationShutdown {
|
||||
const data: WAHAWebhook = {
|
||||
event: event,
|
||||
session: session.name,
|
||||
metadata: session.sessionConfig.metadata,
|
||||
me: me,
|
||||
payload: payload,
|
||||
engine: session.engine,
|
||||
|
||||
@@ -137,6 +137,7 @@ export class WebhookConductorCore implements WebhookConductor {
|
||||
const json: WAHAWebhook = {
|
||||
event: event,
|
||||
session: session.name,
|
||||
metadata: session.sessionConfig.metadata,
|
||||
me: me,
|
||||
payload: data,
|
||||
engine: session.engine,
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import {
|
||||
registerDecorator,
|
||||
ValidationArguments,
|
||||
ValidationOptions,
|
||||
} from 'class-validator';
|
||||
|
||||
export function IsDynamicObject(validationOptions?: ValidationOptions) {
|
||||
return function (object: Record<string, any>, propertyName: string) {
|
||||
registerDecorator({
|
||||
name: 'IsDynamicObject',
|
||||
target: object.constructor,
|
||||
propertyName: propertyName,
|
||||
constraints: [],
|
||||
options: validationOptions,
|
||||
validator: {
|
||||
validate(value: any, args: ValidationArguments) {
|
||||
if (!value || typeof value !== 'object') {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const key in value) {
|
||||
if (typeof key !== 'string' || typeof value[key] !== 'string') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
defaultMessage(validationArguments?: ValidationArguments): string {
|
||||
return `${validationArguments.property} accepts string key-value pairs only`;
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { BooleanString } from '@waha/nestjs/validation/BooleanString';
|
||||
import { IsDynamicObject } from '@waha/nestjs/validation/IsDynamicObject';
|
||||
import { Transform, Type } from 'class-transformer';
|
||||
import {
|
||||
IsArray,
|
||||
@@ -86,6 +87,19 @@ export class SessionConfig {
|
||||
@IsOptional()
|
||||
webhooks?: WebhookConfig[];
|
||||
|
||||
@ApiProperty({
|
||||
example: {
|
||||
'user.id': '123',
|
||||
'user.email': 'email@example.com',
|
||||
},
|
||||
description:
|
||||
"Metadata for the session. You'll get 'metadata' in all webhooks.",
|
||||
required: false,
|
||||
})
|
||||
@IsDynamicObject()
|
||||
@IsOptional()
|
||||
metadata?: Map<string, string>;
|
||||
|
||||
@ApiProperty({
|
||||
example: null,
|
||||
})
|
||||
@@ -94,6 +108,10 @@ export class SessionConfig {
|
||||
@IsOptional()
|
||||
proxy?: ProxyConfig;
|
||||
|
||||
@ApiProperty({
|
||||
required: false,
|
||||
default: false,
|
||||
})
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
debug: boolean;
|
||||
|
||||
@@ -106,6 +106,15 @@ export class WAHAWebhook {
|
||||
})
|
||||
session: string;
|
||||
|
||||
@ApiProperty({
|
||||
example: {
|
||||
'user.id': '123',
|
||||
'user.email': 'email@example.com',
|
||||
},
|
||||
description: 'Metadata for the session.',
|
||||
})
|
||||
metadata?: Map<string, string>;
|
||||
|
||||
@ApiProperty({
|
||||
example: WAHAEngine.WEBJS,
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user