/** * Live smoke test for DingTalk automation notifications. * * Usage: * SUPEN_DINGTALK_TEST_JID='dingtalk:appId:cid...' \ * pnpm --filter @supen-ai/daemon exec tsx --env-file=.env scripts/smoke-dingtalk-notify.ts */ import { Gateway, setGatewayInstance } from '../src/core/gateway.js'; import { sendExternalChannelNotification } from '../src/core/channel-notify.js'; import { buildAutomationChannelNotificationText } from '../src/core/workflow-notify.js'; async function main(): Promise { const jid = process.env.SUPEN_DINGTALK_TEST_JID?.trim(); if (!jid) { console.error('Missing SUPEN_DINGTALK_TEST_JID (format: dingtalk:appId:openConversationId)'); process.exit(2); } const gateway = new Gateway({ onMessage: () => {}, onChatMetadata: () => {}, }); setGatewayInstance(gateway); console.log('Connecting daemon gateway uplink...'); await gateway.connect(); if (!gateway.isConnected()) { throw new Error('Gateway uplink did not connect'); } console.log('Gateway connected.'); const text = buildAutomationChannelNotificationText({ automationName: 'Lucid smoke test', prompt: 'Supen DingTalk notify smoke test', taskId: 'task-smoke-test', threadUrl: 'https://app.supen.ai/tasks/task-smoke-test', outcome: 'succeeded', detail: 'If you see this in DingTalk, automation notifications are working.', eventEnvelope: { source: 'github', payload: { issue: { number: 0, title: 'Smoke test issue', html_url: 'https://github.com/example/repo/issues/0', }, }, }, }); console.log(`Sending test notification to ${jid} ...`); await sendExternalChannelNotification(jid, text, { traceId: 'smoke-dingtalk-notify' }); console.log('Notification sent successfully.'); await gateway.disconnect(); } main().catch((error) => { console.error(error instanceof Error ? error.message : String(error)); process.exit(1); });