Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ScheduleMessage not returning scheduled_message_id #1153

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 11 additions & 7 deletions chat.go
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"net/url"
"regexp"
Expand Down Expand Up @@ -114,13 +114,13 @@ func (api *Client) ScheduleMessage(channelID, postAt string, options ...MsgOptio
//
// For more details, see ScheduleMessage documentation.
func (api *Client) ScheduleMessageContext(ctx context.Context, channelID, postAt string, options ...MsgOption) (string, string, error) {
respChannel, respTimestamp, _, err := api.SendMessageContext(
respChannel, scheduledMessageId, _, err := api.SendMessageContext(
ctx,
channelID,
MsgOptionSchedule(postAt),
MsgOptionCompose(options...),
)
return respChannel, respTimestamp, err
return respChannel, scheduledMessageId, err
}

// PostMessage sends a message to a channel.
Expand Down Expand Up @@ -208,7 +208,7 @@ func (api *Client) SendMessage(channel string, options ...MsgOption) (string, st
}

// SendMessageContext more flexible method for configuring messages with a custom context.
func (api *Client) SendMessageContext(ctx context.Context, channelID string, options ...MsgOption) (_channel string, _timestamp string, _text string, err error) {
func (api *Client) SendMessageContext(ctx context.Context, channelID string, options ...MsgOption) (_channel string, _timestampOrScheduledMessageId string, _text string, err error) {
var (
req *http.Request
parser func(*chatResponseFull) responseParser
Expand All @@ -220,19 +220,23 @@ func (api *Client) SendMessageContext(ctx context.Context, channelID string, opt
}

if api.Debug() {
reqBody, err := ioutil.ReadAll(req.Body)
reqBody, err := io.ReadAll(req.Body)
if err != nil {
return "", "", "", err
}
req.Body = ioutil.NopCloser(bytes.NewBuffer(reqBody))
req.Body = io.NopCloser(bytes.NewBuffer(reqBody))
api.Debugf("Sending request: %s", redactToken(reqBody))
}

if err = doPost(ctx, api.httpclient, req, parser(&response), api); err != nil {
return "", "", "", err
}

return response.Channel, response.getMessageTimestamp(), response.Text, response.Err()
if response.ScheduledMessageID != "" {
return response.Channel, response.ScheduledMessageID, response.Text, response.Err()
} else {
return response.Channel, response.getMessageTimestamp(), response.Text, response.Err()
}
}

func redactToken(b []byte) []byte {
Expand Down