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.

For Twitch streamers:

  • 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 username
    {count} - number of raiding viewers
  • Merch:
    {name} - buyer username
    {product} - product name
  • Cloudbot Redemption:
    {name} - buyer username
    {product} - product name
  • Streamlabs Prime Gift:
    {name} - gifter username
    {giftType} - gift type
    {streamer} - gift recipient

For YouTube streamers:

  • Subscribers:
    {name} - new subscriber username
  • Members:
    {name} - new member username
  • Donations:
    {name} - donator username
    {amount} - amount of money donated
  • Super Chats:
    {name} - donator username
    {amount} - amount of money donated
  • Merch:
    {name} - buyer username
    {product} - product name
  • Cloudbot Redemption:
    {name} - buyer username
    {product} - product name
  • Streamlabs Prime Gift:
    {name} - gifter username
    {giftType} - gift type
    {streamer} - gift recipient
2 Likes

hi i input the correct data in relevant fields

I run CMD in administrator mode, but I get this response
curl: (35) schannel: next InitializeSecurityContext failed: Unknown error (0x80092012) - The revocation function was unable to check revocation for the certificate.

Hey @gothguy666!

Iā€™d suggest trying again, and making sure you use the right client ID and secret, because I have no issue getting my tokens.

Thereā€™s only one secret and client ID.

I have no problem getting my tokens, so you shouldnā€™t either.
As long as we canā€™t reproduce the issue, we canā€™t fix it, and so we assume itā€™s on your side.

judging by the tone of message, I assume Ive annoyed you simply by typing.
Dont worry about it.

Request another client secret and try again with that new one.
If it still doesnā€™t work, delete the current application and try with a new one.

so how do I get it so that I have both nightbot in chat and alertbox on stream at the same time is that possilble?

Hey @mkshifty06!

Yes, just set up the visual alerts on Streamlabs, and follow the guide here for Nightbot.

Hi, I was wondering if I could lower the chat delay on nightbot? everything is working fine, it seems when there are two or more notifications back to back, it bottles up Nightbot and some follows/subs/donations chat alerts are missed by nightbot. Any way to fix that?

I think when you test it, it doesnā€™t follow the ā€œalert delayā€ setting in the general settings. I set it to 6 seconds, so that will delay the alert to go off long enough for nightbot to catch up. Iā€™m assuming that would be the fix?

Hey @zidakara!

Yes, that should do the job, although Iā€™m not entirely sure as if an event happens at T0 and another at T1, both would be delayed by 6 seconds so messages would be sent at T6 and T7.

Nightbot limits the amount of messages it sends because Twitch limits it, and if it goes over the limit, then the bot is kicked out of Twitchā€™s server for at least 30 minutes, which would be disruptive to otherā€™s service as well as yours, you donā€™t want that.

Something else that could help thoā€™, is to make sure Nightbot is a moderator.