是否可以通过 API 进行分配?我在文档中没有看到,但我很乐意被惊喜 ![]()
编辑:看起来我将尝试逆向工程!
首先,我们的目标是拥有一个稳定的API,这是一项需要多年努力才能实现的目标,但毫无疑问是我们希望达到的地方。
在此期间,一个合理的2025年技巧是依靠AI代理来解决这些问题:
这展示了如何依靠我们的GitHub助手来回答问题!
你弄明白了吗?如果弄明白了,可以在这里分享你的经验吗?
嘿!
还没有!这个项目因为更紧急的事情被推迟了,但我下周会重新开始做 ![]()
@tobiaseigen 这在我的 node js 上运行正常
var https = require(‘https’);
// 配置
var CONFIG = {
apiUrl: ‘YOURDISCOURSEDOMAIN’,
apiKey: ‘YOURAPIKEY’,
apiUsername: ‘YOURAPIUSER’,
assignToUsername: ‘USERNAMETOASSIGNTO’ // 要分配话题的用户名
};
// 要分配的话题 ID
var topicIds = [634]; // 用话题 ID 更改
function assignTopic(topicId, callback) {
var postData = JSON.stringify({
target_id: topicId,
target_type: ‘Topic’,
username: CONFIG.assignToUsername
});
var options = {
hostname: CONFIG.apiUrl,
port: 443,
path: ‘/assign/assign.json’,
method: ‘PUT’,
rejectUnauthorized: false,
headers: {
‘Api-Key’: CONFIG.apiKey,
‘Api-Username’: CONFIG.apiUsername,
‘Content-Type’: ‘application/json’,
‘Content-Length’: postData.length
}
};
var req = https.request(options, function(res) {
var data = ‘’;
res.on('data', function(chunk) {
data += chunk;
});
res.on('end', function() {
console.log('状态:', res.statusCode);
console.log('原始响应:', data);
try {
var response = JSON.parse(data);
if (res.statusCode === 200) {
console.log('话题 ' + topicId + ' 分配成功');
} else {
console.log('话题 ' + topicId + ' 错误:', response.errors || response.error_type || response);
}
} catch (e) {
console.log('解析错误:', e.message);
}
if (callback) callback();
});
});
req.on(‘error’, function(e) {
console.error('话题 ' + topicId + ' 的请求错误:', e);
if (callback) callback();
});
req.write(postData);
req.end();
}
// 顺序运行
var index = 0;
function next() {
if (index < topicIds.length) {
assignTopic(topicIds[index], function() {
index++;
setTimeout(next, 500);
});
}
}
console.log('正在分配话题:', topicIds.join(‘, ‘));
console.log('分配给:', CONFIG.assignToUsername);
console.log(’’);
next();
Discourse Assign 暴露了以下 API 端点:
/assign/assign.json)必需参数:
target_id - 主题或帖子 IDtarget_type - 必须是 "Topic" 或 "Post"外加以下之一:
username - 要分配的用户名group_name - 要分配的组名可选参数:
note - 分配备注status - 分配状态should_notify - 发送通知 (默认值: true)/assign/unassign.json)必需参数:
target_id - 主题或帖子 IDtarget_type - 必须是 "Topic" 或 "Post"# 将主题 123 分配给用户 "john"
curl -X PUT "https://your-discourse.com/assign/assign.json" \
-H "Api-Key: YOUR_API_KEY" \
-H "Api-Username: YOUR_USERNAME" \
-H "Content-Type: application/json" \
-d '{"target_id": 123, "target_type": "Topic", "username": "john"}'
# 分配给一个组而不是用户
curl -X PUT "https://your-discourse.com/assign/assign.json" \
-H "Api-Key: YOUR_API_KEY" \
-H "Api-Username: YOUR_USERNAME" \
-H "Content-Type: application/json" \
-d '{"target_id": 123, "target_type": "Topic", "group_name": "support-team"}'
备注
target_type: "Post" 和帖子 ID 来分配单个帖子@opcourdis 上面的 Node.js 示例看起来是正确的!![]()
感谢分享,很高兴看到我们可以包含所有这些参数