Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ OPENCODE_MODEL_ID=big-pickle
# If exceeded, the bot stops waiting for the result and marks the run as failed.
# SCHEDULED_TASK_EXECUTION_TIMEOUT_MINUTES=120

# Send scheduled task result/error messages without Telegram push notifications (default: false)
# SCHEDULED_TASK_DISABLE_NOTIFICATION=false

# Response streaming mode: "edit" (default) or "draft" (default: edit)
# edit = uses editMessageText to update messages incrementally (may flicker)
# draft = uses sendMessageDraft (Bot API 9.5+) for smooth animated draft previews,
Expand Down
13 changes: 12 additions & 1 deletion src/bot/messages/scheduled-task-delivery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ function getScheduledTaskDeliveryFormat(): "raw" | "markdown_v2" {
return config.bot.messageFormatMode === "markdown" ? "markdown_v2" : "raw";
}

function getSilentDeliveryOptions(): { options: { disable_notification: true } } | Record<string, never> {
return config.bot.scheduledTaskNotificationsSilent
? { options: { disable_notification: true } }
: {};
}

function buildScheduledTaskSuccessMessageParts(delivery: QueuedScheduledTaskDelivery): string[] {
if (!delivery.resultText) {
return [delivery.notificationText];
Expand Down Expand Up @@ -56,14 +62,18 @@ export function createScheduledTaskDeliverySender(
: [delivery.notificationText];
const format = delivery.status === "success" ? getScheduledTaskDeliveryFormat() : "raw";
const suppressResultNotification = delivery.status === "success" && Boolean(delivery.footerText);
const resultDeliveryOptions =
suppressResultNotification && !config.bot.scheduledTaskNotificationsSilent
? { options: { disable_notification: true } }
: getSilentDeliveryOptions();

for (const part of messageParts) {
await sendBotText({
api,
chatId,
text: part,
format,
...(suppressResultNotification ? { options: { disable_notification: true } } : {}),
...resultDeliveryOptions,
});
}

Expand All @@ -73,6 +83,7 @@ export function createScheduledTaskDeliverySender(
chatId,
text: delivery.footerText,
format: "raw",
...getSilentDeliveryOptions(),
});
}

Expand Down
4 changes: 4 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ export const config = {
"SCHEDULED_TASK_EXECUTION_TIMEOUT_MINUTES",
120,
),
scheduledTaskNotificationsSilent: getOptionalBooleanEnvVar(
"SCHEDULED_TASK_DISABLE_NOTIFICATION",
false,
),
responseStreamThrottleMs: getOptionalPositiveIntEnvVar("RESPONSE_STREAM_THROTTLE_MS", 1000),
responseStreamingMode: getOptionalStreamingModeEnvVar("RESPONSE_STREAMING_MODE", "edit"),
bashToolDisplayMaxLength: getOptionalPositiveIntEnvVar("BASH_TOOL_DISPLAY_MAX_LENGTH", 128),
Expand Down
39 changes: 39 additions & 0 deletions tests/config-scheduled-task-notifications.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { beforeEach, describe, expect, it, vi } from "vitest";

async function loadConfig() {
vi.resetModules();
const module = await import("../src/config.js");
return module.config;
}

describe("config scheduled task notifications", () => {
beforeEach(() => {
vi.stubEnv("TELEGRAM_BOT_TOKEN", "test-telegram-token");
vi.stubEnv("TELEGRAM_ALLOWED_USER_ID", "123456789");
vi.stubEnv("OPENCODE_MODEL_PROVIDER", "test-provider");
vi.stubEnv("OPENCODE_MODEL_ID", "test-model");
vi.stubEnv("SCHEDULED_TASK_DISABLE_NOTIFICATION", "");
});

it("keeps scheduled task notifications enabled by default", async () => {
const config = await loadConfig();

expect(config.bot.scheduledTaskNotificationsSilent).toBe(false);
});

it("parses SCHEDULED_TASK_DISABLE_NOTIFICATION as a boolean", async () => {
vi.stubEnv("SCHEDULED_TASK_DISABLE_NOTIFICATION", "true");

const config = await loadConfig();

expect(config.bot.scheduledTaskNotificationsSilent).toBe(true);
});

it("falls back to enabled notifications on invalid values", async () => {
vi.stubEnv("SCHEDULED_TASK_DISABLE_NOTIFICATION", "banana");

const config = await loadConfig();

expect(config.bot.scheduledTaskNotificationsSilent).toBe(false);
});
});
Loading