Skip to content

AchoBot setup Full guide

Paula Santamaría edited this page Feb 13, 2022 · 4 revisions

1. Dependencies

AchoBot requires the following dependencies to run:

Follow these steps to get everything you need from Notion and Twitch.

1. Notion API Key

You'll need a Notion API key and Database ID.

  1. Go to https://developers.notion.com/my-integrations
  2. Click over "+ New integration"
  3. Fill the form with a Name. E.g: "AchoBot"
  4. Select the option "Internal integration"
  5. Under "Capabilities" select "Read content" (that's the only one AchoBot needs)
  6. Under "User capabilities" select "No user information" (AchoBot doesn't need to access to any user information).
  7. Submit the form
  8. Save the Internal Integration Token somewhere secure. You'll need to add it as an Environment variable later.

2. Notion Database

  1. Setup your Notion Database. Generate it using the following Notion template: [Template] AchoBot

Press "Duplicate" to copy the template in your Notion. The template comes with a few sample commands; feel free to delete them and add your own.

Make sure the database is generated in the same workspace as your Notion Integration.

  1. Share the integration with your database:

    1. Open your newly created AchoBot Database
    2. Click "Share"
    3. Find your integration by typing its name in the search box
    4. Press "Invite"
  2. Open the database in Notion and get the Database ID:

    1. Press "Share"
    2. Select "Copy Link"
    3. The ID is the route parameter in the URL before the ?:
    https://www.notion.so/a8aec43384f447ed84390e8e42c2e089?v=...
                          |--------- Database ID --------|
    
    1. Save the ID somewhere. You'll need to add it as an Environment variable later.

More information about Notion Integrations here: https://developers.notion.com/docs/getting-started

3. Registering a Twitch App

You can register the App using your personal Twitch account or create a new one. The latter is recommended so people in the chat know when they are talking to you or your bot.

💡 Tip: You can check an option in your personal account to enable creating additional accounts with the same verified email. This option can be found in Settings > Security and Privacy > Contact below your verified email.

  1. Go to the developer console

Twitch developer console (empty)

  1. Select "Register your Application"
  2. Fill out the form:

Twitch application form

  1. After submitting you should see the following table

The new application listed in our Twitch Developer Console

  1. Press over the "Manage" button

  2. Generate a "Client Secret" by pressing over the "New Secret" button:

Twitch application form

Take note of both the Client ID and the Client Secret. You will need them to connect your chatbot with the Twitch API.

2. Run the project

1. Get the repo

  1. Clone the repo
git clone https://github.com/pawap90/acho-bot
  1. Install dependencies: Run the following command from the project's root folder:
npm install

2. Environment variables

To run AchoBot we first need to set up all the environment variables. If you are running it locally, simply create a file in the root folder and name it .env. The file should contain the following information:

TWITCH_BOT_CLIENTID=<your-twitch-clientid>    # The Client ID we got on section 1.3
TWITCH_BOT_CLIENTSECRET=<your-twitch-secret>   # The Client Secret we got on section 1.3
TWITCH_BOT_USERNAME=<your-bots-username>   # The username of the Twitch account you created for the bot (section 1.3)
TWITCH_CHANNELS=<your-twitch-channel>   # Your Twitch channel or the channel where you want the bot to join the chat.
TMI_DEBUG=true
TMI_LOGLEVEL=info
PORT=5000   # The port where the app should run
TWITCH_BOT_REDIRECTURI=http://localhost:5000/api/twitch/auth/token    # Make sure the port matches with "PORT"
SESSION_SECRET=<a-random-value>
NOTION_APIKEY=<your-notion-api-key>    # The Notion API Key we got on section 1.1
NOTION_DATABASEID=<your-notion-database-id>    # The Notion DB ID we got on section 1.2
NOTION_VERSION=2021-08-16     # The Notion API version we are using

3. Run the bot!

After everything is set up, you can run the bot using the following commands:

npm run build

npm start

Or you can run it in development mode:

npm run dev

In the logs, you will see AchoBot trying to connect but failing. This is because we haven't logged in yet!

4. Log in to AchoBot with your bot's Twitch account

Since you are going to log in with your bot's account, I recommend doing this in a different browser (or the same browser in private mode) than the one you use to log in with your main account.

  1. While the project is running, navigate to http://localhost:5000/api/twitch/auth
  2. Login with your bot's Twitch account
  3. You will be redirected to http://localhost:5000 and you should see a green message indicating you logged in successfully.
  4. Wait a minute or so and AchoBot will automatically connect to your stream's chat

5. Test it

You don't need to be streaming to test AchoBot! Go to https://dashboard.twitch.tv/u/<your-channel>/stream-manager and start typing commands in the chat (at the bottom left corner). AchoBot should be able to respond by now!