Add ReplyToChannel and ReplyToConvID, and attempt to fix ephemeral sends
This commit is contained in:
56
chat.go
56
chat.go
@ -235,10 +235,9 @@ func (k *Keybase) SendEphemeralToChannel(channel chat1.ChatChannel, duration tim
|
|||||||
Message: SendMessageBody{
|
Message: SendMessageBody{
|
||||||
Body: fmt.Sprintf(message, a...),
|
Body: fmt.Sprintf(message, a...),
|
||||||
},
|
},
|
||||||
|
ExplodingLifetime: explodingLifetime{duration},
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.ExplodingLifetime.Duration = duration
|
|
||||||
|
|
||||||
r, err := k.SendMessage(opts)
|
r, err := k.SendMessage(opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return r, err
|
return r, err
|
||||||
@ -256,10 +255,9 @@ func (k *Keybase) SendEphemeralToConvID(convID chat1.ConvIDStr, duration time.Du
|
|||||||
Message: SendMessageBody{
|
Message: SendMessageBody{
|
||||||
Body: fmt.Sprintf(message, a...),
|
Body: fmt.Sprintf(message, a...),
|
||||||
},
|
},
|
||||||
|
ExplodingLifetime: explodingLifetime{duration},
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.ExplodingLifetime.Duration = duration
|
|
||||||
|
|
||||||
r, err := k.SendMessage(opts)
|
r, err := k.SendMessage(opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return r, err
|
return r, err
|
||||||
@ -268,43 +266,43 @@ func (k *Keybase) SendEphemeralToConvID(convID chat1.ConvIDStr, duration time.Du
|
|||||||
return r, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send sends a chat message
|
// ReplyToChannel sends a chat message to a channel
|
||||||
func (c Chat) Send(message ...string) (ChatAPI, error) {
|
func (k *Keybase) ReplyToChannel(channel chat1.ChatChannel, replyTo *chat1.MessageID, message string, a ...interface{}) (SendResponse, error) {
|
||||||
m := ChatAPI{
|
var r SendResponse
|
||||||
Params: ¶ms{},
|
|
||||||
}
|
opts := SendMessageOptions{
|
||||||
m.Params.Options = options{
|
Channel: channel,
|
||||||
Message: &mesg{},
|
Message: SendMessageBody{
|
||||||
|
Body: fmt.Sprintf(message, a...),
|
||||||
|
},
|
||||||
|
ReplyTo: replyTo,
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Method = "send"
|
r, err := k.SendMessage(opts)
|
||||||
m.Params.Options.Channel = &c.Channel
|
|
||||||
m.Params.Options.Message.Body = strings.Join(message, " ")
|
|
||||||
|
|
||||||
r, err := chatAPIOut(c.keybase, m)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return r, err
|
return r, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return r, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendEphemeral sends an exploding chat message, with specified duration
|
// ReplyToConvID sends a chat message to a conversation id
|
||||||
func (c Chat) SendEphemeral(duration time.Duration, message ...string) (ChatAPI, error) {
|
func (k *Keybase) ReplyToConvID(convID chat1.ConvIDStr, replyTo *chat1.MessageID, message string, a ...interface{}) (SendResponse, error) {
|
||||||
m := ChatAPI{
|
var r SendResponse
|
||||||
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)
|
opts := SendMessageOptions{
|
||||||
|
ConversationID: convID,
|
||||||
|
Message: SendMessageBody{
|
||||||
|
Body: fmt.Sprintf(message, a...),
|
||||||
|
},
|
||||||
|
ReplyTo: replyTo,
|
||||||
|
}
|
||||||
|
|
||||||
|
r, err := k.SendMessage(opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return r, err
|
return r, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return r, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
10
types.go
10
types.go
@ -27,16 +27,16 @@ type Error struct {
|
|||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type duration struct {
|
type explodingLifetime struct {
|
||||||
time.Duration
|
time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *duration) UnmarshalJSON(b []byte) (err error) {
|
func (d *explodingLifetime) UnmarshalJSON(b []byte) (err error) {
|
||||||
d.Duration, err = time.ParseDuration(strings.Trim(string(b), `"`))
|
d.Duration, err = time.ParseDuration(strings.Trim(string(b), `"`))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *duration) MarshalJSON() (b []byte, err error) {
|
func (d *explodingLifetime) MarshalJSON() (b []byte, err error) {
|
||||||
return []byte(fmt.Sprintf(`"%s"`, d.String())), nil
|
return []byte(fmt.Sprintf(`"%s"`, d.String())), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ type SendMessageOptions struct {
|
|||||||
MessageID chat1.MessageID `json:"message_id,omitempty"`
|
MessageID chat1.MessageID `json:"message_id,omitempty"`
|
||||||
ConfirmLumenSend bool `json:"confirm_lumen_send"`
|
ConfirmLumenSend bool `json:"confirm_lumen_send"`
|
||||||
ReplyTo *chat1.MessageID `json:"reply_to,omitempty"`
|
ReplyTo *chat1.MessageID `json:"reply_to,omitempty"`
|
||||||
ExplodingLifetime duration `json:"exploding_lifetime,omitempty"`
|
ExplodingLifetime explodingLifetime `json:"exploding_lifetime,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type sendMessageParams struct {
|
type sendMessageParams struct {
|
||||||
@ -396,7 +396,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"`
|
//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