added support for SendEphemeral
This commit is contained in:
20
chat.go
20
chat.go
@ -185,6 +185,26 @@ func (c Chat) Send(message ...string) (ChatAPI, error) {
|
|||||||
return r, nil
|
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: ¶ms{},
|
||||||
|
}
|
||||||
|
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
|
// Reply sends a reply to a chat message
|
||||||
func (c Chat) Reply(replyTo int, message ...string) (ChatAPI, error) {
|
func (c Chat) Reply(replyTo int, message ...string) (ChatAPI, error) {
|
||||||
m := ChatAPI{
|
m := ChatAPI{
|
||||||
|
|||||||
16
types.go
16
types.go
@ -2,6 +2,8 @@ package keybase
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -326,6 +328,19 @@ type mesg struct {
|
|||||||
Body string `json:"body"`
|
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 {
|
type options struct {
|
||||||
Channel *Channel `json:"channel,omitempty"`
|
Channel *Channel `json:"channel,omitempty"`
|
||||||
MessageID int `json:"message_id,omitempty"`
|
MessageID int `json:"message_id,omitempty"`
|
||||||
@ -341,6 +356,7 @@ type options struct {
|
|||||||
GameID string `json:"game_id,omitempty"`
|
GameID string `json:"game_id,omitempty"`
|
||||||
Alias string `json:"alias,omitempty"`
|
Alias string `json:"alias,omitempty"`
|
||||||
BotAdvertisements []BotAdvertisement `json:"advertisements,omitempty"`
|
BotAdvertisements []BotAdvertisement `json:"advertisements,omitempty"`
|
||||||
|
ExplodingLifetime duration `json:"exploding_lifetime,omitempty"`
|
||||||
|
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
Public bool `json:"public,omitempty"`
|
Public bool `json:"public,omitempty"`
|
||||||
|
|||||||
Reference in New Issue
Block a user