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 src/__tests__/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import { createApp } from "../server.js";
const now = new Date().toISOString();
const botHeaders = { "x-spawndock-bot-secret": "spawndock-dev-bot-secret" };

process.env.TELEGRAM_BOT_USERNAME ??= "rustgpt_bot";
process.env.TELEGRAM_MINI_APP_SHORT_NAME ??= "tma";

function createRuntime(): Runtime {
return {
state: { projects: [], pairingTokens: [], deviceCredentials: [], tunnelSessions: [] },
Expand Down
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ function readContainerRuntime(): "docker" | "podman" {
export const config = {
port: parseInt(process.env.PORT || "3000", 10),
botSecret: process.env.SPAWNDOCK_BOT_SECRET || "spawndock-dev-bot-secret",
telegramBotUsername: process.env.TELEGRAM_BOT_USERNAME || "",
telegramMiniAppShortName: process.env.TELEGRAM_MINI_APP_SHORT_NAME || "tma",
rateLimitRps: parseInt(process.env.RATE_LIMIT_RPS || "10", 10),
get qwenMode() {
return readQwenMode();
Expand Down
15 changes: 15 additions & 0 deletions src/routes/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { Runtime } from "../types.js";
import { createProject, claimPairingToken, inspectPairingToken, resolveOwnedProjectLaunchInfo, buildLaunchUrl } from "../projects.js";
import { saveState } from "../store.js";
import { config } from "../config.js";
import { buildTelegramMiniAppUrl } from "../bot/links.js";

export function projectRoutes(runtime: Runtime, stateFilePath: string): Router {
const router = Router();
Expand Down Expand Up @@ -93,6 +94,7 @@ export function projectRoutes(runtime: Runtime, stateFilePath: string): Router {
saveState(stateFilePath, runtime.state);

const project = result.project;
const telegramMiniAppUrl = resolveTelegramMiniAppUrl(project.slug);
res.status(201).json({
project,
projectId: project.id,
Expand All @@ -104,6 +106,7 @@ export function projectRoutes(runtime: Runtime, stateFilePath: string): Router {
tunnelWsUrl: `${config.publicOrigin.replace(/^http/, "ws")}${config.tunnelPath}?token=${result.deviceCredential.secret}`,
controlPlaneUrl: config.publicOrigin,
localPort: config.tmaLocalPort,
...(telegramMiniAppUrl ? { telegramMiniAppUrl } : {}),
});
};

Expand Down Expand Up @@ -187,3 +190,15 @@ function readOwnerTelegramId(value: unknown): number | null {

return typeof value === "number" && Number.isFinite(value) ? value : null;
}

function resolveTelegramMiniAppUrl(projectSlug: string): string | null {
if (config.telegramBotUsername.length === 0) {
return null;
}

return buildTelegramMiniAppUrl(
config.telegramBotUsername,
config.telegramMiniAppShortName,
projectSlug,
);
}