Browse Source

added support for SendEphemeral

main
David Haukeness 4 years ago
parent
commit
8a5685459a
No known key found for this signature in database
GPG Key ID: 54F2372DDB7F9462
  1. 20
      chat.go
  2. 16
      types.go

20
chat.go

@ -185,6 +185,26 @@ func (c Chat) Send(message ...string) (ChatAPI, error) { @@ -185,6 +185,26 @@ func (c Chat) Send(message ...string) (ChatAPI, error) {
return r, nil
}
// SendEphemeral sends an exploding chat message, with specified duration
func (c Chat) SendEphemeral(duration time.Duration, message ...string) (ChatAPI, error) {
m := ChatAPI{
Params: &params{},
}
m.Params.Options = options{
Message: &mesg{},
}
m.Params.Options.ExplodingLifetime.Duration = duration
m.Method = "send"
m.Params.Options.Channel = &c.Channel
m.Params.Options.Message.Body = strings.Join(message, " ")
r, err := chatAPIOut(c.keybase, m)
if err != nil {
return r, err
}
return r, nil
}
// Reply sends a reply to a chat message
func (c Chat) Reply(replyTo int, message ...string) (ChatAPI, error) {
m := ChatAPI{

16
types.go

@ -2,6 +2,8 @@ package keybase @@ -2,6 +2,8 @@ package keybase
import (
"encoding/json"
"fmt"
"strings"
"time"
)
@ -326,6 +328,19 @@ type mesg struct { @@ -326,6 +328,19 @@ type mesg struct {
Body string `json:"body"`
}
type duration struct {
time.Duration
}
func (d *duration) UnmarshalJSON(b []byte) (err error) {
d.Duration, err = time.ParseDuration(strings.Trim(string(b), `"`))
return
}
func (d *duration) MarshalJSON() (b []byte, err error) {
return []byte(fmt.Sprintf(`"%s"`, d.String())), nil
}
type options struct {
Channel *Channel `json:"channel,omitempty"`
MessageID int `json:"message_id,omitempty"`
@ -341,6 +356,7 @@ type options struct { @@ -341,6 +356,7 @@ type options struct {
GameID string `json:"game_id,omitempty"`
Alias string `json:"alias,omitempty"`
BotAdvertisements []BotAdvertisement `json:"advertisements,omitempty"`
ExplodingLifetime duration `json:"exploding_lifetime,omitempty"`
Name string `json:"name,omitempty"`
Public bool `json:"public,omitempty"`

Loading…
Cancel
Save