Browse Source

Add upload and download methods to chat

main
Sam 5 years ago
parent
commit
d99546ae79
  1. 32
      chat.go
  2. 5
      types.go

32
chat.go

@ -273,3 +273,35 @@ func (c *ChatAPI) Previous(count ...int) (*ChatAPI, error) { @@ -273,3 +273,35 @@ func (c *ChatAPI) Previous(count ...int) (*ChatAPI, error) {
c.keybase = k
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
}

5
types.go

@ -200,6 +200,9 @@ type options struct { @@ -200,6 +200,9 @@ type options struct {
MessageID int `json:"message_id"`
Message message `json:"message"`
Pagination pagination `json:"pagination"`
Filename string `json:"filename,omitempty"`
Title string `json:"title,omitempty"`
Output string `json:"output,omitempty"`
}
type params struct {
Options options `json:"options"`
@ -416,6 +419,8 @@ type chat interface { @@ -416,6 +419,8 @@ type chat interface {
Edit(messageID int, message ...string) (ChatAPI, error)
React(messageID int, reaction 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 {

Loading…
Cancel
Save