【发布时间】:2020-10-02 21:55:31
【问题描述】:
我正在尝试使用 botkit 和 Google App Engine 创建一个非常简单的 Slack 机器人,但由于某种原因,我每次向机器人发送消息时都会收到 401 错误。奇怪的是,Slack 事件订阅 URL(以 /api/messages 结尾的 URL)验证正确,我在 GAE 日志中收到 200 响应,并在 Slack 中进行验证。
但是,每当我实际向机器人发送消息时,它总是会收到 401 错误,而根本没有解释该错误的消息。我尝试了以下代码的各种组合,现在已将其精简到最低限度,如发现 here。除了依赖项和解密凭据的代码(我已经验证它按预期工作)之外,这是我目前的完整代码:
botInit();
async function botInit () {
const credentialsRaw = await getCredentials();
const credentials = JSON.parse(credentialsRaw);
const adapter = new SlackAdapter(credentials);
const controller = new Botkit({
adapter: adapter
});
controller.on('message', async(bot, message) => {
await bot.reply(message, 'I heard a message!');
});
}
我也试过这个消息功能:
controller.ready(() => {
controller.hears(['hello', 'hi'], ['message', 'direct_message'],
async (bot, message) => {
await bot.reply(message, 'Meow. :smile_cat:')
})
})
这用于设置控制器:
const controller = new Botkit({
webhook_uri: '/api/messages',
adapter: adapter
});
尽管所有这些都使用 Slack 上的事件订阅 URL 验证,但一切都返回了完全相同的 401 错误。
【问题讨论】:
标签: node.js google-app-engine slack-api botkit