Add SendEphemeralToChannel and SendEphemeralToConvID
This commit is contained in:
42
chat.go
42
chat.go
@ -226,6 +226,48 @@ func (k *Keybase) SendMessageToConvID(convID chat1.ConvIDStr, message string, a
|
||||
return r, nil
|
||||
}
|
||||
|
||||
// SendEphemeralToChannel sends a chat message to a channel
|
||||
func (k *Keybase) SendEphemeralToChannel(channel chat1.ChatChannel, duration time.Duration, message string, a ...interface{}) (SendResponse, error) {
|
||||
var r SendResponse
|
||||
|
||||
opts := SendMessageOptions{
|
||||
Channel: channel,
|
||||
Message: SendMessageBody{
|
||||
Body: fmt.Sprintf(message, a...),
|
||||
},
|
||||
}
|
||||
|
||||
opts.ExplodingLifetime.Duration = duration
|
||||
|
||||
r, err := k.SendMessage(opts)
|
||||
if err != nil {
|
||||
return r, err
|
||||
}
|
||||
|
||||
return r, nil
|
||||
}
|
||||
|
||||
// SendEphemeralToConvID sends a chat message to a conversation id
|
||||
func (k *Keybase) SendEphemeralToConvID(convID chat1.ConvIDStr, duration time.Duration, message string, a ...interface{}) (SendResponse, error) {
|
||||
var r SendResponse
|
||||
|
||||
opts := SendMessageOptions{
|
||||
ConversationID: convID,
|
||||
Message: SendMessageBody{
|
||||
Body: fmt.Sprintf(message, a...),
|
||||
},
|
||||
}
|
||||
|
||||
opts.ExplodingLifetime.Duration = duration
|
||||
|
||||
r, err := k.SendMessage(opts)
|
||||
if err != nil {
|
||||
return r, err
|
||||
}
|
||||
|
||||
return r, nil
|
||||
}
|
||||
|
||||
// Send sends a chat message
|
||||
func (c Chat) Send(message ...string) (ChatAPI, error) {
|
||||
m := ChatAPI{
|
||||
|
||||
27
types.go
27
types.go
@ -27,6 +27,19 @@ type Error struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
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 SendMessageBody struct {
|
||||
Body string
|
||||
}
|
||||
@ -41,6 +54,7 @@ type SendMessageOptions struct {
|
||||
MessageID chat1.MessageID `json:"message_id,omitempty"`
|
||||
ConfirmLumenSend bool `json:"confirm_lumen_send"`
|
||||
ReplyTo *chat1.MessageID `json:"reply_to,omitempty"`
|
||||
ExplodingLifetime duration `json:"exploding_lifetime,omitempty"`
|
||||
}
|
||||
|
||||
type sendMessageParams struct {
|
||||
@ -367,19 +381,6 @@ 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 *chat1.ChatChannel `json:"channel,omitempty"`
|
||||
MessageID int `json:"message_id,omitempty"`
|
||||
|
||||
Reference in New Issue
Block a user