Luigit
repositories / will

will

owned by admin

scripts/dev-chat.mjs

Raw
#!/usr/bin/env node
/**
 * Send a chat message to the local dev body's fake telegram.
 * The fake echoes it back as a mention, which wakes will.
 *   mise run dev:chat hello will
 */
const text = process.argv.slice(2).join(' ')
if (text === '') {
  console.error('usage: mise run dev:chat <message>')
  process.exit(1)
}
try {
  const res = await fetch('http://localhost:38080/bot-dev-token/sendMessage', {
    method: 'POST',
    headers: { 'content-type': 'application/json' },
    body: JSON.stringify({ chat_id: -100, text }),
  })
  if (!res.ok) throw new Error(`fake telegram ${res.status}`)
  console.log(`sent: ${text}`)
  console.log(
    'the fake telegram echoes it to will as a mention; watch the timeline: http://localhost:3000',
  )
} catch (err) {
  console.error(`delivery failed: ${err instanceof Error ? err.message : String(err)}`)
  console.error('is the dev body up? mise run dev')
  process.exit(1)
}