2026-03-11 10:57:23 +08:00
|
|
|
|
require('dotenv').config();
|
2026-03-06 09:59:01 +08:00
|
|
|
|
const express = require('express');
|
2026-03-11 10:57:23 +08:00
|
|
|
|
const path = require('path');
|
|
|
|
|
|
const handleWebhook = require('./webhook');
|
2026-03-06 09:59:01 +08:00
|
|
|
|
|
|
|
|
|
|
const app = express();
|
2026-03-11 10:57:23 +08:00
|
|
|
|
const PORT = process.env.PORT || 3000;
|
|
|
|
|
|
|
2026-03-06 09:59:01 +08:00
|
|
|
|
app.use(express.json());
|
2026-03-11 10:57:23 +08:00
|
|
|
|
app.use(express.urlencoded({ extended: true }));
|
|
|
|
|
|
app.use(express.static(path.join(__dirname, 'public')));
|
2026-03-06 09:59:01 +08:00
|
|
|
|
|
|
|
|
|
|
app.get('/health', (req, res) => {
|
2026-03-11 10:57:23 +08:00
|
|
|
|
res.json({
|
|
|
|
|
|
status: 'ok',
|
|
|
|
|
|
time: new Date().toISOString(),
|
|
|
|
|
|
webhook_path: '/webhook'
|
|
|
|
|
|
});
|
2026-03-06 09:59:01 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
app.get('/', (req, res) => {
|
2026-03-11 10:57:23 +08:00
|
|
|
|
res.json({
|
|
|
|
|
|
message: '钉钉机器人服务运行中',
|
|
|
|
|
|
mode: 'webhook',
|
|
|
|
|
|
time: new Date().toLocaleString('zh-CN')
|
|
|
|
|
|
});
|
2026-03-06 09:59:01 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
app.post('/webhook', handleWebhook);
|
|
|
|
|
|
|
2026-03-11 10:57:23 +08:00
|
|
|
|
app.listen(PORT, () => {
|
|
|
|
|
|
console.log(`之之秋秋机器人启动:http://localhost:${PORT}`);
|
|
|
|
|
|
console.log(`Webhook: http://localhost:${PORT}/webhook`);
|
2026-03-06 09:59:01 +08:00
|
|
|
|
});
|