~thrrgilag/woodstock

b22c4f10cc34dd705156e254a2c022a8d5596f52 — Morgan McMillian 1 year, 2 months ago 3b9e0ef
add raw to CreateMessage
2 files changed, 18 insertions(+), 9 deletions(-)

M channels.go
M channels_test.go
M channels.go => channels.go +9 -6
@@ 23,8 23,13 @@ type createChannel struct {
	ACL  ACL    `json:"acl"`
}

type createMessage struct {
	Text string `json:"text"`
type NewMessage struct {
	Text               string `json:"text"`
	ParseLinks         string `json:"entities.parse_links,omitempty"`
	ParseMarkdownLinks string `json:"entities.parse_markdown_links,omitempty"`
	Nsfw               string `json:"is_nsfw,omitempty"`
	Raw                []Raw  `json:"raw"`
	ReplyTo            string `json:"reply_to,omitempty"`
}

// GetChannel retrieves the channel object from the channel ID


@@ 155,10 160,8 @@ func (c *Client) GetMessagesOfChannel(id string) (result PostsResult, err error)

// CreateMessage creates a new message
// https://pnut.io/docs/resources/messages/lifecycle#post-channels-id-messages
func (c *Client) CreateMessage(id string, text string) (result PostResult, err error) {
	var message createMessage
	message.Text = text
	json, err := json.Marshal(message)
func (c *Client) CreateMessage(id string, params NewMessage) (result PostResult, err error) {
	json, err := json.Marshal(params)
	if err != nil {
		return
	}

M channels_test.go => channels_test.go +9 -3
@@ 266,7 266,11 @@ func TestCreateMessage(t *testing.T) {
	text := "golang rocks!"
	client := NewClient(config.ClientID, "")
	client.SetAccessToken(config.AccessToken)
	message, err := client.CreateMessage(channelID, text)
	language := map[string]string{"language": "en"}
	var raw []Raw
	raw = append(raw, Raw{Type: "io.pnut.core.language", Value: language})
	newmessage := NewMessage{Text: text, Raw: raw}
	message, err := client.CreateMessage(channelID, newmessage)
	if err != nil {
		t.Error(err)
	}


@@ 285,11 289,13 @@ func TestDeleteMessage(t *testing.T) {
	text := "golang rocks!"
	client := NewClient(config.ClientID, "")
	client.SetAccessToken(config.AccessToken)
	newmessage, err := client.CreateMessage(channelID, text)
	var raw []Raw
	newmessage := NewMessage{Text: text, Raw: raw}
	newmessager, err := client.CreateMessage(channelID, newmessage)
	if err != nil {
		t.Error(err)
	}
	message, err := client.DeleteMessage(channelID, newmessage.Data.ID)
	message, err := client.DeleteMessage(channelID, newmessager.Data.ID)
	if err != nil {
		t.Error(err)
	}