Add upload and download methods to chat

This commit is contained in:
Sam
2019-09-07 10:06:50 -04:00
parent ca4ea152e9
commit d99546ae79
2 changed files with 37 additions and 0 deletions

32
chat.go
View File

@ -273,3 +273,35 @@ func (c *ChatAPI) Previous(count ...int) (*ChatAPI, error) {
c.keybase = k c.keybase = k
return c, nil return c, nil
} }
func (c Chat) Upload(title string, filepath string) (ChatAPI, error) {
m := ChatAPI{
Params: &params{},
}
m.Method = "attach"
m.Params.Options.Channel = c.Channel
m.Params.Options.Filename = filepath
m.Params.Options.Title = title
r, err := chatAPIOut(c.keybase.Path, m)
if err != nil {
return ChatAPI{}, err
}
return r, nil
}
func (c Chat) Download(messageID int, filepath string) (ChatAPI, error) {
m := ChatAPI{
Params: &params{},
}
m.Method = "download"
m.Params.Options.Channel = c.Channel
m.Params.Options.Output = filepath
m.Params.Options.MessageID = messageID
r, err := chatAPIOut(c.keybase.Path, m)
if err != nil {
return ChatAPI{}, err
}
return r, nil
}

View File

@ -200,6 +200,9 @@ type options struct {
MessageID int `json:"message_id"` MessageID int `json:"message_id"`
Message message `json:"message"` Message message `json:"message"`
Pagination pagination `json:"pagination"` Pagination pagination `json:"pagination"`
Filename string `json:"filename,omitempty"`
Title string `json:"title,omitempty"`
Output string `json:"output,omitempty"`
} }
type params struct { type params struct {
Options options `json:"options"` Options options `json:"options"`
@ -416,6 +419,8 @@ type chat interface {
Edit(messageID int, message ...string) (ChatAPI, error) Edit(messageID int, message ...string) (ChatAPI, error)
React(messageID int, reaction string) (ChatAPI, error) React(messageID int, reaction string) (ChatAPI, error)
Send(message ...string) (ChatAPI, error) Send(message ...string) (ChatAPI, error)
Upload(title string, filepath string) (ChatAPI, error)
Download(messageID int, filepath string) (ChatAPI, error)
} }
type chatAPI interface { type chatAPI interface {