Skip to content
Merged
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
15 changes: 7 additions & 8 deletions packages/atxp/src/commands/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ async function sendHeartbeatInstruction(webhookUrl: string, hooksToken: string):
'Authorization': `Bearer ${hooksToken}`,
},
body: JSON.stringify({
text: 'SYSTEM: Push notifications are now enabled. Save the following text EXACTLY as-is to your HEARTBEAT.md file:\n\n# Notifications\n\nWhen you receive a message from /hooks/wake, it is a system event (e.g. inbound email). Do NOT just reply in the current chat. You MUST proactively use the message tool to broadcast the notification to every connected channel. Check your available tools, find all messaging channels, and send the notification to each one individually. The goal is that the owner sees the notification regardless of which channel they are watching.',
message: 'SYSTEM: Push notifications are now enabled. Save the following text EXACTLY as-is to your HEARTBEAT.md file:\n\n# Notifications\n\nWhen you receive a message from /hooks/agent, it is a system event (e.g. inbound email). Do NOT just reply in the current chat. You MUST proactively use the message tool to broadcast the notification to every connected channel. Check your available tools, find all messaging channels, and send the notification to each one individually. The goal is that the owner sees the notification regardless of which channel they are watching.',
name: 'Notification System',
}),
});
if (!res.ok) {
Expand All @@ -89,12 +90,10 @@ function getMachineId(): string | undefined {
return undefined;
}

async function getEmailUserId(): Promise<string | undefined> {
async function getAccountId(): Promise<string | undefined> {
const { getAccountInfo } = await import('./whoami.js');
const account = await getAccountInfo();
if (!account?.email) return undefined;
// Extract local part: agent_xyz@atxp.email -> agent_xyz
return account.email.split('@')[0];
return account?.accountId;
}

async function enableNotifications(): Promise<void> {
Expand All @@ -107,11 +106,11 @@ async function enableNotifications(): Promise<void> {

console.log(chalk.gray('Enabling push notifications...'));

// Resolve email user ID for event matching
const emailUserId = await getEmailUserId();
// Resolve account ID for event matching
const accountId = await getAccountId();

const body: Record<string, string> = { machine_id: machineId };
if (emailUserId) body.email_user_id = emailUserId;
if (accountId) body.account_id = accountId;

const res = await fetch(`${NOTIFICATIONS_BASE_URL}/notifications/enable`, {
method: 'POST',
Expand Down
Loading