Giter Club home page Giter Club logo

channel-points-node-sample's Introduction

Sample Code for Channel Points using NodeJS

This is a basic sample that aims to show how to use the new Channel Points APIs, including creating rewards, getting rewards, getting redemptions, and updating the fulfillment status of each reward.

To do so, this sample will:

  • Create a new custom reward (if it doesn't exist)
  • Poll for new redemptions
  • Follow the user as the action
  • Mark the redemption as fulfilled (or cancelled if an error happens)

This sample is in Node to show the ease of the new APIs.

Note

This example polls for redemptions, but for larger-scale production tools, you should look into using EventSub's Channel Points Webhook as it will scale more quickly than this example.

How to Use

To use this sample, you will need to do three things:

  • Get a user token with appropriate scopes
  • Set the token in a .env file
  • Install required packages

Getting a Token

The first is to install the Twitch CLI here which will enable you to generate a token quickly using the following command:

twitch token -u -s "channel:manage:redemptions user:edit:follows"

Alternatively, you can generate a token using the normal OAuth 2.0 flow as described in the Authentication Docs. The token requires two scopes:

  • channel:manage:redemptions
  • user:edit:follows

Setting the Token in an Environment File (.env)

Once you have the token, you will want to copy .env-sample into a new file .env. Once you've done so, set the TWITCH_ACCESS_TOKEN to the token generated above.

An example .env file would look like:

TWITCH_ACCESS_TOKEN=abcdef12345

The sample will call the validate endpoint to get the broadcaster and Client ID used here.

Install Required Packages

To install the required packages, you just need to run the following in the root of the project:

npm install

Running the Sample

Once you've done the above, you can run the sample.

To do so, simply run:

npm start

This will start the file.

Adjusting the File

All of the code is in the index.js file. Please feel free to update the customRewardBody variable to meet your needs.

channel-points-node-sample's People

Contributors

barrycarlyon avatar bracciata avatar lleadbet avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.