added ChannelSendFileWithMessage

kept it backwards compatible so previous apps dont crash with missing field.
This commit is contained in:
daniel portella 2016-07-26 22:18:20 +01:00
parent 1dcb081f13
commit f4b8e2ecc2

View file

@ -1218,12 +1218,28 @@ func (s *Session) ChannelMessagesPinned(channelID string) (st []*Message, err er
// ChannelFileSend sends a file to the given channel. // ChannelFileSend sends a file to the given channel.
// channelID : The ID of a Channel. // channelID : The ID of a Channel.
// name: The name of the file.
// io.Reader : A reader for the file contents. // io.Reader : A reader for the file contents.
func (s *Session) ChannelFileSend(channelID, name string, r io.Reader) (st *Message, err error) { func (s *Session) ChannelFileSend(channelID, name string, r io.Reader) (st *Message, err error) {
return s.ChannelFileSendWithMessage(channelID, "", name, r)
}
// ChannelFileSendWithMessage sends a file to the given channel with an message.
// channelID : The ID of a Channel.
// content: Optional Message content.
// name: The name of the file.
// io.Reader : A reader for the file contents.
func (s *Session) ChannelFileSendWithMessage(channelID, content string, name string, r io.Reader) (st *Message, err error) {
body := &bytes.Buffer{} body := &bytes.Buffer{}
bodywriter := multipart.NewWriter(body) bodywriter := multipart.NewWriter(body)
if len(content) != 0 {
if err := bodywriter.WriteField("content", content); err != nil {
return nil, err
}
}
writer, err := bodywriter.CreateFormFile("file", name) writer, err := bodywriter.CreateFormFile("file", name)
if err != nil { if err != nil {
return nil, err return nil, err