Some checks failed
Deploy / deploy (push) Has been cancelled
Full-stack web application for Telegram management - Frontend: Vue 3 + Vben Admin - Backend: NestJS - Features: User management, group broadcast, statistics 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
77 lines
2.9 KiB
JavaScript
77 lines
2.9 KiB
JavaScript
// 测试 getMessages 和 sendMessage 方法是否正常工作
|
|
const axios = require('axios');
|
|
|
|
const API_BASE = 'http://localhost:3000';
|
|
const TOKEN = '123456';
|
|
const ACCOUNT_ID = 3044; // 使用18285198777这个账号
|
|
|
|
async function testChatFunctions() {
|
|
console.log('=== 测试聊天功能 ===\n');
|
|
|
|
// 1. 测试获取对话列表
|
|
console.log('1. 测试获取对话列表...');
|
|
try {
|
|
const dialogsRes = await axios.post(
|
|
`${API_BASE}/tgAccount/getDialogs`,
|
|
{
|
|
accountId: ACCOUNT_ID,
|
|
limit: 10
|
|
},
|
|
{
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'token': TOKEN
|
|
}
|
|
}
|
|
);
|
|
|
|
if (dialogsRes.data.success) {
|
|
console.log(`✅ 成功获取 ${dialogsRes.data.data.length} 个对话`);
|
|
|
|
// 如果有对话,测试获取第一个对话的消息
|
|
if (dialogsRes.data.data.length > 0) {
|
|
const firstDialog = dialogsRes.data.data[0];
|
|
console.log(` 第一个对话: ${firstDialog.title}`);
|
|
|
|
// 2. 测试获取消息
|
|
console.log('\n2. 测试获取消息...');
|
|
try {
|
|
const messagesRes = await axios.post(
|
|
`${API_BASE}/tgAccount/getMessages`,
|
|
{
|
|
accountId: ACCOUNT_ID,
|
|
peerId: firstDialog.peerId,
|
|
limit: 5
|
|
},
|
|
{
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'token': TOKEN
|
|
}
|
|
}
|
|
);
|
|
|
|
if (messagesRes.data.success) {
|
|
console.log(`✅ 成功获取 ${messagesRes.data.data.length} 条消息`);
|
|
messagesRes.data.data.forEach((msg, index) => {
|
|
console.log(` 消息${index + 1}: ${msg.message ? msg.message.substring(0, 50) + '...' : '(无文本)'}`);
|
|
});
|
|
} else {
|
|
console.log(`❌ 获取消息失败: ${messagesRes.data.message}`);
|
|
}
|
|
} catch (error) {
|
|
console.log(`❌ 获取消息失败: ${error.response?.data?.message || error.message}`);
|
|
}
|
|
}
|
|
} else {
|
|
console.log(`❌ 获取对话列表失败: ${dialogsRes.data.message}`);
|
|
}
|
|
} catch (error) {
|
|
console.log(`❌ 获取对话列表失败: ${error.response?.data?.message || error.message}`);
|
|
}
|
|
|
|
console.log('\n=== 测试完成 ===');
|
|
}
|
|
|
|
// 运行测试
|
|
testChatFunctions().catch(console.error); |