Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tag1consulting/tag1bot
A toy Slack bot.
https://github.com/tag1consulting/tag1bot
bot rust slack
Last synced: 6 days ago
JSON representation
A toy Slack bot.
- Host: GitHub
- URL: https://github.com/tag1consulting/tag1bot
- Owner: tag1consulting
- License: apache-2.0
- Created: 2022-06-02T06:55:00.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-01-21T12:21:49.000Z (20 days ago)
- Last Synced: 2025-01-21T12:26:46.663Z (20 days ago)
- Topics: bot, rust, slack
- Language: Rust
- Homepage:
- Size: 176 KB
- Stars: 6
- Watchers: 22
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Tag1bot
Porting parts of https://www.drupal.org/project/bot into a Rust-powered slackbot.
Why "Tag1bot"? Because we created this for Tag1's internal Slack server, but then released it as open source feeling it's likely other people also missed the wonderful Drupal irc bot!
## Karma
The bot increases karma for `foo++`-style commands, and decreases karma for `foo--`-style commands. Karma is the total number of times a given word has been incremented or decremented. Words must be 2 to 20 characters long, without any spaces. (Word can optionally start with `@` or `#`.)
## Seen
The bot records the last message per user posted to any public channel it is in, and responds to `seen foo?` with the details.
## Convert
The bot recognizes "convert # FOO to BAR" style requests. For example, `convert 1 BTC to USD` or `convert 100 USD to EUR`.
The bot also recognizes "alert me when # FOO is [greater|less] # bar" style requests. For example `alert me when 1 USD is greater than .95 EUR`, or `alert when BTC is less than 20000 USD`. Alerts will be delivered in the channel the alert was configured in.
The convert features require that you set up an account on https://www.xe.com/xecurrencydata/ and configure the `XE_ACCOUNT_ID` and `XE_API_KEY` environment variables when starting the bot.
## ChatGPT
The bot recognizes any message starting with "chatgpt" as a message to send to the ChatGPT API. For example, "chatgpt why is the rust programming language so popular?".
The chatgpt feature requires that you have an OpenAI ChatGPT API key and configure the `CHATGPT_API_KEY` environment variable when starting the bot.
# How To Use
First, register a new bot in your workspace by clicking `Create New App` at https://api.slack.com/apps. Create from scratch. You can name your bot whatever you want, `Tag1bot`, `Sea Cow`, `Druplicon`, whatever you prefer!
Next, clone the `tag1bot` repo:
```bash
git clone [email protected]:tag1consulting/tag1bot.git
```Next, find your secrets:
- `SLACK_APP_TOKEN` -- go to `Basic Information` in your newly created app, and `Generate Token and Scopes`, starting with `connections:write`. You need the token that starts with `xapp-`.
- `SLACK_BOT_TOKEN` -- go to `OAuth & Permissions` and grab the `User OAuth token` that starts with `xoxp-`. Also scroll down to `Bot Token Scopes` and grant the following:
- `app_mentions:read`
- `channels:history`
- `channels:write`
- `chat:write`
- `groups:history`
- `groups:read`
- `im:history`
- `im:read`
- `mpim:history`
- `users:read`
- `users:write`
- `SLACK_CHANNEL_ID` -- pick the main home for your bot, for example `general`Finally, start your app setting the above secrets in your environment in the most secure way you know. With all these secrets set, you should be able to start the bot with `cargo run --release`, for example:
```bash
SLACK_APP_TOKEN=xapp-... \
SLACK_BOT_TOKEN=xoxb-... \
SLACK_CHANNEL_ID=general \
RUST_LOG=warn \
cargo run --release
```The bot will create an sqlite database called `state.sqlite` which stores all state. If you delete this file, the bot will forget all recorded karma, the last time it's seen users, and so on.
## Why didn't you port my favorite bot feature?
PR's welcome!! https://github.com/tag1consulting/tag1bot/pulls