Feature/message sending #2

Merged
B00tLoad merged 28 commits from feature/message-sending into develop 2025-08-31 13:59:38 +02:00
Showing only changes of commit 5cfbc8d441 - Show all commits

View File

@@ -60,8 +60,8 @@ const MessageSchema = z
.optional(), .optional(),
sound: z.string().optional(), sound: z.string().optional(),
timestamp: z.number().optional(), timestamp: z.number().optional(),
html: z.boolean().optional(), html: z.boolean().optional().default(false),
monospace: z.boolean().optional(), monospace: z.boolean().optional().default(false),
ttl: z.number().optional(), ttl: z.number().optional(),
}) })
.refine( .refine(
@@ -84,7 +84,9 @@ const MessageSchema = z
}, },
); );
export type PushoverMessage = z.infer<typeof MessageSchema>; export type PushoverMessage = z.input<typeof MessageSchema>;
type PushoverMessageParsed = z.output<typeof MessageSchema>;
interface PushoverResponse { interface PushoverResponse {
status: number; status: number;
@@ -152,16 +154,27 @@ export class Pushover {
reject("No recipients specified."); reject("No recipients specified.");
} }
const {
success,
error,
data: parsedMessage,
} = MessageSchema.safeParse(message);
if (!success) {
reject(`Message validation failed: ${error}`);
return;
}
if (options.verbose) { if (options.verbose) {
console.log("Verbose mode enabled. Logging message and options:"); console.log("Verbose mode enabled. Logging message and options:");
console.log(message); console.log(parsedMessage);
console.log(options); console.log(options);
console.log("----------------------"); console.log("----------------------");
copilot-pull-request-reviewer[bot] commented 2025-08-30 22:14:54 +02:00 (Migrated from github.com)
Review

Missing comma after the tags array in the JSDoc example. Should be tags: [\"critical\", \"infra\"],

 *     tags: ["critical", "infra"],
Missing comma after the `tags` array in the JSDoc example. Should be `tags: [\"critical\", \"infra\"],` ```suggestion * tags: ["critical", "infra"], ```
console.log("Sending message..."); console.log("Sending message...");
} }
const promises = options.recipients.map((recipient) => const promises = options.recipients.map((recipient) =>
this.sendToSingleRecipient(message, recipient), this.sendToSingleRecipient(parsedMessage, recipient),
); );
resolve(Promise.all(promises)); resolve(Promise.all(promises));
@@ -169,7 +182,7 @@ export class Pushover {
} }
private async sendToSingleRecipient( private async sendToSingleRecipient(
message: PushoverMessage, message: PushoverMessageParsed,
user: PushoverUser, user: PushoverUser,
): Promise<PushoverMessageResponse> { ): Promise<PushoverMessageResponse> {
const params = new URLSearchParams(); const params = new URLSearchParams();