Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation for setting up a token #201

Merged
merged 4 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class NightscoutCommand(category: Category) : DiscordCommand(category, null) {
this.guildOnly = false
this.aliases = arrayOf("ns", "bg", "bs")
this.examples = arrayOf(
"diabot nightscout casscout", "diabot ns", "diabot ns set https://casscout.herokuapp.com",
"diabot nightscout casscout", "diabot ns", "diabot ns set https://casscout.herokuapp.com",
"diabot ns @SomeUser#1234", "diabot ns public false"
)
this.children = arrayOf(
Expand Down Expand Up @@ -446,7 +446,7 @@ class NightscoutCommand(category: Category) : DiscordCommand(category, null) {
}
}

is UnconfiguredNightscoutException -> "Please set your Nightscout hostname using `diabot nightscout set <hostname>`"
is UnconfiguredNightscoutException -> "Please set your Nightscout hostname using `/nightscout set url <hostname>`"
is IllegalArgumentException -> "Error: ${ex.message}"
is InsufficientPermissionException -> {
logger.info("Couldn't reply with nightscout data due to missing permission: ${ex.permission}")
Expand Down Expand Up @@ -492,7 +492,8 @@ class NightscoutCommand(category: Category) : DiscordCommand(category, null) {
is HttpException -> {
if (ex.code() == 401) {
message += if (userDTO.jdaUser != null && userDTO.jdaUser == author) {
"Could not authenticate to Nightscout. Please set an authentication token with `diabot nightscout token <token>`"
"Could not authenticate to Nightscout. Please set an authentication token with `/nightscout set token <token>`, " +
"or view our [setup guide](https://github.com/discord-diabetes/diabot/blob/main/docs/nightscout_setup.md)."
} else {
"Nightscout data is unreadable due to missing token."
}
Expand Down
Binary file added docs/images/token/step_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/token/step_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/token/step_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/token/step_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/token/step_5-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/token/step_5-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions docs/nightscout_setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Nightscout tokens and Diabot

If your Nightscout instance is running
in [token authentication mode](https://nightscout.github.io/nightscout/security/#how-to-turn-off-unauthorized-access), and you want to use
the Nightscout features of the bot, you'll need to set an access token so Diabot access and read your Nightscout data.
You can read more about creating a token [here](https://nightscout.github.io/nightscout/security/#create-authentication-tokens-for-users)

## Quick Guide

1. Starting at your Nightscout page, click the 3 horizontal lines in top right -> "Admin Tools"
2. Click "Add new Subject". Put anything for name (e.g. `diabot`) and put `readable` for roles. Click "Save" in the bottom left.
3. In the "Access Token" column, right-click on the diabot token you just created and copy the link.
4. In Discord, type `/nightscout set url` and click on the command that appears above the chat box. Paste the link you just copied into
the `url` input field for that command. Send the command.
5. Run `diabot ns` in the chat to confirm it's working.

## Regular Guide

1. Open your Nightscout page. In the top right, click on the 3 horizontal lines, and click "Admin Tools"

![Picture showing the location of the admin tools link](./images/token/step_1.png?raw=true)

2. Once in the admin tools page, click "Add new Subject" which will open a menu.

![Picture of the "Add new Subject" button](./images/token/step_2.png?raw=true)

3. You can put anything for the name, but in this example we'll use `diabot`. For the roles, put in `readable`. Once you've confirmed the
values look correct, click "Save" in the bottom-left of the menu.

![Picture showing an example of how the subject fields should look](./images/token/step_3.png?raw=true)

4. After saving it, the new Diabot subject should appear in the table. You can see the new token under the "Access Token" column; it'll
appear as a link to your Nightscout with the token filled in. Right-click on the token link and copy it to your clipboard.

![Picture of the access token link](./images/token/step_4.png?raw=true)

5. Go over to Discord. Make sure you're in a server with Diabot in it. In the chat box, type `/nightscout set url` and click on the command
that appears above the chat box. Your cursor should be in a command option/field box now. Paste the link we copied in step 4 into the
box.

![Picture of the command to select](./images/token/step_5-1.png?raw=true)
![Picture of the command with the URL option filled out](./images/token/step_5-2.png?raw=true)

6. Once you have the link in the command field as shown above, send the command by hitting enter or clicking on the send button. Diabot
should update your URL and you can now test to make sure it works by running `diabot ns`.
Loading