Skip to content
Closed
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
1 change: 1 addition & 0 deletions lib/dispatch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ export async function dispatchTask(
channel: notifyTarget?.channel ?? "telegram",
runtime,
accountId: notifyTarget?.accountId,
messageThreadId: notifyTarget?.messageThreadId,
runCommand: rc,
},
).catch((err) => {
Expand Down
11 changes: 8 additions & 3 deletions lib/dispatch/notify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,16 @@ async function sendMessage(
runtime?: PluginRuntime,
accountId?: string,
runCommand?: RunCommand,
messageThreadId?: number,
): Promise<boolean> {
try {
// Use runtime API when available (avoids CLI subprocess timeouts)
if (runtime) {
if (channel === "telegram") {
// Cast to any to bypass TypeScript type limitation; disableWebPagePreview is valid in Telegram API
await runtime.channel.telegram.sendMessageTelegram(target, message, { silent: true, disableWebPagePreview: true, accountId } as any);
// Cast to any to bypass TypeScript type limitation; disableWebPagePreview and messageThreadId are valid in Telegram API
const telegramOpts: Record<string, unknown> = { silent: true, disableWebPagePreview: true, accountId };
if (messageThreadId != null) telegramOpts.messageThreadId = messageThreadId;
await runtime.channel.telegram.sendMessageTelegram(target, message, telegramOpts as any);
return true;
}
if (channel === "whatsapp") {
Expand Down Expand Up @@ -341,6 +344,8 @@ export async function notify(
accountId?: string;
/** Injected runCommand for dependency injection. */
runCommand?: RunCommand;
/** Optional Telegram forum topic ID for per-topic routing */
messageThreadId?: number;
},
): Promise<boolean> {
if (opts.config?.[event.type] === false) return true;
Expand All @@ -364,7 +369,7 @@ export async function notify(
message,
});

return sendMessage(target, message, channel, opts.workspaceDir, opts.runtime, opts.accountId, opts.runCommand);
return sendMessage(target, message, channel, opts.workspaceDir, opts.runtime, opts.accountId, opts.runCommand, opts.messageThreadId);
}

/**
Expand Down
1 change: 1 addition & 0 deletions lib/projects/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type Channel = {
name: string; // e.g. "primary", "dev-chat"
events: string[]; // e.g. ["*"] for all, ["workerComplete"] for filtered
accountId?: string; // Optional account ID for multi-account setups
messageThreadId?: number; // Optional Telegram forum topic ID for per-topic routing
};

/**
Expand Down
4 changes: 4 additions & 0 deletions lib/services/heartbeat/passes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export async function performReviewPass(
channel: target?.channel ?? "telegram",
runtime,
accountId: target?.accountId,
messageThreadId: target?.messageThreadId,
runCommand,
},
).catch(() => {});
Expand Down Expand Up @@ -162,6 +163,7 @@ export async function performReviewPass(
channel: target?.channel ?? "telegram",
runtime,
accountId: target?.accountId,
messageThreadId: target?.messageThreadId,
runCommand,
},
).catch(() => {});
Expand All @@ -185,6 +187,7 @@ export async function performReviewPass(
channel: target?.channel ?? "telegram",
runtime,
accountId: target?.accountId,
messageThreadId: target?.messageThreadId,
runCommand,
},
).catch(() => {});
Expand Down Expand Up @@ -242,6 +245,7 @@ export async function performReviewSkipPass(
channel: target?.channel ?? "telegram",
runtime,
accountId: target?.accountId,
messageThreadId: target?.messageThreadId,
runCommand,
},
).catch(() => {});
Expand Down
4 changes: 3 additions & 1 deletion lib/services/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export async function executeCompletion(opts: {
channel: notifyTarget?.channel ?? "telegram",
runtime,
accountId: notifyTarget?.accountId,
messageThreadId: notifyTarget?.messageThreadId,
},
).catch((err) => {
auditLog(workspaceDir, "pipeline_warning", { step: "notify", issue: issueId, role, error: (err as Error).message ?? String(err) }).catch(() => {});
Expand All @@ -195,7 +196,7 @@ export async function executeCompletion(opts: {
sourceBranch,
mergedBy: "pipeline",
},
{ workspaceDir, config: notifyConfig, channelId: notifyTarget?.channelId, channel: notifyTarget?.channel ?? "telegram", runtime, accountId: notifyTarget?.accountId },
{ workspaceDir, config: notifyConfig, channelId: notifyTarget?.channelId, channel: notifyTarget?.channel ?? "telegram", runtime, accountId: notifyTarget?.accountId, messageThreadId: notifyTarget?.messageThreadId },
).catch((err) => {
auditLog(workspaceDir, "pipeline_warning", { step: "mergeNotify", issue: issueId, role, error: (err as Error).message ?? String(err) }).catch(() => {});
});
Expand Down Expand Up @@ -245,6 +246,7 @@ export async function executeCompletion(opts: {
channel: notifyTarget?.channel ?? "telegram",
runtime,
accountId: notifyTarget?.accountId,
messageThreadId: notifyTarget?.messageThreadId,
},
).catch((err) => {
auditLog(workspaceDir, "pipeline_warning", { step: "reviewNotify", issue: issueId, role, error: (err as Error).message ?? String(err) }).catch(() => {});
Expand Down
4 changes: 2 additions & 2 deletions lib/workflow/labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export function getNotifyLabel(channel: string, nameOrIndex: string): string {
*/
export function resolveNotifyChannel(
issueLabels: string[],
channels: Array<{ channelId: string; channel: string; name?: string; accountId?: string }>,
): { channelId: string; channel: string; accountId?: string } | undefined {
channels: Array<{ channelId: string; channel: string; name?: string; accountId?: string; messageThreadId?: number }>,
): { channelId: string; channel: string; accountId?: string; messageThreadId?: number } | undefined {
const notifyLabel = issueLabels.find((l) => l.startsWith(NOTIFY_LABEL_PREFIX));
if (notifyLabel) {
const value = notifyLabel.slice(NOTIFY_LABEL_PREFIX.length);
Expand Down
Loading