Browse Source

added ChannelSendFileWithMessage

kept it backwards compatible so previous apps dont crash with missing field.
daniel portella 8 years ago
parent
commit
f4b8e2ecc2
1 changed files with 16 additions and 0 deletions
  1. 16 0
      restapi.go

+ 16 - 0
restapi.go

@@ -1218,12 +1218,28 @@ func (s *Session) ChannelMessagesPinned(channelID string) (st []*Message, err er
 
 // ChannelFileSend sends a file to the given channel.
 // channelID : The ID of a Channel.
+// name: The name of the file.
 // io.Reader : A reader for the file contents.
 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{}
 	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)
 	if err != nil {
 		return nil, err