Documentation ¶
Overview ¶
Package goteamsnotify is used to send messages to Microsoft Teams (channels)
PROJECT HOME ¶
See our GitHub repo (https://github.com/atc0005/go-teams-notify) for the latest code, to file an issue or submit improvements for review and potential inclusion into the project.
PURPOSE ¶
Send messages to a Microsoft Teams channel.
FEATURES ¶
• Generate messages with one or more sections, Facts (key/value pairs) or images (hosted externally)
• Submit messages to Microsoft Teams
EXAMPLE
import ( "github.com/atc0005/go-teams-notify/v2" ) func main() { _ = sendTheMessage() } func sendTheMessage() error { // init the client mstClient := goteamsnotify.NewClient() // setup webhook url webhookUrl := "https://outlook.office.com/webhook/YOUR_WEBHOOK_URL_OF_TEAMS_CHANNEL" // setup message card msgCard := goteamsnotify.NewMessageCard() msgCard.Title = "Hello world" msgCard.Text = "Here are some examples of formatted stuff like "+ "<br> * this list itself <br> * **bold** <br> * *italic* <br> * ***bolditalic***" msgCard.ThemeColor = "#DF813D" // send return mstClient.Send(webhookUrl, msgCard) }
Index ¶
- Constants
- func IsValidInput(webhookMessage MessageCard, webhookURL string) (bool, error)
- func IsValidMessageCard(webhookMessage MessageCard) (bool, error)
- func IsValidWebhookURL(webhookURL string) (bool, error)
- type API
- type MessageCard
- type MessageCardSection
- func (mcs *MessageCardSection) AddFact(fact ...MessageCardSectionFact) error
- func (mcs *MessageCardSection) AddFactFromKeyValue(key string, values ...string) error
- func (mcs *MessageCardSection) AddHeroImage(heroImage MessageCardSectionImage) error
- func (mcs *MessageCardSection) AddHeroImageStr(imageURL string, imageTitle string) error
- func (mcs *MessageCardSection) AddImage(sectionImage ...MessageCardSectionImage) error
- type MessageCardSectionFact
- type MessageCardSectionImage
Constants ¶
const ( WebhookURLOfficecomPrefix = "https://outlook.office.com" WebhookURLOffice365Prefix = "https://outlook.office365.com" )
Known webhook URL prefixes for submitting messages to Microsoft Teams
Variables ¶
This section is empty.
Functions ¶
func IsValidInput ¶
func IsValidInput(webhookMessage MessageCard, webhookURL string) (bool, error)
IsValidInput is a validation "wrapper" function. This function is intended to run current validation checks and offer easy extensibility for future validation requirements.
func IsValidMessageCard ¶
func IsValidMessageCard(webhookMessage MessageCard) (bool, error)
IsValidMessageCard performs validation/checks for known issues with MessardCard values.
func IsValidWebhookURL ¶
IsValidWebhookURL performs validation checks on the webhook URL used to submit messages to Microsoft Teams.
Types ¶
type API ¶
type API interface {
Send(webhookURL string, webhookMessage MessageCard) error
}
API - interface of MS Teams notify
type MessageCard ¶
type MessageCard struct { // Required; must be set to "MessageCard" Type string `json:"@type"` // Required; must be set to "https://schema.org/extensions" Context string `json:"@context"` // Summary is required if the card does not contain a text property, // otherwise optional. The summary property is typically displayed in the // list view in Outlook, as a way to quickly determine what the card is // all about. Summary appears to only be used when there are sections defined Summary string `json:"summary,omitempty"` // Title is the title property of a card. is meant to be rendered in a // prominent way, at the very top of the card. Use it to introduce the // content of the card in such a way users will immediately know what to // expect. Title string `json:"title,omitempty"` // Text is required if the card does not contain a summary property, // otherwise optional. The text property is meant to be displayed in a // normal font below the card's title. Use it to display content, such as // the description of the entity being referenced, or an abstract of a // news article. Text string `json:"text,omitempty"` // Specifies a custom brand color for the card. The color will be // displayed in a non-obtrusive manner. ThemeColor string `json:"themeColor,omitempty"` // Sections is a collection of sections to include in the card. Sections []*MessageCardSection `json:"sections,omitempty"` }
MessageCard represents a legacy actionable message card used via Office 365 or Microsoft Teams connectors.
func NewMessageCard ¶
func NewMessageCard() MessageCard
NewMessageCard creates a new message card with fields required by the legacy message card format already predefined
func (*MessageCard) AddSection ¶
func (mc *MessageCard) AddSection(section ...*MessageCardSection) error
AddSection adds one or many additional MessageCardSection values to a MessageCard. Validation is performed to reject invalid values with an error message.
type MessageCardSection ¶
type MessageCardSection struct { // Title is the title property of a section. This property is displayed // in a font that stands out, while not as prominent as the card's title. // It is meant to introduce the section and summarize its content, // similarly to how the card's title property is meant to summarize the // whole card. Title string `json:"title,omitempty"` // Text is the section's text property. This property is very similar to // the text property of the card. It can be used for the same purpose. Text string `json:"text,omitempty"` // ActivityImage is a property used to display a picture associated with // the subject of a message card. For example, this might be the portrait // of a person who performed an activity that the message card is // associated with. ActivityImage string `json:"activityImage,omitempty"` // ActivityTitle is a property used to summarize the activity associated // with a message card. ActivityTitle string `json:"activityTitle,omitempty"` // ActivitySubtitle is a property used to show brief, but extended // information about an activity associated with a message card. Examples // include the date and time the associated activity was taken or the // handle of a person associated with the activity. ActivitySubtitle string `json:"activitySubtitle,omitempty"` // ActivityText is a property used to provide details about the activity. // For example, if the message card is used to deliver updates about a // topic, then this property would be used to hold the bulk of the content // for the update notification. ActivityText string `json:"activityText,omitempty"` // Markdown represents a toggle to enable or disable Markdown formatting. // By default, all text fields in a card and its sections can be formatted // using basic Markdown. Markdown bool `json:"markdown,omitempty"` // StartGroup is the section's startGroup property. This property marks // the start of a logical group of information. Typically, sections with // startGroup set to true will be visually separated from previous card // elements. StartGroup bool `json:"startGroup,omitempty"` // HeroImage is a property that allows for setting an image as the // centerpiece of a message card. This property can also be used to add a // banner to the message card. // Note: heroImage is not currently supported by Microsoft Teams // https://stackoverflow.com/a/45389789 // We use a pointer to this type in order to have the json package // properly omit this field if not explicitly set. // https://github.com/golang/go/issues/11939 // https://stackoverflow.com/questions/18088294/how-to-not-marshal-an-empty-struct-into-json-with-go // https://stackoverflow.com/questions/33447334/golang-json-marshal-how-to-omit-empty-nested-struct HeroImage *MessageCardSectionImage `json:"heroImage,omitempty"` // Facts is a collection of MessageCardSectionFact values. A section entry // usually is displayed in a two-column key/value format. Facts []MessageCardSectionFact `json:"facts,omitempty"` // Images is a property that allows for the inclusion of a photo gallery // inside a section. // We use a slice of pointers to this type in order to have the json // package properly omit this field if not explicitly set. // https://github.com/golang/go/issues/11939 // https://stackoverflow.com/questions/18088294/how-to-not-marshal-an-empty-struct-into-json-with-go // https://stackoverflow.com/questions/33447334/golang-json-marshal-how-to-omit-empty-nested-struct Images []*MessageCardSectionImage `json:"images,omitempty"` }
MessageCardSection represents a section to include in a message card.
func NewMessageCardSection ¶
func NewMessageCardSection() *MessageCardSection
NewMessageCardSection creates an empty message card section
func (*MessageCardSection) AddFact ¶
func (mcs *MessageCardSection) AddFact(fact ...MessageCardSectionFact) error
AddFact adds one or many additional MessageCardSectionFact values to a MessageCardSection
func (*MessageCardSection) AddFactFromKeyValue ¶
func (mcs *MessageCardSection) AddFactFromKeyValue(key string, values ...string) error
AddFactFromKeyValue accepts a key and slice of values and converts them to MessageCardSectionFact values
func (*MessageCardSection) AddHeroImage ¶
func (mcs *MessageCardSection) AddHeroImage(heroImage MessageCardSectionImage) error
AddHeroImage adds a Hero Image to a MessageCard section using a MessageCardSectionImage argument. This image is used as the centerpiece or banner of a message card.
func (*MessageCardSection) AddHeroImageStr ¶
func (mcs *MessageCardSection) AddHeroImageStr(imageURL string, imageTitle string) error
AddHeroImageStr adds a Hero Image to a MessageCard section using string arguments. This image is used as the centerpiece or banner of a message card.
func (*MessageCardSection) AddImage ¶
func (mcs *MessageCardSection) AddImage(sectionImage ...MessageCardSectionImage) error
AddImage adds an image to a MessageCard section. These images are used to provide a photo gallery inside a MessageCard section.
type MessageCardSectionFact ¶
type MessageCardSectionFact struct { // Name is the key for an associated value in a key/value pair Name string `json:"name"` // Value is the value for an associated key in a key/value pair Value string `json:"value"` }
MessageCardSectionFact represents a section fact entry that is usually displayed in a two-column key/value format.
func NewMessageCardSectionFact ¶
func NewMessageCardSectionFact() MessageCardSectionFact
NewMessageCardSectionFact creates an empty message card section fact
type MessageCardSectionImage ¶
type MessageCardSectionImage struct { // Image is the URL to the image. Image string `json:"image"` // Title is a short description of the image. Typically, this description // is displayed in a tooltip as the user hovers their mouse over the // image. Title string `json:"title"` }
MessageCardSectionImage represents an image as used by the heroImage and images properties of a section.
func NewMessageCardSectionImage ¶
func NewMessageCardSectionImage() MessageCardSectionImage
NewMessageCardSectionImage creates an empty image for use with message card section