@agentdao/core
Version:
Core functionality, skills, and ready-made UI components for AgentDAO - Web3 subscriptions, content generation, social media, help support, live chat, RSS fetching, web search, and agent pricing integration
54 lines (53 loc) • 2.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RssFetcherSkill = void 0;
const Parser = require('rss-parser');
class RssFetcherSkill {
constructor(config = {}) {
this.parser = new Parser();
}
async fetchFeed(url, options) {
let feeds = [];
if (options?.urls && Array.isArray(options.urls) && options.urls.length > 0) {
// Multi-feed aggregation
const allFeeds = await Promise.all(options.urls.map(u => this.parser.parseURL(u)));
feeds = allFeeds.flatMap(feed => feed.items.map((item) => ({ ...item, _feedUrl: feed.link })));
}
else {
const feed = await this.parser.parseURL(url);
feeds = feed.items;
}
// Filtering
if (options?.keyword) {
feeds = feeds.filter((item) => (item.title || '').toLowerCase().includes(options.keyword.toLowerCase()) ||
(item.content || '').toLowerCase().includes(options.keyword.toLowerCase()));
}
if (options?.after) {
const afterDate = new Date(options.after);
feeds = feeds.filter((item) => new Date(item.pubDate || '') > afterDate);
}
if (options?.limit) {
feeds = feeds.slice(0, options.limit);
}
// Custom fields
if (options?.fields && Array.isArray(options.fields) && options.fields.length > 0) {
feeds = feeds.map((item) => {
const filtered = {};
options.fields.forEach(f => { filtered[f] = item[f]; });
return filtered;
});
}
// Summarization (stub)
if (options?.summarize) {
// TODO: Integrate with AI summarizer
feeds = feeds.map((item) => ({ ...item, summary: '[Summary not implemented]' }));
}
// Enrichment (stub)
if (options?.enrich) {
// TODO: Fetch article and extract metadata
feeds = feeds.map((item) => ({ ...item, enriched: '[Enrichment not implemented]' }));
}
return feeds;
}
}
exports.RssFetcherSkill = RssFetcherSkill;