56 lines
2.3 KiB
Markdown
56 lines
2.3 KiB
Markdown
# 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`
|
|
3. Set up a cronjob (see below)
|
|
4. Test cronjob works
|
|
5. Relax
|
|
|
|
## How it works
|
|
|
|
We run this on the newcardigan wordpress server.
|
|
|
|
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,
|
|
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
|
|
|
|
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.
|
|
|
|
We need to include some secrets via environment values:
|
|
|
|
* **channel** is the channel ID (`DISCORD_CHANNEL`)
|
|
* **token** is the secret token for the webhook (`DISCORD_TOKEN`)
|
|
* **cardiparty_ping** is the ID of the `@cardiParty ping` role (`DISCORD_CARDIPARTY_PING`)
|
|
|
|
There are also a couple of other things we need to do:
|
|
* **civicrm_settings** - set `CIVICRM_SETTINGS` so that `cv` can find it
|
|
* **venv** - we need to activate the venv using `source <path/to/venv>`
|
|
|
|
## Cron job command
|
|
|
|
```sh
|
|
*/15 * * * * cd /home/cardigan/rss-discord-bot && ./get_party.sh
|
|
```
|
|
`get_party.sh` should pipe a string like this into `webhook.py`:
|
|
|
|
```
|
|
[{"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
|
|
|
|
The rss feed is `https://newcardigan.org/category/cardiparties/?feed=featured_image_feed`.
|
|
|
|
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. |