最近,我一直在用 Javascript 创建 Slack 机器人。然后我得到一个错误,是 token 类型,这是在
team.accessLogs()
funcntion is not allowed 中给出的。详细错误如下:
Error: An API error occurred: not_allowed_token_type
at platformErrorFromResult (/bot-todo/node_modules/@slack/bolt/node_modules/@slack/web-api/dist/errors.js:56:33)
at WebClient.apiCall (/bot-todo/node_modules/@slack/bolt/node_modules/@slack/web-api/dist/WebClient.js:181:56)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async getIPAddress (file:///bot-todo/program-test.js:18:27) {
code: 'slack_webapi_platform_error',
data: { ok: false, error: 'not_allowed_token_type', response_metadata: {} }
}
代码:
'use strict';
import bolt from '@slack/bolt';
import chalk from 'chalk';
import dotenv from 'dotenv';
dotenv.config();
import fs from 'node:fs';
import readline from 'readline';
const rs = fs.createReadStream('./meaning-data.csv');
const rl = readline.createInterface({ input: rs});
const app = new bolt.App(
{ token: process.env.SLACK_BOT_TOKEN,
appToken: process.env.SLACK_APP_TOKEN,
socketMode: true,
logLevel: 'debug'
});
async function getIPAddress(n, page) {
try {
const userInformation = await app.client.team.accessLogs({
token: "xoxb-5515557116866-5558641076690-dzK2Qk3c1HcaOx2OI0wlD8SU",
before: 1701620221,
count: n,
page: page,
limit: 1,
team_id: "T05F5GD3ERG"
});
console.log(chalk.blue(userInformation));
} catch(error){
console.error(chalk.red(error));
}
}
getIPAddress('1', "12");
SLACK_BOT_TOKEN="xoxb-5515557116866-5558641076690-dzK2Qk3c1HcaOx2OI0wlD8SU"
到目前为止,我尝试过:
accessLogs()
功能SLACK_APP_TOKEN
。图片↓
基于以上事实,为什么用
auth.test()
函数测试成功,而用team.accessLogs()
函数测试失败呢?
看起来您正在将
team_id
和机器人令牌 (xoxb-*) 传递给请求,但文档说“team_id 仅在使用组织级令牌时才相关。”。那么也许尝试省略 team_id 或使用组织级别令牌?
(抱歉,我没有足够的代表来发表评论)