Skip to content

Commit

Permalink
feat: include challenge in EventSubNotification (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
iProdigy committed Jan 20, 2021
1 parent d68e404 commit c3764dd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
Expand Up @@ -24,4 +24,9 @@ public class EventSubNotification {
*/
private EventSubEvent event;

/**
* The value of challenge from the callback verification request must be returned to complete the verification process.
*/
private String challenge;

}
Expand Up @@ -25,7 +25,8 @@ public EventSubNotification deserialize(JsonParser p, DeserializationContext ctx
final SubscriptionType<?, ?, ?> type = sub.getType();
final EventSubEvent event = type != null ? getObject(p.getCodec(), root, "event", type.getEventClass()) : null;

return new EventSubNotification(sub, event);
final String challenge = root.path("challenge").asText(null);
return new EventSubNotification(sub, event, challenge);
}

private static <T> T getObject(ObjectCodec codec, JsonNode parent, String field, Class<T> clazz) {
Expand Down
Expand Up @@ -4,6 +4,7 @@
import com.github.twitch4j.eventsub.condition.ChannelFollowCondition;
import com.github.twitch4j.eventsub.events.ChannelFollowEvent;
import com.github.twitch4j.eventsub.subscriptions.SubscriptionTypes;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

Expand All @@ -17,6 +18,17 @@
public class EventSubNotificationTest {

@Test
@DisplayName("Deserialize Challenge")
public void deserializeChallenge() {
String json = "{\"subscription\":{\"id\":\"b9ee086b-4ff1-4f11-8be8-9c93e3cd9515\",\"status\":\"webhook_callback_verification_pending\",\"type\":\"channel.follow\",\"version\":\"1\",\"condition\":{\"broadcaster_user_id\":\"207813352\"}," +
"\"transport\":{\"method\":\"webhook\",\"callback\":\"https://twitch4j.ngrok.io\"},\"created_at\":\"2021-01-20T19:41:07.513199878Z\"},\"challenge\":\"sample-challenge\"}";

EventSubNotification notif = TypeConvert.jsonToObject(json, EventSubNotification.class);
assertEquals("sample-challenge", notif.getChallenge());
}

@Test
@DisplayName("Deserialize Follow Notification")
public void deserializeFollowNotification() {
EventSubNotification notif = TypeConvert.jsonToObject(
"{\"subscription\":{\"id\":\"f1c2a387-161a-49f9-a165-0f21d7a4e1c4\",\"status\":\"authorization_revoked\",\"type\":\"channel.follow\",\"version\":\"1\",\"condition\":{\"broadcaster_user_id\":\"12826\"},\"transport\":{\"method\":\"webhook\"," +
Expand Down
Expand Up @@ -144,6 +144,8 @@ default HystrixCommand<BitsLeaderboard> getBitsLeaderboard(

/**
* Creates a Custom Reward on a channel.
* <p>
* Query parameter broadcaster_id must match the user_id in the User-Access token.
*
* @param authToken User access token for the broadcaster (scope: channel:manage:redemptions).
* @param broadcasterId The id of the target channel, which must match the token user id.
Expand All @@ -164,7 +166,7 @@ HystrixCommand<CustomRewardList> createCustomReward(
/**
* Deletes a Custom Reward on a channel.
* <p>
* Only rewards created manually by a broadcaster in the Creator Dashboard or created programmatically by the same client_id can be deleted.
* Only rewards created programmatically by the same client_id can be deleted.
* Any UNFULFILLED Custom Reward Redemptions of the deleted Custom Reward will be updated to the FULFILLED status.
*
* @param authToken User access token for the broadcaster (scope: channel:manage:redemptions).
Expand All @@ -183,7 +185,7 @@ HystrixCommand<Void> deleteCustomReward(
/**
* Returns a list of Custom Reward objects for the Custom Rewards on a channel.
* <p>
* Developers only have access to update and delete rewards that were created manually by a broadcaster in the Creator Dashboard or created programmatically by the same/calling client_id.
* Developers only have access to update and delete rewards that were created programmatically by the same/calling client_id.
* <p>
* There is a limit of 50 Custom Rewards on a channel at a time. This includes both enabled and disabled Custom Rewards.
*
Expand All @@ -205,7 +207,7 @@ HystrixCommand<CustomRewardList> getCustomRewards(
/**
* Returns Custom Reward Redemption objects for a Custom Reward on a channel that was created by the same client_id.
* <p>
* Developers only have access to get and update redemptions for the rewards created manually by a broadcaster in the Creator Dashboard or created programmatically by the same client_id.
* Developers only have access to get and update redemptions for the rewards created programmatically by the same client_id.
*
* @param authToken User access token for the broadcaster (scope: channel:manage:redemptions).
* @param broadcasterId The id of the target channel, which must match the token user id.
Expand Down Expand Up @@ -233,7 +235,7 @@ HystrixCommand<CustomRewardRedemptionList> getCustomRewardRedemption(
/**
* Updates a Custom Reward created on a channel.
* <p>
* Only rewards created manually by a broadcaster in the Creator Dashboard or created programmatically by the same client_id can be updated.
* Only rewards created programmatically by the same client_id can be updated.
*
* @param authToken User access token for the broadcaster (scope: channel:manage:redemptions).
* @param broadcasterId The id of the target channel, which must match the token user id.
Expand All @@ -256,7 +258,7 @@ HystrixCommand<CustomRewardList> updateCustomReward(
/**
* Updates the status of Custom Reward Redemption objects on a channel that are in the UNFULFILLED status.
* <p>
* Only redemptions for a reward created manually by a broadcaster in the Creator Dashboard, or created programmatically by the same client_id as attached to the access token can be updated.
* Only redemptions for a reward created programmatically by the same client_id as attached to the access token can be updated.
*
* @param authToken User access token for the broadcaster (scope: channel:manage:redemptions).
* @param broadcasterId The id of the target channel, which must match the token user id.
Expand Down

0 comments on commit c3764dd

Please sign in to comment.