tucnak / telebot

Telebot is a Telegram bot framework in Go.
MIT License
4.01k stars 467 forks source link

FileName not work when use Send tb.Document #147

Closed mritd closed 6 years ago

mritd commented 6 years ago

FileName not work when use Send tb.Document; Here is the sample code:

package main

import (
    "net/http"
    "time"
    "net/url"
    tb "gopkg.in/tucnak/telebot.v2"
)

func main() {

    p := func(_ *http.Request) (*url.URL, error) {
        return url.Parse("http://PROXY_ADDRESS:8123")
    }
    client := &http.Client{
        Timeout: 20 * time.Second,
        Transport: &http.Transport{Proxy: p},
    }

    bot, _ := tb.NewBot(tb.Settings{
        Token:  "BOT_TOKEN",
        Poller: &tb.LongPoller{Timeout: 10 * time.Second},
        Client: client,
    })
    bot.Send(&tb.Chat{ID: int64(305893639)}, &tb.Document{
        File:     tb.FromDisk("/Users/mritd/gopath/src/github.com/mritd/test/main.go"),
        FileName: "test",
    })
}

image

olehbozhok commented 6 years ago

you need specify caption https://core.telegram.org/bots/api#senddocument

FileName is not "" when you got file

mritd commented 6 years ago

@Oleg-MBO I added the caption parameter, but the file name has not changed.

image

ilyaglow commented 5 years ago

Same thing for tb.FromReader call.

ilyaglow commented 5 years ago

Hmm, it seems that 6264ba6 doesn't work for the OP case either. Reproduced the same issue with tb.FromDisk too. Ping @tucnak @stek29.

We should probably add filename parameter to addFileToWriter function.

stek29 commented 5 years ago

hm, I don't think that'd be enough. FileName needs to be passed from (Object).Send to (*Bot) sendObject, and from there to (*Bot) sendFiles, and from there to addFileToWriter.

Also, what should we do with files created from file_id/url? There's no way to set filename there, is there?