UNPKG

3.66 kBMarkdownView Raw
1# Hubot Fitbit Leaders
2
3[![npm version](https://badge.fury.io/js/hubot-fitbit-leaders.svg)](http://badge.fury.io/js/hubot-fitbit-leaders) [![Node CI](https://github.com/stephenyeargin/hubot-fitbit-leaders/actions/workflows/nodejs.yml/badge.svg)](https://github.com/stephenyeargin/hubot-fitbit-leaders/actions/workflows/nodejs.yml)
4
5This script is designed to be used with a [Hubot](http://hubot.github.com) to compare the Fitbit activity of your friends.
6
7## Adding to Your Hubot
8
9See full instructions [here](https://github.com/github/hubot/blob/master/docs/scripting.md#npm-packages).
10
111. `npm install hubot-fitbit-leaders --save` (updates your `package.json` file)
122. Open the `external-scripts.json` file in the root directory (you may need to create this file) and add an entry to the array (e.g. `[ 'hubot-fitbit-leaders' ]`).
13
14## Commands
15
16- `hubot fitbit setup` - Run through the setup process for the bot (for admins)
17- `hubot fitbit leaders` - Show table of leaders
18- `hubot fitbit register` - Show how to friend the bot
19- `hubot fitbit approve` - Approve all pending requests
20
21## Upgrading from 1.0.x?
22
23You will need to update your `FITBIT_CLIENT_ID` and generate a new `FITBIT_OAUTH_TOKEN` using the steps below. You no longer need the `FITBIT_OAUTH_TOKEN_SECRET` configuration variable. Note that you will have to go through this process at least once a year (the Implicit grant type token is time-limited.)
24
25## Configuration
26
27| Environment Variable | Description |
28| -----------------------| ------------------------------------------------|
29| `FITBIT_CLIENT_ID` | Obtained from the app registration. |
30| `FITBIT_CLIENT_SECRET` | Obtained from the app registration. |
31| `FITBIT_REDIRECT_URL` | Redirect URL, must mach app registration. |
32| `FITBIT_OAUTH_TOKEN` | Found in the callback response, lasts one year. |
33
34Register the three values as environment variables when starting your bot (as usual with Hubot scripts) using `export` or `heroku config:set` or whatever applies to your Hubot hosting environment.
35
36## Suggested Setup
37
38* Decide whether you want to use a user account or create a "robot" account to use with Fitbit
39* Go to the [Fitbit Developer App Registration Page](https://dev.fitbit.com/apps/new) and register an application
40 * The "Callback URL" field can be any running public web server. I prefer to use a [RunScope](https://runscope.com) bucket.
41 * The "OAuth 2.0 Application Type: is "Client"
42 * The application will need "Read & Write" access (for friend requests)
43* Note the Client ID and Client Secret. Go ahead and add those to your configuration file and restart Hubot.
44* Run the Fitbit setup command, e.g. `hubot fitbit setup`
45* A URL will be displayed that contains your configured Client ID, but is missing the registered callback URL. Plug that in, then go through the authorization steps.
46* Upon a successful authorization, the URL will appear in your browser containing your access token. It's very long, so make sure you grab everything between the `=` and the next `&`. Place these values into your configuration and restart Hubot.
47* If all went well, type `hubot register` and see if you receive a response.
48
49## Troubleshooting
50
51- Remember that the token expires after a year, so be prepared to go through these steps at least that often (replacing the Access Token).
52- Double check your saved configuration to make sure it matches the values displayed in the Fitbit application.
53- The callback step is a bit tricky. The few times I've run it, I ended up with a server error, but was still able to retrieve the Access Token from the URL.