Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Those extensions are in the current official extension repository, with automati
* [Show Feed ID](xExtension-showFeedID/README.md): Show the ID of feed and category
* [Title-Wrap](xExtension-TitleWrap/README.md): Applies a line-wrap to long article titles instead of truncating them
* [Unsafe Autologin](xExtension-UnsafeAutologin/README.md): Brings back removed unsafe autologin feature from FreshRSS
* [Webhook](xExtension-Webhook/README.md): Automatically sends webhook notifications when RSS entries match specified keywords
* [Word Highlighter](xExtension-WordHighlighter/README.md): Highlight specific words
* [YouTube Video Feed](xExtension-YouTube/README.md): Embed YouTube feeds inside article content

Expand Down
228 changes: 228 additions & 0 deletions xExtension-Webhook/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
# FreshRSS Webhook Extension

[![License: AGPL v3](https://img.shields.io/badge/License-AGPL%20v3-blue.svg)](https://www.gnu.org/licenses/agpl-3.0)
[![FreshRSS](https://img.shields.io/badge/FreshRSS-1.20.0+-green.svg)](https://freshrss.org/)

A powerful FreshRSS extension that automatically sends webhook notifications when RSS entries match configured search filters. Perfect for integrating with Discord, Slack, Telegram, or any service that supports webhooks.

## 🚀 Features

- **Automated Notifications**: Automatically sends webhooks when new RSS entries match your search filters
- **Search Filters**: FreshRSS native search filter syntax for precise matching
- **Multiple HTTP Methods**: Supports GET, POST, PUT
- **Configurable Formats**: Send data as JSON or form-encoded
- **Template System**: Customizable webhook payloads with placeholders
- **Error Handling**: Robust error handling with graceful fallbacks
- **Test Functionality**: Built-in test feature to verify webhook configuration

## 📋 Requirements

- FreshRSS 1.28.2+

## 🔧 Installation

1. Download the extension files
2. Upload the `xExtension-Webhook` folder to your FreshRSS `extensions` directory
3. Enable the extension in FreshRSS admin panel under Extensions

## ⚙️ Configuration

### Basic Setup

1. Go to **Administration** → **Extensions** → **Webhook**
2. Configure the following settings:

#### Search Filter

Use [FreshRSS search filter syntax](https://freshrss.github.io/FreshRSS/en/users/10_filter.html) to match entries. Each line is an OR condition — if any line matches, the webhook fires. Leave empty to match all entries.

```text
intitle:breaking news
intitle:security alert
#your-project-name
```

#### Webhook Settings

- **Webhook URL**: Your webhook endpoint URL
- **HTTP Method**: Choose from GET, POST, PUT, DELETE, etc.
- **Body Type**: JSON or Form-encoded
- **Headers**: Custom HTTP headers (one per line)

### Webhook Body Template

Customize the webhook payload using placeholders:

```json
{
"title": "{title}",
"feed": "{feed_name}",
"url": "{url}",
"content": "{content}",
"date": "{date}",
"timestamp": "{date_timestamp}",
"author": "{author}",
"tags": "{tags}"
}
```

#### Available Placeholders

| Placeholder | Description |
| ----------- | ----------- |
| `{title}` | Article title |
| `{url}` | Article URL |
| `{content}` | Article content (HTML) |
| `{date}` | Publication date (string) |
| `{date_timestamp}` | Publication date as Unix timestamp |
| `{author}` | Article authors |
| `{feed_name}` | Feed name |
| `{feed_url}` | Feed URL |
| `{thumbnail_url}` | Thumbnail (image) URL |
| `{tags}` | Article tags (separated by " #") |

## 🎯 Use Cases

### Discord Webhook

```json
{
"content": "New article: **{title}**",
"embeds": [{
"title": "{title}",
"url": "{url}",
"description": "{content}",
"color": 3447003,
"footer": {
"text": "{feed_name}"
}
}]
}
```

### Slack Webhook

```json
{
"text": "New article from {feed_name}",
"attachments": [{
"title": "{title}",
"title_link": "{url}",
"text": "{content}",
"color": "good"
}]
}
```

### Custom API Integration

```json
{
"event": "new_article",
"data": {
"title": "{title}",
"url": "{url}",
"feed": "{feed_name}",
"timestamp": "{date_timestamp}"
}
}
```

## 🔍 Search Filters

The extension uses [FreshRSS search filter syntax](https://freshrss.github.io/FreshRSS/en/users/10_filter.html) to match entries.
Examples:

```text
intitle:security
inurl:example.com
author:John
#breaking-news
intitle:urgent OR intitle:critical
intitle:release -intitle:beta
```

## 🛠️ Advanced Configuration

### Custom Headers

Add authentication or custom headers:

```text
Authorization: Bearer your-token-here
X-Custom-Header: custom-value
User-Agent: FreshRSS-Webhook/1.0
```

### Error Handling

- Failed webhooks are logged for debugging
- Network timeouts are handled gracefully
- Invalid configurations are validated

### Performance

- Only sends webhooks when filters match
- Efficient filter evaluation via FreshRSS core
- Minimal impact on RSS processing

## 🐛 Troubleshooting

### Common Issues

**Webhooks not sending:**
- Check that a search filter is configured (or leave empty to match all)
- Verify webhook URL is accessible
- Check the FreshRSS logs for `[Webhook]` entries

**Filter not matching:**
- Try simple filters first (e.g., `intitle:test`)
- Refer to the [FreshRSS filter documentation](https://freshrss.github.io/FreshRSS/en/users/10_filter.html) for syntax

**Authentication errors:**
- Check custom headers configuration
- Verify webhook endpoint accepts your format

### Debugging

The extension logs to the FreshRSS log file with the `[Webhook]` prefix:
- **Debug level**: filter matches, HTTP requests sent (visible in `DEVELOPMENT` environment)
- **Warning level**: errors during article processing or failed requests (always visible)

## 📝 Changelog

### Version 0.1.1

- Initial release
- Automated webhook notifications
- Pattern matching in multiple fields
- Configurable HTTP methods and formats
- Comprehensive error handling
- Template-based webhook payloads

## 🤝 Contributing

This extension was developed to address [FreshRSS Issue #1513](https://github.com/FreshRSS/FreshRSS/issues/1513).

Contributions are welcome! Please:
1. Fork the repository
2. Create a feature branch
3. Follow FreshRSS coding standards
4. Add tests for new functionality
5. Submit a pull request

## 📄 License

This extension is licensed under the [GNU Affero General Public License v3.0](LICENSE).

## 🙏 Acknowledgments

- FreshRSS development team for the excellent extension system
- Community members who requested and tested this feature
- Contributors to the original feature request

## 📞 Support

- [FreshRSS Documentation](https://freshrss.github.io/FreshRSS/)
- [GitHub Issues](https://github.com/FreshRSS/Extensions/issues)
- [FreshRSS Community](https://github.com/FreshRSS/FreshRSS/discussions)
151 changes: 151 additions & 0 deletions xExtension-Webhook/configure.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<?php
declare(strict_types=1);
/** @var WebhookExtension $this */
?>
<small><?= _t('ext.webhook.description') ?></small>
<form action="<?= _url('extension', 'configure', 'e', urlencode($this->getName())) ?>" method="post">
<input type="hidden" name="_csrf" value="<?= FreshRSS_Auth::csrfToken() ?>" />

<fieldset>
<legend><?= _t('ext.webhook.event_settings') ?> ⚙️</legend>
<details open="open">
<summary class="stick"><small><?= _t('ext.webhook.show_hide') ?></small></summary>

<div class="form-group">
<label class="group-name" for="search_filter"><?= _t('ext.webhook.search_filter') ?></label>
<div class="group-controls">
<textarea name="search_filter" id="search_filter"><?=
htmlspecialchars($this->getUserConfigurationString('search_filter') ?? '', ENT_COMPAT, 'UTF-8')
?></textarea>
<br />
<small><?= _t('ext.webhook.search_filter_description') ?></small>
</div>
</div>
</details>
</fieldset>

<fieldset>
<legend><?= _t('ext.webhook.webhook_settings') ?> 🌐</legend>
<div class="form-group">
<label class="group-name" for="webhook_url">Method / URL:</label>
<div class="group-controls">
<select id="webhook_method" name="webhook_method">
<option value="GET" <?= $this->getUserConfigurationString('webhook_method') === 'GET' ? 'selected="selected"' : '' ?>>GET</option>
<option value="POST" <?= $this->getUserConfigurationString('webhook_method') === 'POST' ? 'selected="selected"' : '' ?>>POST</option>
<option value="PUT" <?= $this->getUserConfigurationString('webhook_method') === 'PUT' ? 'selected="selected"' : '' ?>>PUT</option>
</select>
<input type="text" name="webhook_url" id="webhook_url" value="<?=
htmlspecialchars($this->getUserConfigurationString('webhook_url') ?? '', ENT_COMPAT, 'UTF-8') ?>" />
</div>
</div>

<div class="form-group">
<label class="group-name" for="webhook_body_type"><?= _t('ext.webhook.http_body_type') ?></label>
<div class="group-controls">
<select id="webhook_body_type" name="webhook_body_type" class="select-input-changer" data-name="webhook_body">
<option value="custom" data-input-visible="true" <?= $this->getUserConfigurationString('webhook_body_type') === 'custom' ? 'selected="selected"' : '' ?>><?= _t('ext.webhook.custom_body_type') ?></option>
<option value="greader" data-input-visible="false" <?= $this->getUserConfigurationString('webhook_body_type') === 'greader' ? 'selected="selected"' : '' ?>><?= _t('ext.webhook.greader_body_type') ?></option>
<option value="rss" data-input-visible="false" <?= $this->getUserConfigurationString('webhook_body_type') === 'rss' ? 'selected="selected"' : '' ?>><?= _t('ext.webhook.rss_body_type') ?></option>
</select>
</div>
</div>

<div class="form-group" id="webhook_body-block">
<label class="group-name" for="webhook_body"><?= _t('ext.webhook.http_body') ?></label>
<div class="group-controls">
<textarea name="webhook_body" id="webhook_body" class="valid-json"><?= htmlspecialchars(
json_encode($this->getUserConfigurationArray('webhook_body') ?: $this->webhook_body, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) ?: '',
ENT_COMPAT, 'UTF-8')
?></textarea>
<br />
<small><?= _t('ext.webhook.http_body_description') ?></small>

<details>
<summary><small><?= _t('ext.webhook.http_body_placeholder_summary') ?></small></summary>
<div>
<div class="content">
<table>
<tr>
<th><b><code><?= _t('ext.webhook.http_body_placeholder_title') ?></code></b></th>
<th><b><?= _t('ext.webhook.http_body_placeholder_description') ?></b></th>
</tr>
<tr>
<td><code>{title}</code></td>
<td><?= _t('ext.webhook.http_body_placeholder_title_description') ?></td>
</tr>
<tr>
<td><code>{url}</code></td>
<td><?= _t('ext.webhook.http_body_placeholder_url_description') ?></td>
</tr>
<tr>
<td><code>{content}</code></td>
<td><?= _t('ext.webhook.http_body_placeholder_content_description') ?></td>
</tr>
<tr>
<td><code>{date_published}</code></td>
<td><?= _t('ext.webhook.http_body_placeholder_date_published_description') ?></td>
</tr>
<tr>
<td><code>{date_received}</code></td>
<td><?= _t('ext.webhook.http_body_placeholder_date_received_description') ?></td>
</tr>
<tr>
<td><code>{date_modified}</code></td>
<td><?= _t('ext.webhook.http_body_placeholder_date_modified_description') ?></td>
</tr>
<tr>
<td><code>{date_user_modified}</code></td>
<td><?= _t('ext.webhook.http_body_placeholder_date_user_modified_description') ?></td>
</tr>
<tr>
<td><code>{author}</code></td>
<td><?= _t('ext.webhook.http_body_placeholder_authors_description') ?></td>
</tr>
<tr>
<td><code>{feed_name}</code></td>
<td><?= _t('ext.webhook.http_body_placeholder_feed_description') ?></td>
</tr>
<tr>
<td><code>{feed_url}</code></td>
<td><?= _t('ext.webhook.http_body_placeholder_feed_url_description') ?></td>
</tr>
<tr>
<td><code>{tags}</code></td>
<td><?= _t('ext.webhook.http_body_placeholder_tags_description') ?></td>
</tr>
</table>
</div>
</div>
</details>
</div>

<label class="group-name" for="webhook_content_type"><?= _t('ext.webhook.http_content_type') ?></label>
<div class="group-controls">
<input type="radio" id="webhook_content_type_json" name="webhook_content_type" value="json"
<?= $this->getUserConfigurationString('webhook_content_type') === 'json' ? 'checked="checked"' : '' ?> />
<label for="webhook_content_type_json" class="group"><code>JSON</code></label>

<input type="radio" id="webhook_content_type_form" name="webhook_content_type" value="form"
<?= $this->getUserConfigurationString('webhook_content_type') === 'form' ? 'checked="checked"' : '' ?> />
<label for="webhook_content_type_form" class="group"><code>x-www-form-urlencoded</code></label>
</div>
</div>

<div class="form-group">
<label class="group-name" for="webhook_headers"><?= _t('ext.webhook.webhook_headers') ?></label>
<div class="group-controls">
<textarea name="webhook_headers" id="webhook_headers"><?=
htmlspecialchars($this->getWebhookHeaders(), ENT_COMPAT, 'UTF-8')
?></textarea>
</div>
</div>
</fieldset>

<div class="form-group form-actions">
<div class="group-controls">
<button type="submit" class="btn btn-important"><?= _t('gen.action.submit') ?></button>
<button type="reset" class="btn"><?= _t('gen.action.cancel') ?></button>
<button type="menu" class="btn"><?= _t('ext.webhook.save_and_send_test_req') ?></button>
</div>
</div>
</form>
Loading