[SOLVED] Nothing is received - Twitch API - Twitch-Channel (NPM Package)

The Twitch API doesn’t seem to get any response from the Twitch webhook. It might be linked to the ping websites ban as Twitch webhook might put a lot of pressure too.

I run my Discord bot with Discord.js
I also have access to the Twitch API with Twitch-Channel (https://www.npmjs.com/package/twitch-channel)

I copied and paste the example provided by twitch-channel and started doing my stuff with it but it turns out I don’t have access to 4 events which are using Twitch Webhooks. I already asked the creator of twitch-channel for some advices through GitHub but it turns out it should have been working.

Everything is correct, I just can’t receive anything back from webhook-based events. It might be because of Glitch… Can anyone provide an answer to why it doesn’t receive the webhook data ?

Code :

channel[guild.id] = new TwitchChannel({
  channel: guildparam.sub,
  bot_name: "streamnotifierbot", // twitch bot login 
  bot_token: "", // create your token here https://twitchapps.com/tmi/
  client_id: "", // get it by registering a twitch app https://dev.twitch.tv/dashboard/apps/create (Redirect URI is not used)
  client_secret: "", // secret of your registered twitch app
  streamlabs_socket_token: guildparam.streamlabtoken, // get yours here https://streamlabs.com/dashboard#/apisettings in API TOKENS then "your socket API token"
  port: LocalPort, // the lib will listen to this port
  callback_url: "https://streamnotifier.glitch.me/", // url to your server, accessible from the outside world
  secret: "no", // any random string
  is_test: true // set to true to listen to test donations and hosts from streamlabs
}); 

channel[guild.id].connect()
channel[guild.id].on("follow", async ({ viewerId, viewerName }) => {
 fetched = db.fetch(`guildparam_${guild.id}`);
if (fetched == null) var newguildparam = {prefix:"S!"};
else var newguildparam = fetched;
  if(newguildparam.sub != guildparam.sub) return await channel[guild.id].disconnect();
  
  if(newguildparam.notifications.follow == true){
    var tosend = newguildparam.message.follow
      .replace(/{viewerName}/g, viewerName)
      .replace(/{streamer}/g, newguildparam.sub)
    
    const embed = new Discord.RichEmbed()
    
    .setTitle('Follow')
    .setAuthor('StreamNotifier')
    .setColor('RANDOM')
    .addField(tosend,"\u200C")
    .setURL('https://twitch.tv/'+guildparam.sub)
    
    client.channels.get(newguildparam.channel).send(embed)
  }

  if(newguildparam.counter.follow !=""){
    
    request.post("https://id.twitch.tv/oauth2/token?client_id=stuff&client_secret=stuff&grant_type=client_credentials&scope=stuff",function(error, response, body1){
      body1 = JSON.parse(body1)

    request({
  url: 'https://api.twitch.tv/helix/users/follows?first=1&to_id='+guildparam.subdata.id,
  headers: {
    'Client-ID':'qrgioeji5fs7tvzthfy1j2175u6ohk',
    'Authorization': "Bearer "+body1.access_token
  }}, function(error, response, body2){
      
      body2 = JSON.parse(body2)
      client.channels.get(newguildparam.counter.follow).edit({ name: body2.total+" follows"})
      
    })
      })
    
  }
});

`

You should probably remove your API Keys/Bot Tokens from your code.

Are the webhooks going to twitch or going to your project?

Going to the project. Basically the subscription (request to Twitch) is working there is no problem with it but once the subscription is done, I just receive nothing (request to project). It should be working. That’s why I think it’s coming from Glitch…

Ah. I believe that Glitch likely blocked the request because it thinks that Twitch is an autopinger. I suppose you could just wait it out. I’m really sorry about this!

Yes maybe, that’s what I think too. I’m trying stuff on the callback URL. As I’m listening to ports from 4000, it might also be the reason why. But then why are the other events working… ?

Does Twitch give you any details if the request failed?

Nope :frowning: got no log for this

I think it’s because I listen to 4000, 4001,4002 and so on. I should use a proxy instead of sending request to inaccessible ports (only port 3000 is accessible from the open), Twitch needs the ports to be accessible from the open I think. I still don’t understand how the other requests can be listened to though :thinking: .