add title

This commit is contained in:
Balakrishnan Balasubramanian 2022-05-07 21:01:14 -04:00
parent 3f4be7b0ae
commit 7d8f7b58a8
4 changed files with 10 additions and 6 deletions

View File

@ -15,8 +15,7 @@
* ✓ Implement atom * ✓ Implement atom
* ✓ Cleanup * ✓ Cleanup
* Show Feed name instead of Link * Show Feed name instead of Link
* Change flags to os.Args[1] for config path * ✓ Make Rhash optional
* Make Rhash optional
## Issues ## Issues
* ✓ Last record is not written fully to csv: *Fixed*. Had to Flush writer * ✓ Last record is not written fully to csv: *Fixed*. Had to Flush writer
@ -52,6 +51,7 @@
* Filter from app based on keyword * Filter from app based on keyword
* Move telegram auth token to credential file * Move telegram auth token to credential file
* Check if context is used correctly * Check if context is used correctly
* Change flags to os.Args[1] for config path
### Log ### Log
* Log to file * Log to file

View File

@ -104,7 +104,7 @@ func ProcessFeed(feed FeedCfg, scheduler Scheduler, dbDir string, tgram telegram
Time: time.Now(), Time: time.Now(),
FeedEntry: entry, FeedEntry: entry,
} }
err := tgram.SendLink(entry.Link, feed.Channel, feed.Rhash) err := tgram.SendLink(entry.Link, feed.Channel, feed.Rhash, feed.Title)
if err != nil { if err != nil {
log.Error("failed to send to telegram", "feed", feed.Name, "link", entry.Link, "channel", feed.Channel, "rhash", feed.Rhash, "error", err) log.Error("failed to send to telegram", "feed", feed.Name, "link", entry.Link, "channel", feed.Channel, "rhash", feed.Rhash, "error", err)
r.Status = Error r.Status = Error

View File

@ -20,6 +20,7 @@ type FeedCfg struct {
Cron string `yaml:"cron"` Cron string `yaml:"cron"`
Proxy string `yaml:"proxy"` Proxy string `yaml:"proxy"`
Type parser.FeedType `yaml:"type"` Type parser.FeedType `yaml:"type"`
Title string `yaml:"title"`
FTL *int `yaml:"first_time_limit"` FTL *int `yaml:"first_time_limit"`
FirstTimeLimit FeedLimit `yaml:"-"` FirstTimeLimit FeedLimit `yaml:"-"`
} }

View File

@ -16,7 +16,7 @@ import (
) )
type TelegramSender interface { type TelegramSender interface {
SendLink(link, channel, rhash string) error SendLink(link, channel, rhash, title string) error
} }
type telegramSender struct { type telegramSender struct {
@ -26,14 +26,17 @@ type telegramSender struct {
rateLimiterPerSec *rate.Limiter rateLimiterPerSec *rate.Limiter
} }
func (ts *telegramSender) SendLink(link string, channel string, rhash string) error { func (ts *telegramSender) SendLink(link, channel, rhash, title string) error {
if title == "" {
title = "Link"
}
msg := struct { msg := struct {
ChatID string `json:"chat_id"` ChatID string `json:"chat_id"`
Text string `json:"text"` Text string `json:"text"`
ParseMode string `json:"parse_mode"` ParseMode string `json:"parse_mode"`
}{ }{
ChatID: channel, ChatID: channel,
Text: fmt.Sprintf(`<a href="%s">➢</a> <a href="%s">Link</a>`, genIVLink(link, rhash), link), Text: fmt.Sprintf(`<a href="%s">➢</a> <a href="%s">%s</a>`, genIVLink(link, rhash), link, title),
ParseMode: "HTML", ParseMode: "HTML",
} }
data, err := json.Marshal(msg) data, err := json.Marshal(msg)