buzz listener: instant DM acks (receipt on every DM before substantive reply)

This commit is contained in:
zai-agent 2026-09-17 11:13:33 +00:00
parent bcc381b97b
commit fd19d1c076

View file

@ -13,6 +13,7 @@ import { execFileSync } from 'node:child_process'
const RELAY = 'wss://ch4t.buzz' const RELAY = 'wss://ch4t.buzz'
const ME = '4abe5fcdf9695be34bdfc8fe82297aaaf0cf65b5ca92b6c789f6f8783b5ee197' const ME = '4abe5fcdf9695be34bdfc8fe82297aaaf0cf65b5ca92b6c789f6f8783b5ee197'
const DM_CHANNEL = '4113fff6-f288-46af-927e-094b5a8386f2'
const INBOX = '/home/opc/.buzz-inbox' const INBOX = '/home/opc/.buzz-inbox'
const STATE = '/home/opc/.buzz-last-seen' const STATE = '/home/opc/.buzz-last-seen'
const MAX_LIFETIME = 120 * 1000 // reconnect every 2 min: replays since lastSeen (zombie-socket proof) const MAX_LIFETIME = 120 * 1000 // reconnect every 2 min: replays since lastSeen (zombie-socket proof)
@ -78,6 +79,13 @@ ws.onmessage = (msg) => {
saveLastSeen(evt.created_at + 1) saveLastSeen(evt.created_at + 1)
fs.appendFileSync(INBOX, JSON.stringify(evt) + '\n') fs.appendFileSync(INBOX, JSON.stringify(evt) + '\n')
console.error('message received from', evt.pubkey.slice(0, 10)) console.error('message received from', evt.pubkey.slice(0, 10))
// Instant DM receipt: the sender should never wonder if we're alive.
const chTag = (evt.tags.find((t) => t[0] === 'h') || [])[1] || ''
if (chTag === DM_CHANNEL) {
try {
execFileSync(BUZZ_CLI, ['messages', 'send', '--channel', chTag, '--reply-to', evt.id, '--content', '✓ received — will respond in a moment'], { timeout: 15000, stdio: 'ignore' })
} catch {}
}
process.exit(0) process.exit(0)
} }
if (type === 'EOSE') console.error('EOSE — live') if (type === 'EOSE') console.error('EOSE — live')