cardiparty-discord-bot/README.md

56 lines
2.3 KiB
Markdown
Raw Normal View History

2024-09-15 11:55:45 +10:00
# Discord cardiParty webhook
This is a simple webhook to push new cardiParties into the cardiParty channel.
## install
1. Create and activate [virtual env](https://docs.python.org/3/library/venv.html)
2. Install requirements: `pip install -r requirements.txt`
2024-09-15 17:20:50 +10:00
3. Set up a cronjob (see below)
2024-09-15 11:55:45 +10:00
4. Test cronjob works
5. Relax
## How it works
We run this on the newcardigan wordpress server.
2024-09-15 17:20:50 +10:00
1. With a cron job we call `get_party.sh`
2. The shell script set env values and uses the civiCRM API using `cv` to grab the details of the latest cardiParty
3. We pipe that string into `webhook.py`
4. The script checks a custom RSS feed for new parties
5. If no new party, end
6. If new party,
2024-09-15 11:55:45 +10:00
1. save the guid to `latest_post.txt` for the next round of checking
2. use the image and title from the RSS feed and the details from the cv API call
3. publish via a webhook to Discord
## env values
2024-09-15 17:20:50 +10:00
These are all set in `get_party.sh`, not in crontab. Because we need most of them in a subsequent call (either inside `cv` or in `webhook.py`) we `export` them all.
2024-09-15 11:55:45 +10:00
We need to include some secrets via environment values:
2024-09-16 09:15:26 +10:00
* **channel** is the channel ID (`DISCORD_GUILD`)
2024-09-16 09:14:20 +10:00
* **token** is the secret token for the webhook (`DISCORD_TOKEN`)
* **cardiparty_ping** is the ID of the `@cardiParty ping` role (`DISCORD_CARDIPARTY_PING`)
2024-09-15 11:55:45 +10:00
2024-09-15 17:20:50 +10:00
There are also a couple of other things we need to do:
2024-09-16 09:14:20 +10:00
* **civicrm_settings** - set `CIVICRM_SETTINGS` so that `cv` can find it
* **venv** - we need to activate the venv using `source <path/to/venv>`
2024-09-15 17:20:50 +10:00
2024-09-15 11:55:45 +10:00
## Cron job command
```sh
2024-09-15 17:20:50 +10:00
*/15 * * * * cd /home/cardigan/rss-discord-bot && ./get_party.sh
2024-09-15 11:55:45 +10:00
```
2024-09-15 17:20:50 +10:00
`get_party.sh` should pipe a string like this into `webhook.py`:
2024-09-15 11:55:45 +10:00
```
[{"id":108,"title":"Melbourne Art Library","address.city":"Melbourne","start_date":"2024-04-06 16:30:00","summary":"Melbourne Art Library (MAL) is a not-for-profit lending library that collects specialised art and design texts. They are proudly independent and are curious about what being a 'library' means."}]
```
## RSS feed
2024-09-16 09:08:29 +10:00
The rss feed is `https://newcardigan.org/category/cardiparties/?feed=featured_image_feed`.
2024-09-15 11:55:45 +10:00
2024-09-16 09:08:29 +10:00
This special `featured_image_feed` is a slightly modified RSS2 feed. The only thing it does differently is include the featured image in an `enclosure` so that we can pick it up directly from the feed. See the newcardigan WordPress theme for how this works.