'How to post message on slack channel with a 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 ?



Solution 1:[1]

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?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Th3Ph4nt0m