Closed SebPautot closed 4 years ago
Hi,
Yes this part definitely needs more doc and more logs to be able to debug problems 👍
Those 4 events are the webhook ones, most of the time what can prevent webhooks to work is that twitch http requests don't reach your server (if it's a server at home, the port must be forwarded in your router interface to your machine).
Here is a config example that works without proxy:
{
channel: "(my channel)",
client_id: "(my client id)",
client_secret: "(my client secret)",
callback_url: "http://(my ip):3000/",
port: 3000
}
Here is an example where the webhook requests go through an express proxy on port 3000 that logs them before redirecting them to port 3001. That may be useful to debug because I log the requests. When the server starts you should see 2 http calls that end with a 202 response code:
GET /twitch-callback/follows.to.xxx?hub.challenge=xxx&hub.lease_seconds=100000&hub.mode=subscribe&hub.topic=https%3A%2F%2Fapi.twitch.tv%2Fhelix%2Fusers%2Ffollows%3Ffirst%3D1%26to_id%3Dxxx 202 - - 20.037 ms
GET /twitch-callback/stream.change.xxx?hub.challenge=xxx&hub.lease_seconds=100000&hub.mode=subscribe&hub.topic=https%3A%2F%2Fapi.twitch.tv%2Fhelix%2Fstreams%3Fuser_id%3Dxxx 202 - - 6.530 ms
const express = require("express");
const proxy = require("express-http-proxy");
const channel = require("twitch-channel");
const morgan = require("morgan");
const { TwitchChannel } = require("twitch-channel");
async function start() {
const app = express();
app.use(morgan("tiny"));
app.use("/twitch-callback", proxy("http://localhost:3001"));
await new Promise((resolve) => {
app.listen(3000, resolve);
});
const channel = new TwitchChannel({
channel: "(my channel)",
client_id: "(my client id)",
client_secret: "(my client secret)",
callback_url: "http://(my ip):3000/twitch-callback",
port: 3001,
});
channel.on("stream-begin", ({ game }) => {
console.log(`stream-begin: ${game}`);
});
await channel.connect();
}
start().catch((error) => {
console.error(error);
process.exit(1);
});
Are webhooks the only things that need a specified port to be listened or not ? That might be the reason why.
Yes we need the port only for webhooks
Ok that's why. I host the code on Glitch and the requests from the internet are limited to port 3000, but I didn't make a proxy, so all listeners are listening to port 4000, 4001, 4002,etc... It was working without proxy so I thought it was ok, even if I didn't understand why it was ok. I didn't know the other ones didn't need ports.
Thanks for the info :)
I don't know why they don't work but it's a bit annoying. I know start-stream needs 3 minutes after the stream starts to actually receive the signal and stream-end is 7 minutes, but even with these conditions I don't think it's receiving a thing. Those 4 simply don't work (sadly I couldn't test a lot changed game but I assume it doesn't work as well as it's supposed to be on the same webhook).
At least the rest works 24/7, it's a super cool package for Twitch API imo, I'm really happy I found this. Keep up the good work :) I'll update the issue if I have any updates on why it doesn't listen to these events.