Spaces:
Runtime error
Runtime error
File size: 2,726 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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | import { ApiExtraModels, ApiProperty, getSchemaPath } from '@nestjs/swagger';
import { WHATSAPP_DEFAULT_SESSION_NAME } from '@waha/structures/base.dto';
import { ChatRequest } from '@waha/structures/chatting.dto';
import { BinaryFile, RemoteFile } from '@waha/structures/files.dto';
import { ChatIdProperty } from '@waha/structures/properties.dto';
import { Type } from 'class-transformer';
import {
ArrayMaxSize,
ArrayMinSize,
IsArray,
IsEnum,
IsNotEmpty,
IsOptional,
IsString,
ValidateIf,
ValidateNested,
} from 'class-validator';
export enum ButtonType {
REPLY = 'reply',
URL = 'url',
CALL = 'call',
COPY = 'copy',
}
/**
* buttons:
* - type: reply|url|call|copy
* text: Display Text
* url: only for url (required)
* phone_number: only for call (required)
*/
export class Button {
@IsEnum(ButtonType)
type: ButtonType = ButtonType.REPLY;
@ApiProperty({
example: 'Button Text',
})
@IsString()
text: string;
@ApiProperty({
example: '321321',
})
@IsOptional()
@IsString()
id?: string;
@ApiProperty({
example: 'https://example.com',
})
@ValidateIf((o) => o.type === ButtonType.URL)
@IsNotEmpty()
url?: string;
@ApiProperty({
example: '+1234567890',
})
@ValidateIf((o) => o.type === ButtonType.CALL)
@IsNotEmpty()
phoneNumber?: string;
@ApiProperty({
example: '4321',
})
@ValidateIf((o) => o.type === ButtonType.COPY)
@IsNotEmpty()
copyCode?: string;
}
@ApiExtraModels(RemoteFile, BinaryFile)
export class SendButtonsRequest {
@IsString()
session: string = WHATSAPP_DEFAULT_SESSION_NAME;
@ChatIdProperty()
@IsString()
chatId: string;
@ApiProperty({
example: 'How are you?',
})
@IsOptional()
header: string;
@ApiProperty({
oneOf: [
{ $ref: getSchemaPath(RemoteFile) },
{ $ref: getSchemaPath(BinaryFile) },
],
})
@IsOptional()
headerImage?: RemoteFile | BinaryFile;
@ApiProperty({
example: 'Tell us how are you please 🙏',
})
@IsOptional()
body: string;
@ApiProperty({
example: 'If you have any questions, please send it in the chat',
})
@IsOptional()
footer: string;
@ValidateNested({ each: true })
@Type(() => Button)
@IsArray()
@ArrayMinSize(1)
@ArrayMaxSize(4)
@ApiProperty({
example: [
{
type: 'reply',
text: 'I am good!',
},
{
type: 'call',
text: 'Call us',
phoneNumber: '+1234567890',
},
{
type: 'copy',
text: 'Copy code',
copyCode: '4321',
},
{
type: 'url',
text: 'How did you do that?',
url: 'https://waha.devlike.pro',
},
],
})
buttons: Button[];
}
|