From 717c8f2538e1855ca6499a48d8de043aa1ace584 Mon Sep 17 00:00:00 2001 From: Chris Rhodes Date: Sun, 13 Nov 2016 21:51:57 -0800 Subject: [PATCH] Support embed messages. --- restapi.go | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/restapi.go b/restapi.go index 1423fa9..fd4f8cd 100644 --- a/restapi.go +++ b/restapi.go @@ -1228,6 +1228,28 @@ func (s *Session) ChannelMessageSendTTS(channelID string, content string) (st *M return s.channelMessageSend(channelID, content, true) } +// ChannelMessageSendEmbed sends a message to the given channel with embedded data (bot only). +// channelID : The ID of a Channel. +// embed : The embed data to send. +func (s *Session) ChannelMessageSendEmbed(channelID string, embed *MessageEmbed) (st *Message, err error) { + if embed != nil && embed.Type == "" { + embed.Type = "rich" + } + + data := struct { + Embed *MessageEmbed `json:"embed"` + }{embed} + + // Send the message to the given channel + response, err := s.RequestWithBucketID("POST", EndpointChannelMessages(channelID), data, EndpointChannelMessages(channelID)) + if err != nil { + return + } + + err = unmarshal(response, &st) + return +} + // ChannelMessageEdit edits an existing message, replacing it entirely with // the given content. // channeld : The ID of a Channel @@ -1680,8 +1702,6 @@ func (s *Session) WebhookExecute(webhookID, token string, wait bool, data *Webho uri += "?wait=true" } - fmt.Println(uri) - _, err = s.RequestWithBucketID("POST", uri, data, EndpointWebhookToken("", "")) return @@ -1759,8 +1779,6 @@ func (s *Session) relationshipCreate(userID string, relationshipType int) (err e Type int `json:"type"` }{relationshipType} - fmt.Println("Data: " + fmt.Sprintf("%v", data)) - _, err = s.RequestWithBucketID("PUT", EndpointRelationship(userID), data, EndpointRelationships()) return }