如何使用机器人在Slack Channel上发布消息?

发布于 2025-01-30 09:05:23 字数 934 浏览 5 评论 0原文

我试图像频道上的某人说“你好”我的机器人回答“ 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅沫记忆 2025-02-06 09:05:23

在我看来,机器人缺少权限:
您可以阅读 ,机器人需要范围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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文