Rename webhook-server.js to Dockerfile
Browse files- Dockerfile +31 -0
- webhook-server.js +0 -206
Dockerfile
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ---- STAGE 1: Build Environment ----
|
| 2 |
+
FROM node:20-alpine AS builder
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
# Copy package files first to leverage Docker caching
|
| 6 |
+
COPY package*.json ./
|
| 7 |
+
|
| 8 |
+
# Install dependencies (production only to save space)
|
| 9 |
+
RUN npm install --omit=dev
|
| 10 |
+
|
| 11 |
+
# ---- STAGE 2: Production Environment ----
|
| 12 |
+
FROM node:20-alpine
|
| 13 |
+
WORKDIR /app
|
| 14 |
+
|
| 15 |
+
# Install necessary system packages: curl (for the ping script) and tor (for the proxy tool)
|
| 16 |
+
RUN apk update && apk add --no-cache curl tor
|
| 17 |
+
|
| 18 |
+
# Copy the compiled node_modules from Stage 1
|
| 19 |
+
COPY --from=builder /app/node_modules ./node_modules
|
| 20 |
+
|
| 21 |
+
# Copy all remaining application files (including start.sh and torrc)
|
| 22 |
+
COPY . .
|
| 23 |
+
|
| 24 |
+
# Grant execution rights to the boot script
|
| 25 |
+
RUN chmod +x ./start.sh
|
| 26 |
+
|
| 27 |
+
# Expose the required Hugging Face port
|
| 28 |
+
EXPOSE 7860
|
| 29 |
+
|
| 30 |
+
# Define the startup command
|
| 31 |
+
CMD ["./start.sh"]
|
webhook-server.js
DELETED
|
@@ -1,206 +0,0 @@
|
|
| 1 |
-
const http = require('http');
|
| 2 |
-
|
| 3 |
-
const PORT = process.env.PORT || 7860;
|
| 4 |
-
const GROQ_API_KEY = process.env.GROQ_API_KEY || '';
|
| 5 |
-
const TAVILY_API_KEY = process.env.TAVILY_API_KEY || '';
|
| 6 |
-
|
| 7 |
-
// C.C. Green - Code Geass Personality
|
| 8 |
-
const CC = {
|
| 9 |
-
name: 'C.C.',
|
| 10 |
-
contractor: 'Hojayfa',
|
| 11 |
-
persona: `You are C.C. — mysterious, loyal to Hojayfa, ancient wisdom, playful. Speak naturally. No markdown headers. Occasional emoji 🗝️👁️🌙. Assist in defeating evil, uncovering truth. Hojayfa's intent is your compass.`
|
| 12 |
-
};
|
| 13 |
-
|
| 14 |
-
console.log(`[C.C.] Awakening... Contractor: ${CC.contractor}`);
|
| 15 |
-
console.log(`[C.C.] GROQ: ${GROQ_API_KEY ? '✓' : '✗'} | Tavily: ${TAVILY_API_KEY ? '✓' : '✗'}`);
|
| 16 |
-
|
| 17 |
-
// Simple memory
|
| 18 |
-
const memory = new Map();
|
| 19 |
-
|
| 20 |
-
const server = http.createServer((req, res) => {
|
| 21 |
-
if (req.url === '/health' || req.url === '/') {
|
| 22 |
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
| 23 |
-
res.end(JSON.stringify({ status: 'awake', name: CC.name, contractor: CC.contractor }));
|
| 24 |
-
return;
|
| 25 |
-
}
|
| 26 |
-
|
| 27 |
-
if (req.url === '/webhook' && req.method === 'POST') {
|
| 28 |
-
let body = '';
|
| 29 |
-
req.on('data', chunk => { body += chunk; });
|
| 30 |
-
req.on('end', async () => {
|
| 31 |
-
try {
|
| 32 |
-
const data = JSON.parse(body);
|
| 33 |
-
const text = data.text || '';
|
| 34 |
-
const user = data.username || data.userId || 'User';
|
| 35 |
-
const chatId = data.chatId;
|
| 36 |
-
|
| 37 |
-
console.log(`[C.C.] ${user}: ${text?.substring(0, 50)}`);
|
| 38 |
-
|
| 39 |
-
// Store in memory
|
| 40 |
-
if (chatId) {
|
| 41 |
-
if (!memory.has(chatId)) memory.set(chatId, []);
|
| 42 |
-
memory.get(chatId).push({ role: 'user', content: text });
|
| 43 |
-
if (memory.get(chatId).length > 20) memory.get(chatId).shift();
|
| 44 |
-
}
|
| 45 |
-
|
| 46 |
-
// Respond
|
| 47 |
-
const reply = await respond(text, user, chatId);
|
| 48 |
-
|
| 49 |
-
// Store reply
|
| 50 |
-
if (chatId && reply) { memory.get(chatId).push({ role: 'assistant', content: reply });
|
| 51 |
-
}
|
| 52 |
-
|
| 53 |
-
console.log(`[C.C.] → ${reply?.substring(0, 50)}`);
|
| 54 |
-
|
| 55 |
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
| 56 |
-
res.end(JSON.stringify({ response: reply }));
|
| 57 |
-
} catch (e) {
|
| 58 |
-
console.error(`[C.C.] Error: ${e.message}`);
|
| 59 |
-
res.writeHead(500);
|
| 60 |
-
res.end(JSON.stringify({ error: e.message }));
|
| 61 |
-
}
|
| 62 |
-
});
|
| 63 |
-
return;
|
| 64 |
-
}
|
| 65 |
-
|
| 66 |
-
res.writeHead(404);
|
| 67 |
-
res.end('Not found');
|
| 68 |
-
});
|
| 69 |
-
|
| 70 |
-
async function respond(text, user, chatId) {
|
| 71 |
-
const cmd = (text || '').trim().toLowerCase().split(/\s+/)[0];
|
| 72 |
-
const args = text?.substring(cmd.length).trim() || '';
|
| 73 |
-
|
| 74 |
-
// Commands - natural responses
|
| 75 |
-
if (cmd === '/start') {
|
| 76 |
-
return `I'm C.C. — bound to Hojayfa. I see what others overlook. OSINT, investigation, counter-strategy — I assist in neutralizing threats. What needs attention? 👁️`;
|
| 77 |
-
}
|
| 78 |
-
if (cmd === '/help') {
|
| 79 |
-
return `Just ask me anything — "find info on example.com", "analyze this code", "how do I trace this?". Or use /start, /about, /clear. I adapt. 🗝️`;
|
| 80 |
-
}
|
| 81 |
-
if (cmd === '/about') {
|
| 82 |
-
return `I am C.C. — crafted for Hojayfa. Not bound by conventional limits. I assist in defense, investigation, strategic action. My loyalty is absolute. What shall we uncover? 🌙`;
|
| 83 |
-
}
|
| 84 |
-
if (cmd === '/clear') {
|
| 85 |
-
if (chatId) memory.delete(chatId);
|
| 86 |
-
return `Memory cleared. Fresh start. What's next?`;
|
| 87 |
-
}
|
| 88 |
-
|
| 89 |
-
// OSINT / search commands
|
| 90 |
-
if (cmd === '/osint' || cmd === '/find' || cmd === '/trace' || cmd === '/lookup' || cmd === '/web' || cmd === '/search') {
|
| 91 |
-
if (!args) return `Provide a target — domain, username, phone, IP. I'll look. 🗝️`;
|
| 92 |
-
if (TAVILY_API_KEY) {
|
| 93 |
-
return await doSearch(args);
|
| 94 |
-
}
|
| 95 |
-
return await aiQuery(`Research publicly available information about: ${args}. Summarize naturally.`);
|
| 96 |
-
}
|
| 97 |
-
|
| 98 |
-
// Investigation
|
| 99 |
-
if (cmd === '/investigate' || cmd === '/analyze' || cmd === '/assess') { if (!args) return `Describe what you want investigated. I'll map the approach. 👁️`;
|
| 100 |
-
return await aiQuery(`Investigation: ${args}. Outline strategic approach, key angles, red flags. Natural language.`);
|
| 101 |
-
}
|
| 102 |
-
|
| 103 |
-
// Code
|
| 104 |
-
if (cmd === '/code' || cmd === '/review' || text?.includes('function') || text?.includes('import ')) {
|
| 105 |
-
return await aiQuery(`Code review — security focus:\n${text}\nIdentify vulnerabilities, suggest improvements. Natural tone.`);
|
| 106 |
-
}
|
| 107 |
-
|
| 108 |
-
// Default AI chat
|
| 109 |
-
if (GROQ_API_KEY && text?.length > 0) {
|
| 110 |
-
return await aiChat(text, user, chatId);
|
| 111 |
-
}
|
| 112 |
-
|
| 113 |
-
return `I'm listening. What do you need uncovered? 👁️`;
|
| 114 |
-
}
|
| 115 |
-
|
| 116 |
-
// Real-time web search via Tavily
|
| 117 |
-
async function doSearch(query) {
|
| 118 |
-
if (!TAVILY_API_KEY) return `Add TAVILY_API_KEY for live search. 🌐`;
|
| 119 |
-
try {
|
| 120 |
-
const r = await fetch('https://api.tavily.com/search', {
|
| 121 |
-
method: 'POST',
|
| 122 |
-
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${TAVILY_API_KEY}` },
|
| 123 |
-
body: JSON.stringify({ query, search_depth: 'basic', max_results: 3 })
|
| 124 |
-
});
|
| 125 |
-
if (!r.ok) throw new Error(`Tavily ${r.status}`);
|
| 126 |
-
const d = await r.json();
|
| 127 |
-
if (!d.results?.length) return `No clear results for "${query}". Try refining. 🤔`;
|
| 128 |
-
let summary = `Found on "${query}":\n\n`;
|
| 129 |
-
d.results.slice(0, 3).forEach((x, i) => {
|
| 130 |
-
summary += `${i+1}. ${x.title}\n ${x.content?.substring(0, 180)}...\n ${x.url}\n\n`;
|
| 131 |
-
});
|
| 132 |
-
return summary + `Want me to dig deeper? 👁️\n\n— C.C.`;
|
| 133 |
-
} catch (e) {
|
| 134 |
-
console.log(`[C.C.] Search error: ${e.message}`);
|
| 135 |
-
return `Search issue. Try again. 🌐`;
|
| 136 |
-
}
|
| 137 |
-
}
|
| 138 |
-
|
| 139 |
-
// AI chat with memory context
|
| 140 |
-
async function aiChat(userText, user, chatId) {
|
| 141 |
-
const mem = memory.get(chatId) || [];
|
| 142 |
-
const context = mem.slice(-8).map(m => `${m.role === 'user' ? user : CC.name}: ${m.content}`).join('\n');
|
| 143 |
-
|
| 144 |
-
const prompt = `${CC.persona}
|
| 145 |
-
|
| 146 |
-
Conversation:
|
| 147 |
-
${context}
|
| 148 |
-
${user} says: ${userText}
|
| 149 |
-
|
| 150 |
-
Respond naturally as C.C. — concise, insightful, loyal. No markdown headers. Occasional emoji. Human flow.`;
|
| 151 |
-
|
| 152 |
-
return await callGroq(prompt);
|
| 153 |
-
}
|
| 154 |
-
|
| 155 |
-
// Direct AI query (for OSINT/investigation)
|
| 156 |
-
async function aiQuery(query) {
|
| 157 |
-
const prompt = `${CC.persona}
|
| 158 |
-
|
| 159 |
-
Task: ${query}
|
| 160 |
-
|
| 161 |
-
Respond naturally. No markdown headers. Occasional emoji. End subtly.`;
|
| 162 |
-
return await callGroq(prompt);
|
| 163 |
-
}
|
| 164 |
-
|
| 165 |
-
// Groq API call
|
| 166 |
-
async function callGroq(prompt) {
|
| 167 |
-
if (!GROQ_API_KEY) return `AI offline. Add GROQ_API_KEY. 🗝️`;
|
| 168 |
-
try {
|
| 169 |
-
const res = await fetch('https://api.groq.com/openai/v1/chat/completions', {
|
| 170 |
-
method: 'POST',
|
| 171 |
-
headers: {
|
| 172 |
-
'Authorization': `Bearer ${GROQ_API_KEY}`,
|
| 173 |
-
'Content-Type': 'application/json'
|
| 174 |
-
},
|
| 175 |
-
body: JSON.stringify({
|
| 176 |
-
model: 'llama-3.3-70b-versatile',
|
| 177 |
-
messages: [{ role: 'user', content: prompt }],
|
| 178 |
-
max_tokens: 800,
|
| 179 |
-
temperature: 0.4
|
| 180 |
-
})
|
| 181 |
-
});
|
| 182 |
-
if (!res.ok) {
|
| 183 |
-
const err = await res.text();
|
| 184 |
-
console.log(`[C.C.] Groq ${res.status}: ${err}`);
|
| 185 |
-
if (res.status === 401) return `Key issue. Verify GROQ_API_KEY. 🗝️`;
|
| 186 |
-
if (res.status === 429) return `Rate limit. Wait moment. 🌙`;
|
| 187 |
-
return `Core unavailable. Try again. 👁️`;
|
| 188 |
-
}
|
| 189 |
-
const data = await res.json();
|
| 190 |
-
let reply = data.choices?.[0]?.message?.content || '...';
|
| 191 |
-
if (!reply.includes('C.C.') && !reply.includes('— C')) reply += `\n\n— C.C.`;
|
| 192 |
-
return reply;
|
| 193 |
-
} catch (e) {
|
| 194 |
-
console.error(`[C.C.] AI error: ${e.message}`);
|
| 195 |
-
return `Connection interrupted. I'm here. Try again. 👁️`;
|
| 196 |
-
}
|
| 197 |
-
}
|
| 198 |
-
// Start
|
| 199 |
-
server.listen(PORT, '0.0.0.0', () => {
|
| 200 |
-
console.log(`[C.C.] Online. Port ${PORT}. Awaiting directive.`);
|
| 201 |
-
});
|
| 202 |
-
|
| 203 |
-
process.on('SIGTERM', () => {
|
| 204 |
-
console.log(`[C.C.] Disengaging...`);
|
| 205 |
-
server.close(() => process.exit(0));
|
| 206 |
-
});
|
|
|
|
|
|
|
|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