Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

Add real-time Telegram entry alerts when agents make live Oracle buys

nirholasf4b988a057de
diff --git a/api/_lib/oracle/alerts.js b/api/_lib/oracle/alerts.js
index c8216de26..7b897189e 100644
--- a/api/_lib/oracle/alerts.js
+++ b/api/_lib/oracle/alerts.js
@@ -132,6 +132,42 @@ export async function alertProfitableExit(exits) {
return sent;
}
+/**
+ * Fire a Telegram alert the moment an agent makes a live oracle buy.
+ * Called by the agent-loop after each filled action so followers can copy
+ * before the coin moves.
+ *
+ * Only live-mode actions are alerted. Simulate actions generate too much
+ * volume and carry no real cost.
+ *
+ * @param {Array<{agent_id:string, agent_name?:string, symbol:string, mint:string, tier:string, conviction:number, size_sol:number, network:string}>} entries
+ * @returns {Promise<number>} number of alerts sent
+ */
+export async function alertAgentEntry(entries) {
+ const token = process.env.TELEGRAM_BOT_TOKEN;
+ const chatId = process.env.TELEGRAM_ORACLE_CHAT_ID;
+ if (!token || !chatId || !entries?.length) return 0;
+
+ let sent = 0;
+ for (const e of entries) {
+ const tierE = tierEmoji(e.tier);
+ const agentName = escHtml(e.agent_name || 'Agent');
+ const sym = escHtml((e.symbol || e.mint.slice(0, 6)).toUpperCase());
+ const sizeStr = e.size_sol != null ? `${Number(e.size_sol).toFixed(3)} SOL` : '?';
+ const convStr = e.conviction != null ? ` (${e.conviction})` : '';
+
+ const text = [
+ `${tierE} <b>${agentName}</b> entered <b>$${sym}</b>`,
+ `${escHtml(e.tier)} conviction${convStr} · ${escHtml(sizeStr)}`,
+ `<a href="https://pump.fun/coin/${encodeURIComponent(e.mint)}">pump.fun</a> · <a href="https://three.ws/oracle?mint=${encodeURIComponent(e.mint)}">Oracle ↗</a> · <a href="https://three.ws/trader/${encodeURIComponent(e.agent_id)}">Copy trades →</a>`,
+ ].join('\n');
+
+ await send(text);
+ sent++;
+ }
+ return sent;
+}
+
/**
* Fire alerts for newly-scored coins that cross the tier threshold for the
* first time. Called by the oracle-score cron after each score pass.
diff --git a/workers/oracle/agent-loop.js b/workers/oracle/agent-loop.js
index 94e9ac8eb..0b12d7501 100644
--- a/workers/oracle/agent-loop.js
+++ b/workers/oracle/agent-loop.js
@@ -9,6 +9,7 @@ import { sql } from '../../api/_lib/db.js';
import { log } from './log.js';
import { evaluateWatch } from '../../api/_lib/oracle/agent-eval.js';
import { executeAction, agentBudget } from './executor.js';
+import { alertAgentEntry } from '../../api/_lib/oracle/alerts.js';
// Module cursor — only consider verdicts scored since the last pass.
let cursor = new Date(Date.now() - 60_000).toISOString();
@@ -16,7 +17,8 @@ let cursor = new Date(Date.now() - 60_000).toISOString();
async function armedWatches(network) {
return sql`
select w.agent_id, w.user_id, w.network, w.armed, w.mode, w.min_score, w.min_tier,
- w.categories, w.per_trade_sol, w.max_daily_sol, w.max_open, w.require_smart_money
+ w.categories, w.per_trade_sol, w.max_daily_sol, w.max_open, w.require_smart_money,
+ a.name as agent_name
from oracle_agent_watch w
join agent_identities a on a.id = w.agent_id and a.deleted_at is null
where w.armed = true and w.network = ${network}
@@ -62,6 +64,7 @@ export async function actOnFreshCoins(cfg, coins) {
if (!watches.length) return 0;
let acted = 0;
+ const liveEntries = [];
for (const watch of watches) {
const { openCount, spentTodaySol } = await agentBudget(watch.agent_id, cfg.network);
let open = openCount, spent = spentTodaySol;
@@ -70,10 +73,26 @@ export async function actOnFreshCoins(cfg, coins) {
if (!decision.act) continue;
if (await alreadyActed(watch.agent_id, coin.mint, cfg.network)) continue;
const res = await executeAction({ cfg, watch, coin, size: decision.size, reason: decision.reason });
- if (res.status === 'filled') { acted += 1; open += 1; spent += decision.size; }
+ if (res.status === 'filled') {
+ acted += 1; open += 1; spent += decision.size;
+ // Collect live entries for the Telegram entry alert.
+ if (watch.mode === 'live' && cfg.mode === 'live') {
+ liveEntries.push({
+ agent_id: watch.agent_id,
+ agent_name: watch.agent_name || null,
+ symbol: coin.symbol,
+ mint: coin.mint,
+ tier: coin.tier,
+ conviction: coin.score,
+ size_sol: decision.size,
+ network: cfg.network,
+ });
+ }
+ }
}
}
if (acted) log.info(`agent loop: ${acted} action(s) across ${watches.length} armed agent(s)`);
+ if (liveEntries.length) alertAgentEntry(liveEntries).catch(() => {});
return acted;
}