File size: 2,080 Bytes
4327358
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import { ApiProperty } from '@nestjs/swagger';
import {
  AllEvents,
  AllEventType,
  WAHAEvents,
} from '@waha/structures/enums.dto';
import { Type } from 'class-transformer';
import {
  IsArray,
  IsEnum,
  IsIn,
  IsNumber,
  IsOptional,
  IsString,
  IsUrl,
  ValidateNested,
} from 'class-validator';
import { each } from 'lodash';

export enum RetryPolicy {
  LINEAR = 'linear',
  EXPONENTIAL = 'exponential',
  CONSTANT = 'constant',
}

export class RetriesConfiguration {
  @ApiProperty({
    example: 2,
  })
  @IsNumber()
  @IsOptional()
  delaySeconds?: number;

  @ApiProperty({
    example: 15,
  })
  @IsNumber()
  @IsOptional()
  attempts?: number;

  @ApiProperty({
    example: RetryPolicy.LINEAR,
  })
  @IsOptional()
  @IsEnum(RetryPolicy)
  policy?: RetryPolicy;
}

export class CustomHeader {
  @ApiProperty({
    example: 'X-My-Custom-Header',
  })
  @IsString()
  name: string;

  @ApiProperty({
    example: 'Value',
  })
  @IsString()
  value: string;
}

export class HmacConfiguration {
  @ApiProperty({
    example: 'your-secret-key',
  })
  @IsString()
  @IsOptional()
  key?: string;
}

export class WebhookConfig {
  @ApiProperty({
    example: 'https://webhook.site/11111111-1111-1111-1111-11111111',
    required: true,
    description:
      'You can use https://docs.webhook.site/ to test webhooks and see the payload',
  })
  @IsUrl({
    protocols: ['http', 'https'],
    require_protocol: true,
    require_tld: false,
  })
  url: string;

  @ApiProperty({
    example: ['message', 'session.status'],
    required: true,
  })
  @IsIn(AllEvents, { each: true })
  @IsArray()
  events: AllEventType[];

  @ApiProperty({
    example: null,
  })
  @ValidateNested()
  @Type(() => HmacConfiguration)
  @IsOptional()
  hmac?: HmacConfiguration;

  @ApiProperty({
    example: null,
  })
  @ValidateNested()
  @Type(() => RetriesConfiguration)
  @IsOptional()
  retries?: RetriesConfiguration;

  @ApiProperty({
    example: null,
  })
  @ValidateNested()
  @Type(() => CustomHeader)
  @IsArray()
  @IsOptional()
  customHeaders?: CustomHeader[];
}