Webhooks Issue - Not Receiving Real Events

Hey,

I need help with debugging my webhooks, so I already have a webhook setup and it is currently living in an aws lambda function. I have correctly responded to the challenge and I know for sure that I’m currently subscribe to eventsub since I use the get method for subscription and I see my subscription there with my id. I also know that my callback is working because I can test it with the Twitch cli and it is responding with 200, and my cloudwatch also logs them properly, so I know my lambda function really receives those test event.

But now when I actually tried to do some real events on my account like following it with another user, it does not receive any notification. So basically, my partner’s twitch account will unfollow my page, then wait for about a minute and then follow it again, but I don’t receive any event, the lambda function is not even firing since at the very top I have a simple console log to see if it will fire.

I have the scope of “moderator:read:followers” and I’m currently subscribe to “channel.follow”.

I also tried to delete my subscription and resub again but still no effect. But when I do it with my CLI, it works normally.

Also, not related but why is the headers for event sub not uniform? The challenge header has a camel case but the notification header has a lower case, it’s weird…

Thank you

This generally won’t work as twitch will attempt to reduce spam and prevent refollows notifiy.
Thats for all things that nofity for follows like email and so on.

channel.update is likely more reliable to test with than (re)follows

the HTTP specfiication states the casting of headers is irrelevant.
Most libraries will convert the key names of headers to all lower case during capture of the HTTP request.

is the subscription enabled in the status field?

Ohh yeah that’s what I figured, therefore, I added the stream.online and stream.offline on my subscription and tried going live but yeah my endpoint still didn’t receive any.

Yup just found this a while ago, and it’s current status is webhook_callback_verification_failed and I’m assuming because I’m not returning the correct challenge.

here are the things that I tried

const bodyObject = JSON.parse(event.body);
return {
    body: bodyObject.challenge,
};
return bodyObject.challenge

While checking the docs, I think this is the part that I’m missing as I don’t understand what it means

the response body must contain the raw challenge value, and you must set the Content-Type response header to the length of the challenge value

What library are you using in node to serve with? (assuming node)

I’m not sure I’m following, you mean like npm packages? in aws, I’m not using any dependency right now, so I’m just using whatever it have by default

Here’s how I return my challenge, not sure if it will help

export const handler = async (event) => {
  console.log(event);
  const bodyObject = JSON.parse(event.body);
  console.log(bodyObject.challenge);

  const headers = event.headers;

  const camelCaseHeader = "Twitch-Eventsub-Message-Type";
  const lowerCaseHeader = camelCaseHeader.toLowerCase();

  if (headers[camelCaseHeader]) {
    handleChallenge(headers[camelCaseHeader]);
  } else if (headers[lowerCaseHeader]) {
    handleChallenge(headers[lowerCaseHeader]);
  }

  function handleChallenge(messageType) {
    if (messageType == "webhook_callback_verification") {
      console.log("Challenge has return")
      return bodyObject.challenge;
    }
  }

  // TODO implement
  const response = {
    statusCode: 200,
  };
  return response;
};

The challenge handler is being triggered during subscription because I can see the log

use the CLI to test it

I’m not sure what you need to do here to return the right things.

Personally I use express.

heres my example using express twitch_misc/receive.js at main · BarryCarlyon/twitch_misc · GitHub

Yeah, CLI correctly responds to my callback, but does it have a way to check for the challenge instead of a trigger for events?
image

twitch event verify-subscription

1 Like

Eyyyy, it works! status is now set to enabled, Thank you!

Here’s my solution:
This is mainly for aws lambda, make sure to set the content-type to text/plain, and then for some reason even tho I have set the return on my challenge handler, the function still runs and also returns the 200 at the very bottom so technically I’m also returning a wrong challenge, so just make a response variable at the top and update this inside the challenge function and finally just do one return response at the very end


export const handler = async (event) => {
  let response = {
    statusCode: 200
  }
  
  const bodyObject = JSON.parse(event.body);
  const headers = event.headers;

  const camelCaseHeader = "Twitch-Eventsub-Message-Type";
  const lowerCaseHeader = camelCaseHeader.toLowerCase();

  if (headers[camelCaseHeader]) {
    handleChallenge(headers[camelCaseHeader]);
  } else if (headers[lowerCaseHeader]) {
    handleChallenge(headers[lowerCaseHeader]);
  }
  
  function handleChallenge(messageType) {
    if (messageType == "webhook_callback_verification") {
      response = {
        statusCode: 200,
        headers: {
         "content-type": "text/plain"
        },
        body: bodyObject.challenge
      };
    }
  }

  return response;
};

EDIT: I just freaking realize while reading my own post that I’m not actually returning anything on my challenge handler function because that’s a separate function and by default I’m just returning outside of that function :man_facepalming:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.