Send a message to the chat via POST request

Please tell me how can I send a message via POST request to the streamer’s chat on twitch. First need to connect to the chat and then send a message, do I understand correctly? But I don’t know how to do it

Code:

import axios from "axios";

axios.post('https://id.twitch.tv/oauth2/token', {
  client_id: 'iwnng41kyacsy2v5mvzueo69y',
  client_secret: '6ujwqbnhy5ltv3l7uljc5k',
  grant_type: 'client_credentials'
})
.then(function (response) {
console.log(response);
})

.catch((e) => {
 console.log(e);
});

axios.get('https://api.twitch.tv/helix/search/channels?query=loserfruit', {
headers: {
  'Client-Id': 'iwnng41y2v5mvzueo69y',
  'Authorization': 'Bearer vz9fcq1xv0qximnykjf8x4ao0icrf5y4dv'
}})
.then(function (response) {
console.log(response);
})

.catch((e) => {
  console.log(e);
});

Thank you for your attention!

You cannot do this via axios POST or any POST request…

You need to connect to Twitch Chat via a socket, using an IRC style interface.
Then you can send/recieve like a IRC client would.

Like I said here

Which links to the documentation and an example bot script is included in the documentation

you can join the chat like this:

client.on('connect', function(connection) {
    console.log('WebSocket Client Connected');
    
    connection.sendUTF('CAP REQ :twitch.tv/membership twitch.tv/tags twitch.tv/commands');
    connection.sendUTF('PASS oauth:yfvzjqb705z12hrhy1zkwa9xt7v662');
    connection.sendUTF('NICK myusername');

    connection.sendUTF('JOIN #bar,#foo');
});

can you join with this code?

Looks plausible

ok, I will try