NightDev Community Forums

Nightbot Alerts In Chat

Intro

Are you wondering how to set up Nightbot to automatically welcome your new followers, notify you of any channels hosting you, tip you off about recent donations, or announce new subscribers to your chat? And are you too lazy to set up another bot that probably already has these functions built in? Well today is your lucky day because this is possible to do with the use of Streamlabs! Setting up in-chat alerts for Nightbot will take some work on your part, but I am sure you will not mind if you are really committed to doing this.


Part 1: Hitting up the Nightbot API

Prepare to read a bunch of technical mumbo jumbo. Before you mess around with Streamlabs, you have to create a Nightbot application and use that application to obtain an access token from the Nightbot API. This access token will allow Streamlabs to make further requests to the Nightbot API to make Nightbot post messages in your chat on Streamlabs’ behalf.

Setting up a Nightbot App

Go to your list of Nightbot applications and create a new app. You can pick any app name. You do not need a redirect URI. Click “Submit”. Click the app’s edit button on the right-hand side of the page. Take note of the client ID. Click “New Secret” to obtain a client secret.

Copy down your client ID and secret and keep them someplace safe, especially your client secret!

Obtaining an Access and Refresh Token

Open the command prompt. For Windows users, open the Run window by pressing Windows+R. Type cmd into the dialogue and hit enter. Once the command prompt is open, copy and paste the following cURL command into the prompt:

curl -X POST "https://api.nightbot.tv/oauth2/token" -d "client_id=CLIENT_ID&client_secret=CLIENT_SECRET&grant_type=client_credentials&scope=channel_send"

Replace CLIENT_ID with your client ID and CLIENT_SECRET with your client secret, then hit enter. You should get a response similar to the following:

{"access_token":"ACCESS_TOKEN","token_type":"bearer","expires_in":2592000,"refresh_token":"REFRESH_TOKEN","scope":"channel_send"}

ACCESS_TOKEN is your access token and REFRESH_TOKEN is your refresh token.

Copy down these tokens and keep them someplace safe as well.

Obtaining New Tokens

Your access token will last 30 days and your refresh token will last 60 days. After your access token expires but before your refresh token expires, open the command prompt, then copy and paste the following cURL command into the prompt:

curl -X POST "https://api.nightbot.tv/oauth2/token" -d "client_id=CLIENT_ID&client_secret=CLIENT_SECRET&grant_type=refresh_token&refresh_token=REFRESH_TOKEN"

Replace CLIENT_ID with your client ID, CLIENT_SECRET with your client secret, and REFRESH_TOKEN with your refresh token, then hit enter. You should get a response similar to the following:

{"access_token":"NEW_ACCESS_TOKEN","token_type":"bearer","expires_in":2592000,"refresh_token":"NEW_REFRESH_TOKEN","scope":"channel_send"}

NEW_ACCESS_TOKEN is your new access token and NEW_REFRESH_TOKEN is your new refresh token. Copy down the new access token and refresh token.

Copy down the new tokens and keep them someplace safe, just like the previous pair of tokens.

Part 2: Configuring Streamlabs Alerts

Sign up for Streamlabs if you have not done so already! Go to the Streamlabs website here and log in using your Twitch or YouTube account.

Alert Box Widget

Go to your Streamlabs alert box widget editor. In your general settings, set the alert delay to at least 5 seconds. Navigate to the settings of the specific type of alert you want to set up (follows, subscriptions, donations, hosts, etc).

I will set up follower alerts as an example. Navigate to the follow alerts menu. At the bottom of the menu, enable custom HTML/CSS. This will open up a custom script editor below. Navigate to the JS script editor, then copy and paste the following AJAX script.

$.ajax({
    url: "https://api.nightbot.tv/1/channel/send",
    method: "POST",
    headers: {
        "Authorization":"Bearer ACCESS_TOKEN",
    },
    data: "message={name} is now following!"
});

Replace ACCESS_TOKEN with your access token. Go to the bottom of the menu and save your settings.

Remember that your access token will expire in 30 days. This means that every 30 days you will have to open the script editor and replace the access token with a new token (see part 1 above for obtaining new access tokens).

Now you are done! The last step to make your alerts work is to go to the top of the alert box menu and copy the widget URL, then either:

  • Run the widget URL in any browser tab and keep that tab open throughout your stream.

  • Add a browser source in your streaming software using the widget URL. The alerts will then work as long as you keep your streaming software open. If you stream using OBS or XSplit, read this guide on how to add browser sources.

Further Customizing Your Alerts

I gave an example above for setting up follower alerts, but what if you want to set up donation alerts that announce how much money is being donated or set up raid alerts that tell you how many viewers are about to come to your chat to spam “#raidHYPE”?

See this line of code in the AJAX script above?

data: "message={name} is now following!"

You can see that whatever comes after message= is what is being sent to the Nightbot API for Nightbot to post in your chat. You should especially notice that the variable {name} represents the username of the new follower.

You may, of course, tweak this message to your liking, and it may help to know how to make your alerts more dynamic by including variables that contain information such as follower usernames, donation amounts, bits amounts, number of raiders, etc. Therefore I will list each type of alert you can set up below along with the variables that you can include for each alert type.

  • Follows:
    {name} - new follower username
  • Subscriptions:
    {name} - subscriber username
  • Donations:
    {name} - donator username
    {amount} - amount of money donated
  • Hosts:
    {name} - host username
    {count} - number of viewers watching from the host’s channel
  • Bits:
    {name} - donator username
    {amount} - amount of bits donated
  • Raids:
    {name} - raiding streamer usernmae
    {count} - number of raiding viewers
  • Merch:
    {name} - buyer username
    {product} - product name
  • Cloudbot Redemption:
    {name} - buyer username
    {product} - product name

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