# Webhooks Issue - Not Receiving Real Events

**URL:** <https://discuss.dev.twitch.com/t/webhooks-issue-not-receiving-real-events/44736>\
**Category:** API\
**Created:** [April 3, 2023, 4:36am UTC](https://discuss.dev.twitch.com/t/webhooks-issue-not-receiving-real-events/44736 "2023-04-03T04:36:22Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peepersoak](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/peepersoak/32/23759_2.png) [@Peepersoak](https://discuss.dev.twitch.com/u/Peepersoak)\
**Post date:** [April 3, 2023, 4:36am UTC](https://discuss.dev.twitch.com/t/webhooks-issue-not-receiving-real-events/44736/1 "2023-04-03T04:36:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [April 3, 2023, 8:48am UTC](https://discuss.dev.twitch.com/t/webhooks-issue-not-receiving-real-events/44736/2 "2023-04-03T08:48:23Z")

</div>

> [@Peepersoak](#):
>
> 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”.

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

> [@Peepersoak](#):
>
> 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…

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.

> [@Peepersoak](#):
>
> currently subscribe to eventsub since I use the get method for subscription and I see my subscription there with my id.

is the subscription `enabled` in the `status` field?

---

<div class="post-metadata">

**Author:** ![Peepersoak](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/peepersoak/32/23759_2.png) [@Peepersoak](https://discuss.dev.twitch.com/u/Peepersoak)\
**Post date:** [April 3, 2023, 11:36pm UTC](https://discuss.dev.twitch.com/t/webhooks-issue-not-receiving-real-events/44736/3 "2023-04-03T23:36:48Z")

</div>

> [@BarryCarlyon](#):
>
> 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

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.

> [@BarryCarlyon](#):
>
> is the subscription `enabled` in the `status` field?

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

```auto
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

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [April 3, 2023, 11:37pm UTC](https://discuss.dev.twitch.com/t/webhooks-issue-not-receiving-real-events/44736/4 "2023-04-03T23:37:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Peepersoak](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/peepersoak/32/23759_2.png) [@Peepersoak](https://discuss.dev.twitch.com/u/Peepersoak)\
**Post date:** [April 3, 2023, 11:46pm UTC](https://discuss.dev.twitch.com/t/webhooks-issue-not-receiving-real-events/44736/5 "2023-04-03T23:46:46Z")

</div>

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

```auto
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

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [April 3, 2023, 11:49pm UTC](https://discuss.dev.twitch.com/t/webhooks-issue-not-receiving-real-events/44736/6 "2023-04-03T23:49:24Z")

</div>

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](https://github.com/BarryCarlyon/twitch_misc/blob/main/eventsub/webhooks/nodejs/receive.js)

---

<div class="post-metadata">

**Author:** ![Peepersoak](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/peepersoak/32/23759_2.png) [@Peepersoak](https://discuss.dev.twitch.com/u/Peepersoak)\
**Post date:** [April 3, 2023, 11:54pm UTC](https://discuss.dev.twitch.com/t/webhooks-issue-not-receiving-real-events/44736/7 "2023-04-03T23:54:36Z")

</div>

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](https://d2opxh93rbxzdn.cloudfront.net/original/3X/a/6/a6e448c38b423fb1ced08bbb916a1d880e8cc6d4.png)

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [April 3, 2023, 11:59pm UTC](https://discuss.dev.twitch.com/t/webhooks-issue-not-receiving-real-events/44736/8 "2023-04-03T23:59:30Z")

</div>

`twitch event verify-subscription`

---

<div class="post-metadata">

**Author:** ![Peepersoak](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/peepersoak/32/23759_2.png) [@Peepersoak](https://discuss.dev.twitch.com/u/Peepersoak)\
**Post date:** [April 4, 2023, 12:45am UTC](https://discuss.dev.twitch.com/t/webhooks-issue-not-receiving-real-events/44736/9 "2023-04-04T00:45:01Z")

</div>

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

```auto

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 🤦‍♂️

---

<div class="post-metadata">

**Author:** ![system](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://discuss.dev.twitch.com/u/system)\
**Post date:** [May 4, 2023, 12:45am UTC](https://discuss.dev.twitch.com/t/webhooks-issue-not-receiving-real-events/44736/10 "2023-05-04T00:45:48Z")

</div>

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