https://github.com/rivques/bag-store-template
A template repo for a store bot using Slack and @hackclub/bag.
https://github.com/rivques/bag-store-template
Last synced: 3 months ago
JSON representation
A template repo for a store bot using Slack and @hackclub/bag.
- Host: GitHub
- URL: https://github.com/rivques/bag-store-template
- Owner: rivques
- License: mit
- Created: 2024-07-05T14:33:15.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-07-05T22:05:47.000Z (12 months ago)
- Last Synced: 2025-01-22T06:47:44.525Z (5 months ago)
- Language: TypeScript
- Size: 45.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bag-store-template
A template repo for a store bot using Slack and @hackclub/bag.
## Tutorial
# How to run your own store bot
Hi! This will teach you how to set up your own Bag store. We'll host it on Nest, Hack Club's program for free compute for teens.
## Prerequisites
* A [Nest]() account. Follow the [Quickstart](https://guides.hackclub.app/index.php/Quickstart) to get an account if you don't have one already.
* An editor. I reccomend VS Code with the Remote SSH extension, but you could use something like `nano` or `vim` if you're more hardcore than me.
## Sign into your Nest account
(if you're not using VS Code, connection to Nest is beyond the scope of this guide. I trust you.)Open VS Code, install the Remote SSH extenson and click the blue >< symbol in the bottom left corner. Click "Connect current window to host," then "Add new SSH host." Enter `ssh [email protected]`, replacing NESTUSERNAME with your Nest username. Hit enter, then enter again, then click "connect" in the notification in the bottom-right corner. A new window will open. Select "Linux" on the prompt, then "Continue". You should now find yourself logged into Nest.
## Template and clone this repository
Head to https://github.com/rivques/bag-store-template (if you're not already here). Click "Use this template" in the top right, then "Create a new repository." Change "repository name" to whatever you'd like the name of your NPC to be, and hit "Create repository." Once your repository is created, hit the big green "Code" button, then copy the url. Head back into VS Code and hit ``Ctrl+``` (that's the backtick) to bring up a terminal. Type `git clone URL`, replacing URL with what you just copied, and hit enter. Finally, open the folder from VS Code by heading to `File->Open Folder`, then selecting the repository you just cloned.
## Install dependencies
In the terminal, type `npm i` and hit enter.
## Create config.json
Copy the `config.json.example` file on the left sidebar and rename it to `config.json`. This is where all of your API keys will go, as well as settings like what you'll be selling. We'll fill it up over the next few steps.
## Set up Slack app
First, we need to get ourselves a Slack app. Head to the [Your Slack Apps](https://api.slack.com/apps) page and hit "Create New App," then "From App Manifest." Pick Hack Club as the workspace, then paste the contents of `slack_maifest.json` into the window. Change `YOUR BOT NAME` to whatever your bot is called and hit Next, then Create. Click the big green Install to Workspace button and install it into Hack Club. Once you're back on the Basic Information page, scroll down to App Tokens and hit Generate Token and Scopes. Name the token Socket Mode and give it the `connections:write`. Hit the Generate button and then copy the resulting token. Paste it in SLACK_APP_TOKEN in `config.json`. Next, head to the OAuth and Permissions section of the app settings and copy your bot user token. Paste it in SLACK_BOT_TOKEN. Finally, open up Slack, click on your profile picture in the bottom left corner, and hit Profile. Click the 3 vertical dots in your profile, then Copy Member ID. Paste this in the "YOUR_USER_ID" section of `config.json`.
## Set up Bag app
Next, we need to register an app with Bag. Head to the Slack and run /bot somewhere. Enter your bot's name, then choose "public" and "read," and hit "create."Bag should immediately DM you an app ID and app token. Put the app ID in your `config.json` file next to `"BAG_APP_ID": `. Put the app token in to `BAG_APP_KEY`, replacing the example key. While you're in the Slack, click on your profile picture in the bottom left, then click "profile." Select the three vertical dots in the menu that pops up, then pick "Copy member ID." Paste this next to `YOUR_USER_ID` in the `config.json` file.
## Choose your character
Now, you can make this bot your own. Tweak the `greetingText` to sound like your shopkeeper. Change `itemsToSell` to fit what you want to sell. Note: This will pull out of your inventory, so don't stock something you don't want to sell! Also, the `id`s in `itemsToSell` are the actual internal Bag item ids, which means they're usually capitalized, spaced words like `Fancy Pants` or `Pickaxe`. If you're getting item not found errors, make sure you've done that (and also feel free to ask in the Slack if you need help).
## Test it
Now, it's time to start your bot. In the terminal, run `npm start`. Head to #market and give your bot a mention (add it to the channel if prompted, then ping it again), and make sure it works.
## Set up to run forever
Open bag-store.service. Replace where it says YOUR_DIRECTORY_HERE with the directory you're working in. (it'll probably look something like `/home/yournestusername/yourrepositoryname`.) Then, run the following in the terminal, one by one:
```
cp bag-store.service ~/.config/systemd/user/bag-store.service
systemctl daemon-reload
systemctl --user enable bag-store
systemctl --user start bag-store
```
This should start the bot for good.