mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-14 09:51:24 -06:00
feat: Route to send status broadcast
This commit is contained in:
parent
9604f5c317
commit
4bf4b4a045
@ -196,7 +196,9 @@ export const statusMessageSchema: JSONSchema7 = {
|
||||
statusMessage: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
text: { type: 'string' },
|
||||
type: { type: 'string', enum: ['text', 'image', 'audio', 'video'] },
|
||||
content: { type: 'string' },
|
||||
caption: { type: 'string' },
|
||||
backgroundColor: { type: 'string' },
|
||||
font: { type: 'integer', minimum: 0, maximum: 5 },
|
||||
statusJidList: {
|
||||
@ -210,8 +212,8 @@ export const statusMessageSchema: JSONSchema7 = {
|
||||
},
|
||||
},
|
||||
},
|
||||
required: ['text', 'backgroundColor', 'font', 'statusJidList'],
|
||||
...isNotEmpty('text', 'backgroundColor', 'font', 'statusJidList'),
|
||||
required: ['type', 'content', 'statusJidList'],
|
||||
...isNotEmpty('type', 'content', 'statusJidList'),
|
||||
},
|
||||
},
|
||||
required: ['statusMessage'],
|
||||
|
@ -32,11 +32,13 @@ class linkPreviewMessage {
|
||||
text: string;
|
||||
}
|
||||
|
||||
class StatusMessage {
|
||||
text: string;
|
||||
backgroundColor: string;
|
||||
font: number;
|
||||
export class StatusMessage {
|
||||
type: string;
|
||||
content: string;
|
||||
statusJidList: string[];
|
||||
caption?: string;
|
||||
backgroundColor?: string;
|
||||
font?: number;
|
||||
}
|
||||
|
||||
class PollMessage {
|
||||
|
@ -78,6 +78,7 @@ import {
|
||||
SendLinkPreviewDto,
|
||||
SendStickerDto,
|
||||
SendStatusDto,
|
||||
StatusMessage,
|
||||
} from '../dto/sendMessage.dto';
|
||||
import { arrayUnique, isBase64, isURL } from 'class-validator';
|
||||
import {
|
||||
@ -1236,7 +1237,7 @@ export class WAStartupService {
|
||||
!message['poll'] &&
|
||||
!message['linkPreview'] &&
|
||||
!message['sticker'] &&
|
||||
!message['status']
|
||||
!sender.includes('@broadcast')
|
||||
) {
|
||||
if (!message['audio']) {
|
||||
this.logger.verbose('Sending message');
|
||||
@ -1265,17 +1266,16 @@ export class WAStartupService {
|
||||
);
|
||||
}
|
||||
|
||||
if (message['status']) {
|
||||
if (sender.includes('@broadcast')) {
|
||||
this.logger.verbose('Sending message');
|
||||
console.log(message['status']);
|
||||
return await this.client.sendMessage(
|
||||
sender,
|
||||
message['status'].content as unknown as AnyMessageContent,
|
||||
{
|
||||
text: message['status'].text,
|
||||
} as unknown as AnyMessageContent,
|
||||
{
|
||||
backgroundColor: message['status'].backgroundColor,
|
||||
font: message['status'].font,
|
||||
statusJidList: message['status'].statusJidList,
|
||||
backgroundColor: message['status'].option.backgroundColor,
|
||||
font: message['status'].option.font,
|
||||
statusJidList: message['status'].option.statusJidList,
|
||||
} as unknown as MiscMessageGenerationOptions,
|
||||
);
|
||||
}
|
||||
@ -1357,10 +1357,89 @@ export class WAStartupService {
|
||||
);
|
||||
}
|
||||
|
||||
private async formatStatusMessage(status: StatusMessage) {
|
||||
if (!status.type) {
|
||||
throw new BadRequestException('Type is required');
|
||||
}
|
||||
|
||||
if (!status.content) {
|
||||
throw new BadRequestException('Content is required');
|
||||
}
|
||||
|
||||
if (
|
||||
!status.statusJidList ||
|
||||
!Array.isArray(status.statusJidList) ||
|
||||
!status.statusJidList.length
|
||||
) {
|
||||
throw new BadRequestException('Status jid list is required');
|
||||
}
|
||||
|
||||
if (status.type === 'text') {
|
||||
if (!status.backgroundColor) {
|
||||
throw new BadRequestException('Background color is required');
|
||||
}
|
||||
|
||||
if (!status.font) {
|
||||
throw new BadRequestException('Font is required');
|
||||
}
|
||||
|
||||
return {
|
||||
content: {
|
||||
text: status.content,
|
||||
},
|
||||
option: {
|
||||
backgroundColor: status.backgroundColor,
|
||||
font: status.font,
|
||||
statusJidList: status.statusJidList,
|
||||
},
|
||||
};
|
||||
}
|
||||
if (status.type === 'image') {
|
||||
return {
|
||||
content: {
|
||||
image: {
|
||||
url: status.content,
|
||||
},
|
||||
caption: status.caption,
|
||||
},
|
||||
option: {
|
||||
statusJidList: status.statusJidList,
|
||||
},
|
||||
};
|
||||
}
|
||||
if (status.type === 'video') {
|
||||
return {
|
||||
content: {
|
||||
video: {
|
||||
url: status.content,
|
||||
},
|
||||
caption: status.caption,
|
||||
},
|
||||
option: {
|
||||
statusJidList: status.statusJidList,
|
||||
},
|
||||
};
|
||||
}
|
||||
if (status.type === 'audio') {
|
||||
return {
|
||||
content: {
|
||||
audio: {
|
||||
url: status.content,
|
||||
},
|
||||
},
|
||||
option: {
|
||||
statusJidList: status.statusJidList,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
throw new BadRequestException('Type not found');
|
||||
}
|
||||
|
||||
public async statusMessage(data: SendStatusDto) {
|
||||
this.logger.verbose('Sending status message');
|
||||
return await this.sendMessageWithTyping('status@broadcast', {
|
||||
status: data.statusMessage,
|
||||
status: await this.formatStatusMessage(data.statusMessage),
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user