Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish to telegram #15

Merged
merged 25 commits into from
Dec 6, 2019
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d938e0f
Add telegram client, for send notification
sgaynetdinov Nov 16, 2019
908cda8
Send message telegram if get new item RSS
sgaynetdinov Nov 16, 2019
3ae8267
Add new package in vendor
sgaynetdinov Nov 16, 2019
d8fb331
Not raise error if telegram token empty
sgaynetdinov Nov 18, 2019
c741b89
Add 'TestSendIfChannelIDEmpty'
sgaynetdinov Nov 18, 2019
ee439da
Fix: 'NewTelegramClient' return 'TelegramClient' not 'nil'
sgaynetdinov Nov 18, 2019
635a674
Add in environment 'TELEGRAM_TOKEN'
sgaynetdinov Nov 18, 2019
80ca198
Refactoring test
sgaynetdinov Nov 18, 2019
be4eeb7
Add test for 'TelegramClient.tagLinkOnlySupport'
sgaynetdinov Nov 18, 2019
117ef40
Add test for 'TelegramClient.getMessageHTML'
sgaynetdinov Nov 18, 2019
bec8544
Rename 'html_expected' -> 'htmlExpected'
sgaynetdinov Nov 18, 2019
010a331
Pretty log, if error send telegram message
sgaynetdinov Nov 19, 2019
d3d0adb
dd prefix "@" for "channel" if not found
sgaynetdinov Nov 19, 2019
b8312f0
Add interface 'Notification'
sgaynetdinov Nov 19, 2019
69f08f9
Set timeout for telegram
sgaynetdinov Nov 20, 2019
2b98130
Revert "Set timeout for telegram"
sgaynetdinov Nov 26, 2019
336fa15
Use timeout from http.Client without context timeout
sgaynetdinov Nov 26, 2019
c5a94a5
Pretty log
sgaynetdinov Dec 4, 2019
c2f5de1
Send audio if file size less 50 Mb or send only text
sgaynetdinov Dec 4, 2019
727df45
Add const 'maxTelegramFileSize'
sgaynetdinov Dec 5, 2019
395831a
Refactoring, message error
sgaynetdinov Dec 5, 2019
ec63f0e
Get filename audio file from url
sgaynetdinov Dec 5, 2019
588a63f
Fix: []byte is a slice backed by pointer already
sgaynetdinov Dec 5, 2019
e27a045
Telegram timeout moved to opts
sgaynetdinov Dec 5, 2019
7193518
Not reads file content to memory
sgaynetdinov Dec 5, 2019
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
Prev Previous commit
Not reads file content to memory
  • Loading branch information
sgaynetdinov committed Dec 5, 2019
commit 7193518df4b6ae9535032d42e1d052dc481d67b2
19 changes: 6 additions & 13 deletions app/proc/telegram.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package proc

import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net/http"
"path"
"strings"
@@ -113,13 +112,14 @@ func (client TelegramClient) sendText(channelID string, item feed.Item) (*tb.Mes
}

func (client TelegramClient) sendAudio(channelID string, item feed.Item) (*tb.Message, error) {
file, err := client.downloadAudio(item.Enclosure.URL)
httpBody, err := client.downloadAudio(item.Enclosure.URL)
defer httpBody.Close() //nolint:staticcheck
if err != nil {
return nil, err
}

audio := tb.Audio{
File: tb.FromReader(bytes.NewReader(file)),
File: tb.FromReader(httpBody),
FileName: client.getFilenameByURL(item.Enclosure.URL),
MIME: "audio/mpeg",
Caption: client.getMessageHTML(item),
@@ -137,24 +137,17 @@ func (client TelegramClient) sendAudio(channelID string, item feed.Item) (*tb.Me
return message, err
}

func (client TelegramClient) downloadAudio(url string) ([]byte, error) {
func (client TelegramClient) downloadAudio(url string) (io.ReadCloser, error) {
clientHTTP := &http.Client{Timeout: client.Timeout * time.Second}

resp, err := clientHTTP.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()

log.Printf("[DEBUG] start download audio: %s", url)

file, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}

log.Printf("[DEBUG] finish download audio: %s", url)
return file, err
return resp.Body, err
}

// https://core.telegram.org/bots/api#html-style