abbasyk60 commited on
Commit
a2fb4d4
·
1 Parent(s): 9091de1

Add Render deployment config and guide

Browse files
Files changed (3) hide show
  1. DEPLOY.md +61 -0
  2. debug-bot.js +67 -0
  3. render.yaml +14 -0
DEPLOY.md ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Deploy to Render.com (Free 24/7 Hosting)
2
+
3
+ ## Step 1: Create Render Account
4
+
5
+ 1. Go to **https://render.com**
6
+ 2. Sign up with your GitHub account
7
+
8
+ ## Step 2: Push Code to GitHub
9
+
10
+ ```bash
11
+ cd C:\Users\abbasyk\Documents\opencode-hf-space
12
+ git init
13
+ git add -A
14
+ git commit -m "Initial commit"
15
+ git remote add origin https://github.com/YOUR_USERNAME/opencode-bot.git
16
+ git push -u origin main
17
+ ```
18
+
19
+ ## Step 3: Create Background Worker on Render
20
+
21
+ 1. Go to **https://dashboard.render.com**
22
+ 2. Click **"New +"** → **"Background Worker"**
23
+ 3. Connect your GitHub repo
24
+ 4. Settings:
25
+ - **Name**: opencode-telegram-bot
26
+ - **Runtime**: Node
27
+ - **Build Command**: `npm install`
28
+ - **Start Command**: `node bot.js`
29
+ 5. Click **"Advanced"** → Add these **Environment Variables**:
30
+
31
+ | Key | Value |
32
+ |-----|-------|
33
+ | `TELEGRAM_BOT_TOKEN` | `8835963099:AAHvLdFqbpsfDs3hTUBXuFQzSo3LSpedd6k` |
34
+ | `TELEGRAM_CHAT_ID` | `6922119748` |
35
+ | `OPENCODE_ZEN_KEY` | `sk-1IwuYl2EKD0bNtmoEPqBVuWQHlKlc7gN5VLFZnjBrGTUbg7O1376dM9eYg8AHaUv` |
36
+
37
+ 6. Click **"Create Background Worker"**
38
+
39
+ ## Step 4: Verify
40
+
41
+ - Go to your service page on Render
42
+ - Check **"Logs"** tab - you should see:
43
+ ```
44
+ [OK] Starting Telegram bot...
45
+ [OK] Telegram bot is running!
46
+ ```
47
+
48
+ ## Free Tier Limitations
49
+
50
+ - **750 hours/month** (enough for 24/7)
51
+ - **Sleeps after 15 min** of inactivity (but Telegram bot keeps it awake)
52
+ - **Spins up in ~30 seconds** when new message arrives
53
+
54
+ ## Alternative: Fly.io
55
+
56
+ If Render doesn't work, try Fly.io:
57
+ 1. Install: `curl -L https://fly.io/install.sh | sh`
58
+ 2. Run: `fly auth login`
59
+ 3. Run: `fly launch`
60
+ 4. Run: `fly secrets set TELEGRAM_BOT_TOKEN=... TELEGRAM_CHAT_ID=... OPENCODE_ZEN_KEY=...`
61
+ 5. Run: `fly deploy`
debug-bot.js ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const { Bot } = require("grammy");
2
+
3
+ const BOT_TOKEN = process.env.TELEGRAM_BOT_TOKEN;
4
+ const ZEN_API_KEY = process.env.OPENCODE_ZEN_KEY;
5
+
6
+ console.log("[TEST] Starting debug bot...");
7
+ console.log("[TEST] Token:", BOT_TOKEN ? BOT_TOKEN.substring(0, 10) + "..." : "MISSING");
8
+ console.log("[TEST] Key:", ZEN_API_KEY ? ZEN_API_KEY.substring(0, 12) + "..." : "MISSING");
9
+
10
+ const bot = new Bot(BOT_TOKEN);
11
+
12
+ bot.on("message", async (ctx) => {
13
+ const info = {
14
+ chatId: ctx.chat.id,
15
+ chatType: ctx.chat.type,
16
+ text: ctx.message.text || "(non-text)",
17
+ fromId: ctx.from?.id,
18
+ fromUser: ctx.from?.username,
19
+ };
20
+ console.log("[MSG] Received:", JSON.stringify(info));
21
+
22
+ // Step 1: Echo test
23
+ try {
24
+ await ctx.reply("Echo: " + (ctx.message.text || "no text"));
25
+ console.log("[MSG] Echo reply sent OK");
26
+ } catch (e) {
27
+ console.error("[MSG] Echo reply FAILED:", e.message);
28
+ return;
29
+ }
30
+
31
+ // Step 2: API test
32
+ if (ctx.message.text && ctx.message.text.startsWith("/")) return;
33
+
34
+ try {
35
+ console.log("[API] Calling Zen API...");
36
+ const resp = await fetch("https://opencode.ai/zen/v1/chat/completions", {
37
+ method: "POST",
38
+ headers: {
39
+ Authorization: "Bearer " + ZEN_API_KEY,
40
+ "Content-Type": "application/json",
41
+ },
42
+ body: JSON.stringify({
43
+ model: "deepseek-v4-flash-free",
44
+ messages: [{ role: "user", content: ctx.message.text }],
45
+ max_tokens: 4096,
46
+ }),
47
+ });
48
+ console.log("[API] Status:", resp.status);
49
+ const data = await resp.json();
50
+ const msg = data.choices?.[0]?.message;
51
+ let reply = msg?.content || msg?.reasoning_content || "(empty)";
52
+ console.log("[API] Reply length:", reply.length);
53
+ await ctx.reply(reply.substring(0, 4000));
54
+ console.log("[API] Reply sent OK");
55
+ } catch (e) {
56
+ console.error("[API] FAILED:", e.message);
57
+ await ctx.reply("API Error: " + e.message);
58
+ }
59
+ });
60
+
61
+ bot.catch((err) => console.error("[BOT ERROR]", err));
62
+
63
+ bot.start({
64
+ onStart: () => {
65
+ console.log("[BOT] Running! Send a message to @jotish66bot NOW...");
66
+ },
67
+ });
render.yaml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ services:
2
+ - type: worker
3
+ name: opencode-telegram-bot
4
+ runtime: node
5
+ plan: free
6
+ buildCommand: npm install
7
+ startCommand: node bot.js
8
+ envVars:
9
+ - key: TELEGRAM_BOT_TOKEN
10
+ sync: false
11
+ - key: TELEGRAM_CHAT_ID
12
+ sync: false
13
+ - key: OPENCODE_ZEN_KEY
14
+ sync: false