Skip to content

Commit

Permalink
integration/telegram: add possibility to disable buttons
Browse files Browse the repository at this point in the history
Closes #2093
  • Loading branch information
janydoe committed Sep 21, 2023
1 parent 59c003b commit 8e593f0
Show file tree
Hide file tree
Showing 26 changed files with 85 additions and 44 deletions.
7 changes: 7 additions & 0 deletions internal/database/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -776,4 +776,11 @@ var migrations = []func(tx *sql.Tx) error{
_, err = tx.Exec(sql)
return err
},
func(tx *sql.Tx) (err error) {
sql := `
ALTER TABLE integrations ADD COLUMN telegram_bot_disable_buttons bool default 'f';
`
_, err = tx.Exec(sql)
return err
},
}
1 change: 1 addition & 0 deletions internal/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ func PushEntries(feed *model.Feed, entries model.Entries, userIntegrations *mode
userIntegrations.TelegramBotTopicID,
userIntegrations.TelegramBotDisableWebPagePreview,
userIntegrations.TelegramBotDisableNotification,
userIntegrations.TelegramBotDisableButtons,
); err != nil {
logger.Error("[Integration] %v", err)
}
Expand Down
22 changes: 12 additions & 10 deletions internal/integration/telegrambot/telegrambot.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"miniflux.app/v2/internal/model"
)

func PushEntry(feed *model.Feed, entry *model.Entry, botToken, chatID string, topicID *int64, disableWebPagePreview, disableNotification bool) error {
func PushEntry(feed *model.Feed, entry *model.Entry, botToken, chatID string, topicID *int64, disableWebPagePreview, disableNotification bool, buttonsIsDisabled bool) error {
textTemplate := `<b><a href=%q>%s</a></b> - <a href=%q>%s</a>`
formattedText := fmt.Sprintf(
textTemplate,
Expand All @@ -31,18 +31,20 @@ func PushEntry(feed *model.Feed, entry *model.Entry, botToken, chatID string, to
message.MessageThreadID = *topicID
}

var markupRow []*InlineKeyboardButton
if !buttonsIsDisabled {
var markupRow []*InlineKeyboardButton

minifluxURLButton := InlineKeyboardButton{Text: "Go to article", URL: entry.URL}
markupRow = append(markupRow, &minifluxURLButton)
minifluxURLButton := InlineKeyboardButton{Text: "Go to article", URL: entry.URL}
markupRow = append(markupRow, &minifluxURLButton)

if entry.CommentsURL != "" {
commentButton := InlineKeyboardButton{Text: "Comments", URL: entry.CommentsURL}
markupRow = append(markupRow, &commentButton)
}
if entry.CommentsURL != "" {
commentButton := InlineKeyboardButton{Text: "Comments", URL: entry.CommentsURL}
markupRow = append(markupRow, &commentButton)
}

message.ReplyMarkup = &InlineKeyboard{}
message.ReplyMarkup.InlineKeyboard = append(message.ReplyMarkup.InlineKeyboard, markupRow)
message.ReplyMarkup = &InlineKeyboard{}
message.ReplyMarkup.InlineKeyboard = append(message.ReplyMarkup.InlineKeyboard, markupRow)
}

client := NewClient(botToken, chatID)
_, err := client.SendMessage(message)
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@
"form.integration.telegram_topic_id": "Topic ID",
"form.integration.telegram_bot_disable_web_page_preview": "Disable web page preview",
"form.integration.telegram_bot_disable_notification": "Disable notification",
"form.integration.telegram_bot_disable_buttons": "Disable buttons",
"form.integration.linkding_activate": "Artikel in Linkding speichern",
"form.integration.linkding_endpoint": "Linkding API-Endpunkt",
"form.integration.linkding_api_key": "Linkding API-Schlüssel",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/el_EL.json
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@
"form.integration.telegram_topic_id": "Topic ID",
"form.integration.telegram_bot_disable_web_page_preview": "Disable web page preview",
"form.integration.telegram_bot_disable_notification": "Disable notification",
"form.integration.telegram_bot_disable_buttons": "Disable buttons",
"form.integration.linkding_activate": "Αποθήκευση άρθρων στο Linkding",
"form.integration.linkding_endpoint": "Τελικό σημείο Linkding API",
"form.integration.linkding_api_key": "Κλειδί API Linkding",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@
"form.integration.telegram_topic_id": "Topic ID",
"form.integration.telegram_bot_disable_web_page_preview": "Disable web page preview",
"form.integration.telegram_bot_disable_notification": "Disable notification",
"form.integration.telegram_bot_disable_buttons": "Disable buttons",
"form.integration.linkding_activate": "Save entries to Linkding",
"form.integration.linkding_endpoint": "Linkding API Endpoint",
"form.integration.linkding_api_key": "Linkding API key",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/es_ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@
"form.integration.telegram_topic_id": "Topic ID",
"form.integration.telegram_bot_disable_web_page_preview": "Disable web page preview",
"form.integration.telegram_bot_disable_notification": "Disable notification",
"form.integration.telegram_bot_disable_buttons": "Disable buttons",
"form.integration.linkding_activate": "Enviar artículos a Linkding",
"form.integration.linkding_endpoint": "Acceso API de Linkding",
"form.integration.linkding_api_key": "Clave de API de Linkding",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/fi_FI.json
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@
"form.integration.telegram_topic_id": "Topic ID",
"form.integration.telegram_bot_disable_web_page_preview": "Disable web page preview",
"form.integration.telegram_bot_disable_notification": "Disable notification",
"form.integration.telegram_bot_disable_buttons": "Disable buttons",
"form.integration.linkding_activate": "Tallenna artikkelit Linkkiin",
"form.integration.linkding_endpoint": "Linkding API-päätepiste",
"form.integration.linkding_api_key": "Linkding API-avain",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/fr_FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@
"form.integration.telegram_topic_id": "Identifiant du sujet (Topic ID)",
"form.integration.telegram_bot_disable_web_page_preview": "Désactiver l'aperçu de la page Web",
"form.integration.telegram_bot_disable_notification": "Désactiver les notifications",
"form.integration.telegram_bot_disable_buttons": "Disable buttons",
"form.integration.linkding_activate": "Sauvegarder les articles vers Linkding",
"form.integration.linkding_endpoint": "URL de l'API de Linkding",
"form.integration.linkding_api_key": "Clé d'API de Linkding",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/hi_IN.json
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@
"form.integration.telegram_topic_id": "Topic ID",
"form.integration.telegram_bot_disable_web_page_preview": "Disable web page preview",
"form.integration.telegram_bot_disable_notification": "Disable notification",
"form.integration.telegram_bot_disable_buttons": "Disable buttons",
"form.integration.linkding_activate": "लिंक्डिन में विषयवस्तु सहेजें",
"form.integration.linkding_endpoint": "लिंकिंग एपीआई समापन बिंदु",
"form.integration.linkding_api_key": "लिंकिंग एपीआई कुंजी",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/id_ID.json
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@
"form.integration.telegram_topic_id": "Topic ID",
"form.integration.telegram_bot_disable_web_page_preview": "Disable web page preview",
"form.integration.telegram_bot_disable_notification": "Disable notification",
"form.integration.telegram_bot_disable_buttons": "Disable buttons",
"form.integration.linkding_activate": "Simpan artikel ke Linkding",
"form.integration.linkding_endpoint": "Titik URL API Linkding",
"form.integration.linkding_api_key": "Kunci API Linkding",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/it_IT.json
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@
"form.integration.telegram_topic_id": "Topic ID",
"form.integration.telegram_bot_disable_web_page_preview": "Disable web page preview",
"form.integration.telegram_bot_disable_notification": "Disable notification",
"form.integration.telegram_bot_disable_buttons": "Disable buttons",
"form.integration.linkding_activate": "Salva gli articoli su Linkding",
"form.integration.linkding_endpoint": "Endpoint dell'API di Linkding",
"form.integration.linkding_api_key": "API key dell'account Linkding",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/ja_JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@
"form.integration.telegram_topic_id": "Topic ID",
"form.integration.telegram_bot_disable_web_page_preview": "Disable web page preview",
"form.integration.telegram_bot_disable_notification": "Disable notification",
"form.integration.telegram_bot_disable_buttons": "Disable buttons",
"form.integration.linkding_activate": "Linkding に記事を保存する",
"form.integration.linkding_endpoint": "Linkding の API Endpoint",
"form.integration.linkding_api_key": "Linkding の API key",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/nl_NL.json
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@
"form.integration.telegram_topic_id": "Topic ID",
"form.integration.telegram_bot_disable_web_page_preview": "Disable web page preview",
"form.integration.telegram_bot_disable_notification": "Disable notification",
"form.integration.telegram_bot_disable_buttons": "Disable buttons",
"form.integration.linkding_activate": "Opslaan naar Linkding",
"form.integration.linkding_endpoint": "Linkding URL",
"form.integration.linkding_api_key": "Linkding API-sleutel",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/pl_PL.json
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@
"form.integration.telegram_topic_id": "Topic ID",
"form.integration.telegram_bot_disable_web_page_preview": "Disable web page preview",
"form.integration.telegram_bot_disable_notification": "Disable notification",
"form.integration.telegram_bot_disable_buttons": "Disable buttons",
"form.integration.linkding_activate": "Zapisz artykuły do Linkding",
"form.integration.linkding_endpoint": "Linkding URL",
"form.integration.linkding_api_key": "Linkding API key",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/pt_BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@
"form.integration.telegram_topic_id": "Topic ID",
"form.integration.telegram_bot_disable_web_page_preview": "Disable web page preview",
"form.integration.telegram_bot_disable_notification": "Disable notification",
"form.integration.telegram_bot_disable_buttons": "Disable buttons",
"form.integration.linkding_activate": "Salvar itens no Linkding",
"form.integration.linkding_endpoint": "Endpoint de API do Linkding",
"form.integration.linkding_api_key": "Chave de API do Linkding",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/ru_RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@
"form.integration.telegram_topic_id": "Topic ID",
"form.integration.telegram_bot_disable_web_page_preview": "Disable web page preview",
"form.integration.telegram_bot_disable_notification": "Disable notification",
"form.integration.telegram_bot_disable_buttons": "Disable buttons",
"form.integration.linkding_activate": "Сохранять статьи в Linkding",
"form.integration.linkding_endpoint": "Конечная точка Linkding API",
"form.integration.linkding_api_key": "API-ключ Linkding",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/tr_TR.json
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@
"form.integration.telegram_topic_id": "Topic ID",
"form.integration.telegram_bot_disable_web_page_preview": "Disable web page preview",
"form.integration.telegram_bot_disable_notification": "Disable notification",
"form.integration.telegram_bot_disable_buttons": "Disable buttons",
"form.integration.linkding_activate": "Makaleleri Linkding'e kaydet",
"form.integration.linkding_endpoint": "Linkding API Uç Noktası",
"form.integration.linkding_api_key": "Linkding API Anahtarı",
Expand Down
3 changes: 2 additions & 1 deletion internal/locale/translations/uk_UA.json
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@
"form.integration.telegram_topic_id": "Topic ID",
"form.integration.telegram_bot_disable_web_page_preview": "Disable web page preview",
"form.integration.telegram_bot_disable_notification": "Disable notification",
"form.integration.telegram_bot_disable_buttons": "Disable buttons",
"form.integration.telegram_chat_id": "ID чату",
"form.integration.linkding_activate": "Зберігати статті до Linkding",
"form.integration.linkding_endpoint": "Linkding API Endpoint",
Expand Down Expand Up @@ -441,4 +442,4 @@
"%d роки тому",
"%d років тому"
]
}
}
1 change: 1 addition & 0 deletions internal/locale/translations/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@
"form.integration.telegram_topic_id": "Topic ID",
"form.integration.telegram_bot_disable_web_page_preview": "Disable web page preview",
"form.integration.telegram_bot_disable_notification": "Disable notification",
"form.integration.telegram_bot_disable_buttons": "Disable buttons",
"form.integration.telegram_chat_id": "聊天ID",
"form.integration.linkding_activate": "保存文章到 Linkding",
"form.integration.linkding_endpoint": "Linkding API 端点",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/zh_TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@
"form.integration.telegram_topic_id": "Topic ID",
"form.integration.telegram_bot_disable_web_page_preview": "Disable web page preview",
"form.integration.telegram_bot_disable_notification": "Disable notification",
"form.integration.telegram_bot_disable_buttons": "Disable buttons",
"form.integration.linkding_activate": "儲存文章到 Linkding",
"form.integration.linkding_endpoint": "Linkding API 端點",
"form.integration.linkding_api_key": "Linkding API 金鑰",
Expand Down
1 change: 1 addition & 0 deletions internal/model/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type Integration struct {
TelegramBotTopicID *int64
TelegramBotDisableWebPagePreview bool
TelegramBotDisableNotification bool
TelegramBotDisableButtons bool
LinkdingEnabled bool
LinkdingURL string
LinkdingAPIKey string
Expand Down
70 changes: 37 additions & 33 deletions internal/storage/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func (s *Storage) Integration(userID int64) (*model.Integration, error) {
telegram_bot_topic_id,
telegram_bot_disable_web_page_preview,
telegram_bot_disable_notification,
telegram_bot_disable_buttons,
linkding_enabled,
linkding_url,
linkding_api_key,
Expand Down Expand Up @@ -223,6 +224,7 @@ func (s *Storage) Integration(userID int64) (*model.Integration, error) {
&integration.TelegramBotTopicID,
&integration.TelegramBotDisableWebPagePreview,
&integration.TelegramBotDisableNotification,
&integration.TelegramBotDisableButtons,
&integration.LinkdingEnabled,
&integration.LinkdingURL,
&integration.LinkdingAPIKey,
Expand Down Expand Up @@ -295,40 +297,41 @@ func (s *Storage) UpdateIntegration(integration *model.Integration) error {
telegram_bot_topic_id=$30,
telegram_bot_disable_web_page_preview=$31,
telegram_bot_disable_notification=$32,
espial_enabled=$33,
espial_url=$34,
espial_api_key=$35,
espial_tags=$36,
linkding_enabled=$37,
linkding_url=$38,
linkding_api_key=$39,
linkding_tags=$40,
linkding_mark_as_unread=$41,
matrix_bot_enabled=$42,
matrix_bot_user=$43,
matrix_bot_password=$44,
matrix_bot_url=$45,
matrix_bot_chat_id=$46,
notion_enabled=$47,
notion_token=$48,
notion_page_id=$49,
readwise_enabled=$50,
readwise_api_key=$51,
apprise_enabled=$52,
apprise_url=$53,
apprise_services_url=$54,
shiori_enabled=$55,
shiori_url=$56,
shiori_username=$57,
shiori_password=$58,
shaarli_enabled=$59,
shaarli_url=$60,
shaarli_api_secret=$61,
webhook_enabled=$62,
webhook_url=$63,
webhook_secret=$64
telegram_bot_disable_buttons=$33,
espial_enabled=$34,
espial_url=$35,
espial_api_key=$36,
espial_tags=$37,
linkding_enabled=$38,
linkding_url=$39,
linkding_api_key=$40,
linkding_tags=$41,
linkding_mark_as_unread=$42,
matrix_bot_enabled=$43,
matrix_bot_user=$44,
matrix_bot_password=$45,
matrix_bot_url=$46,
matrix_bot_chat_id=$47,
notion_enabled=$48,
notion_token=$49,
notion_page_id=$50,
readwise_enabled=$51,
readwise_api_key=$52,
apprise_enabled=$53,
apprise_url=$54,
apprise_services_url=$55,
shiori_enabled=$56,
shiori_url=$57,
shiori_username=$58,
shiori_password=$59,
shaarli_enabled=$60,
shaarli_url=$61,
shaarli_api_secret=$62,
webhook_enabled=$63,
webhook_url=$64,
webhook_secret=$65
WHERE
user_id=$65
user_id=$66
`
_, err := s.db.Exec(
query,
Expand Down Expand Up @@ -364,6 +367,7 @@ func (s *Storage) UpdateIntegration(integration *model.Integration) error {
integration.TelegramBotTopicID,
integration.TelegramBotDisableWebPagePreview,
integration.TelegramBotDisableNotification,
integration.TelegramBotDisableButtons,
integration.EspialEnabled,
integration.EspialURL,
integration.EspialAPIKey,
Expand Down
4 changes: 4 additions & 0 deletions internal/template/templates/views/integrations.html
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,10 @@ <h1>{{ t "page.integrations.title" }}</h1>
<input type="checkbox" name="telegram_bot_disable_notification" value="1" {{ if .form.TelegramBotDisableNotification }}checked{{ end }}> {{ t "form.integration.telegram_bot_disable_notification" }}
</label>

<label>
<input type="checkbox" name="telegram_bot_disable_buttons" value="1" {{ if .form.TelegramBotDisableButtons }}checked{{ end }}> {{ t "form.integration.telegram_bot_disable_buttons" }}
</label>

<div class="buttons">
<button type="submit" class="button button-primary" data-label-loading="{{ t "form.submit.saving" }}">{{ t "action.update" }}</button>
</div>
Expand Down
3 changes: 3 additions & 0 deletions internal/ui/form/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type IntegrationForm struct {
TelegramBotTopicID *int64
TelegramBotDisableWebPagePreview bool
TelegramBotDisableNotification bool
TelegramBotDisableButtons bool
LinkdingEnabled bool
LinkdingURL string
LinkdingAPIKey string
Expand Down Expand Up @@ -119,6 +120,7 @@ func (i IntegrationForm) Merge(integration *model.Integration) {
integration.TelegramBotTopicID = i.TelegramBotTopicID
integration.TelegramBotDisableWebPagePreview = i.TelegramBotDisableWebPagePreview
integration.TelegramBotDisableNotification = i.TelegramBotDisableNotification
integration.TelegramBotDisableButtons = i.TelegramBotDisableButtons
integration.LinkdingEnabled = i.LinkdingEnabled
integration.LinkdingURL = i.LinkdingURL
integration.LinkdingAPIKey = i.LinkdingAPIKey
Expand Down Expand Up @@ -187,6 +189,7 @@ func NewIntegrationForm(r *http.Request) *IntegrationForm {
TelegramBotTopicID: optionalInt64Field(r.FormValue("telegram_bot_topic_id")),
TelegramBotDisableWebPagePreview: r.FormValue("telegram_bot_disable_web_page_preview") == "1",
TelegramBotDisableNotification: r.FormValue("telegram_bot_disable_notification") == "1",
TelegramBotDisableButtons: r.FormValue("telegram_bot_disable_buttons") == "1",
LinkdingEnabled: r.FormValue("linkding_enabled") == "1",
LinkdingURL: r.FormValue("linkding_url"),
LinkdingAPIKey: r.FormValue("linkding_api_key"),
Expand Down
1 change: 1 addition & 0 deletions internal/ui/integration_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func (h *handler) showIntegrationPage(w http.ResponseWriter, r *http.Request) {
TelegramBotTopicID: integration.TelegramBotTopicID,
TelegramBotDisableWebPagePreview: integration.TelegramBotDisableWebPagePreview,
TelegramBotDisableNotification: integration.TelegramBotDisableNotification,
TelegramBotDisableButtons: integration.TelegramBotDisableButtons,
LinkdingEnabled: integration.LinkdingEnabled,
LinkdingURL: integration.LinkdingURL,
LinkdingAPIKey: integration.LinkdingAPIKey,
Expand Down

0 comments on commit 8e593f0

Please sign in to comment.