如何使用机器人在Slack Channel上发布消息?
我试图像频道上的某人说“你好”我的机器人回答“ que puis-je pour toi?” 为此,我有这样的事情:
const bot = new App ({
token : process.env.SLACK_ACCESS_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET,
socketMode : true,
appToken : process.env.SOCKET_TOKEN,
});
const web = new WebClient(process.env.SLACK_BOT_TOKEN,{logLevel: LogLevel.DEBUG});
(async () => {
await bot.start(process.env.PORT || 3000)
.catch(console.error)
console.log("Slack ok")
sendMessage(process.env.SLACK_CHANNEL, 'Bonjour !')
})();
bot.message('hello', async ({ message, say }) => {
await say(`Bonjour <@${message.user}>, que puis-je pour toi?`)
.catch(console.error)
});
async function sendMessage (channel, message) {
await web.chat.postMessage({
channel: channel,
text: message,
})
}
但是什么都没有发生。.
我的bot。在我的控制台“ slack ok”中启动返回,当我输入消息时,我的bot会在我的松弛频道上发送,但是当我打招呼时,它不起作用。
有人可以解释我为什么?
I try to params my bot like if someone on the channel says 'hello' my bot answer 'Que puis-je pour toi?'
To do this i have this :
const bot = new App ({
token : process.env.SLACK_ACCESS_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET,
socketMode : true,
appToken : process.env.SOCKET_TOKEN,
});
const web = new WebClient(process.env.SLACK_BOT_TOKEN,{logLevel: LogLevel.DEBUG});
(async () => {
await bot.start(process.env.PORT || 3000)
.catch(console.error)
console.log("Slack ok")
sendMessage(process.env.SLACK_CHANNEL, 'Bonjour !')
})();
bot.message('hello', async ({ message, say }) => {
await say(`Bonjour <@${message.user}>, que puis-je pour toi?`)
.catch(console.error)
});
async function sendMessage (channel, message) {
await web.chat.postMessage({
channel: channel,
text: message,
})
}
But nothing is happening..
My bot.start return in my console "slack ok", when i put a message, my bot sends on my slack channel but when i write hello, it doesn't work.
Someone can explains me why ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,机器人缺少权限:
您可以阅读 ,机器人需要范围
im:历史记录
才能在频道中读取消息。您是否将此范围分配给了该应用程序?This looks to me like the bot is missing permissions:
As you can read here, the bot needs scope
im:history
to read messages in channels. Have you assigned this scope to the app?