DEV Community

NOGIER Loïc
NOGIER Loïc

Posted on • Updated on

Twitch IRC Capability WebSocket (help)

I'am trying to get a event when a moderator unban a user in the chat, i send a resquest for twitch.tv/tags but i didn't receive any messages when user was ban or unban...

it is my actual code :

const WebSocket = require('ws');

const ws = new WebSocket('wss://irc-ws.chat.twitch.tv:443');

ws.onopen = function(event) {
  console.log('INFO: Socket Opened'); 
  ws.send('CAP REQ :twitch.tv/commands');
  ws.send('CAP REQ :twitch.tv/membership');
  ws.send('CAP REQ :twitch.tv/tags');
  ws.send('PASS oauth:...');
  ws.send('NICK zaekof_');
  ws.send('JOIN #zaekof_');
  ws.send('USER #zaekof_');
};
ws.onerror = function(error) {
  console.log('ERR: ', error);
};
ws.onclose = function() {
  console.log('INFO: Socket Closed');
}; 
ws.onmessage = function(event) {
  console.log('RECV: ', event.data);
};
Enter fullscreen mode Exit fullscreen mode

When i'am connected on irc chat, i receive a follows messages :

RECV:  :tmi.twitch.tv CAP * ACK :twitch.tv/commands
RECV:  :tmi.twitch.tv CAP * ACK :twitch.tv/membership
RECV:  :tmi.twitch.tv CAP * ACK :twitch.tv/tags

RECV:  :tmi.twitch.tv 001 zaekof_ :Welcome, GLHF!
:tmi.twitch.tv 002 zaekof_ :Your host is tmi.twitch.tv
:tmi.twitch.tv 003 zaekof_ :This server is rather new
:tmi.twitch.tv 004 zaekof_ :-
:tmi.twitch.tv 375 zaekof_ :-
:tmi.twitch.tv 372 zaekof_ :You are in a maze of twisty passages, all alike.:tmi.twitch.tv 376 zaekof_ :>
Enter fullscreen mode Exit fullscreen mode

Would anyone have an idea to help me?

Thanks.

Top comments (5)

Collapse
 
ericeberhart profile image
Eric_Eberhart

The Twitch IRC Capability WebSocket is a feature that enables communication between Twitch chat clients and the Twitch IRC (Internet Relay Chat) servers using the WebSocket protocol. This capability allows developers to create chat bots, moderation tools, and other applications that interact with Twitch chat programmatically.

Here's how it works:

WebSocket Protocol: WebSocket is a communication protocol that provides full-duplex communication channels over a single TCP connection. It allows for real-time, bi-directional communication between clients and servers, making it ideal for applications that require low-latency communication, such as chat.

IRC Capability: Internet Relay Chat (IRC) is a protocol used for real-time text messaging and communication. Twitch provides an IRC interface for its chat system, allowing users to send and receive messages in chat channels. The IRC Capability WebSocket extends this functionality by providing a WebSocket interface for interacting with Twitch chat.

Benefits: Using the WebSocket interface for Twitch chat offers several advantages over traditional IRC connections, including better support for modern web technologies, improved performance, and easier integration with web-based applications. WebSocket connections are also more firewall-friendly and can traverse proxies more easily than traditional IRC connections.

Authentication: To use the Twitch IRC Capability WebSocket, developers must authenticate their connections using OAuth tokens. These tokens authorize the application to access Twitch chat on behalf of the user, allowing it to send and receive messages, join channels, and perform other chat-related actions.

API Endpoints: Twitch provides API endpoints for interacting with the IRC Capability WebSocket, including endpoints for connecting to chat channels, sending messages, receiving messages, and managing chat moderators and permissions.

Overall, the Twitch IRC Capability WebSocket provides developers with a powerful and flexible way to build chat-based applications for the Twitch platform, enabling real-time communication and interaction with Twitch chat channels programmatically.

Collapse
 
flozero profile image
florent giraud

did you consider using that lib ? docs.tmijs.org/v1.4.2/Events.html

It will facilitate you the job :)

Collapse
 
zaekof profile image
NOGIER Loïc

Thanks for reply, i go look :)

Collapse
 
zaekof profile image
NOGIER Loïc

It is a right way to do what i want ?

const tmi = require("tmi.js");

let options = {
  options: {
    debug: true,
    clientId: '...'
  },
  connection: {
    server: 'irc-ws.chat.twitch.tv',
    reconnect: true,
    secure: true
  },
  identity: {
    username: "zaekof_",
    password: "oauth:..."
  },
  channels: [ "#zaekof_" ]
};

let client = new tmi.client(options);

client.on("notice", (channel, msgid, message) => {
  console.log(msgid, message);
});

client.connect();

I didn't have any return when i use /unban in chat, just :

[16:34] info: [#zaekof_] ... has been banned.

I'm confused, I must have missed something ^

Thread Thread
 
flozero profile image
florent giraud

you have to put the ids from the bot or you depend and ban from this user you or the bot because it will listen commands from the ids you enter client secret or id