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: {
|
statusMessage: {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
text: { type: 'string' },
|
type: { type: 'string', enum: ['text', 'image', 'audio', 'video'] },
|
||||||
|
content: { type: 'string' },
|
||||||
|
caption: { type: 'string' },
|
||||||
backgroundColor: { type: 'string' },
|
backgroundColor: { type: 'string' },
|
||||||
font: { type: 'integer', minimum: 0, maximum: 5 },
|
font: { type: 'integer', minimum: 0, maximum: 5 },
|
||||||
statusJidList: {
|
statusJidList: {
|
||||||
@ -210,8 +212,8 @@ export const statusMessageSchema: JSONSchema7 = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
required: ['text', 'backgroundColor', 'font', 'statusJidList'],
|
required: ['type', 'content', 'statusJidList'],
|
||||||
...isNotEmpty('text', 'backgroundColor', 'font', 'statusJidList'),
|
...isNotEmpty('type', 'content', 'statusJidList'),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
required: ['statusMessage'],
|
required: ['statusMessage'],
|
||||||
|
@ -32,11 +32,13 @@ class linkPreviewMessage {
|
|||||||
text: string;
|
text: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
class StatusMessage {
|
export class StatusMessage {
|
||||||
text: string;
|
type: string;
|
||||||
backgroundColor: string;
|
content: string;
|
||||||
font: number;
|
|
||||||
statusJidList: string[];
|
statusJidList: string[];
|
||||||
|
caption?: string;
|
||||||
|
backgroundColor?: string;
|
||||||
|
font?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
class PollMessage {
|
class PollMessage {
|
||||||
|
@ -78,6 +78,7 @@ import {
|
|||||||
SendLinkPreviewDto,
|
SendLinkPreviewDto,
|
||||||
SendStickerDto,
|
SendStickerDto,
|
||||||
SendStatusDto,
|
SendStatusDto,
|
||||||
|
StatusMessage,
|
||||||
} from '../dto/sendMessage.dto';
|
} from '../dto/sendMessage.dto';
|
||||||
import { arrayUnique, isBase64, isURL } from 'class-validator';
|
import { arrayUnique, isBase64, isURL } from 'class-validator';
|
||||||
import {
|
import {
|
||||||
@ -1236,7 +1237,7 @@ export class WAStartupService {
|
|||||||
!message['poll'] &&
|
!message['poll'] &&
|
||||||
!message['linkPreview'] &&
|
!message['linkPreview'] &&
|
||||||
!message['sticker'] &&
|
!message['sticker'] &&
|
||||||
!message['status']
|
!sender.includes('@broadcast')
|
||||||
) {
|
) {
|
||||||
if (!message['audio']) {
|
if (!message['audio']) {
|
||||||
this.logger.verbose('Sending message');
|
this.logger.verbose('Sending message');
|
||||||
@ -1265,17 +1266,16 @@ export class WAStartupService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message['status']) {
|
if (sender.includes('@broadcast')) {
|
||||||
this.logger.verbose('Sending message');
|
this.logger.verbose('Sending message');
|
||||||
|
console.log(message['status']);
|
||||||
return await this.client.sendMessage(
|
return await this.client.sendMessage(
|
||||||
sender,
|
sender,
|
||||||
|
message['status'].content as unknown as AnyMessageContent,
|
||||||
{
|
{
|
||||||
text: message['status'].text,
|
backgroundColor: message['status'].option.backgroundColor,
|
||||||
} as unknown as AnyMessageContent,
|
font: message['status'].option.font,
|
||||||
{
|
statusJidList: message['status'].option.statusJidList,
|
||||||
backgroundColor: message['status'].backgroundColor,
|
|
||||||
font: message['status'].font,
|
|
||||||
statusJidList: message['status'].statusJidList,
|
|
||||||
} as unknown as MiscMessageGenerationOptions,
|
} 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) {
|
public async statusMessage(data: SendStatusDto) {
|
||||||
this.logger.verbose('Sending status message');
|
this.logger.verbose('Sending status message');
|
||||||
return await this.sendMessageWithTyping('status@broadcast', {
|
return await this.sendMessageWithTyping('status@broadcast', {
|
||||||
status: data.statusMessage,
|
status: await this.formatStatusMessage(data.statusMessage),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user