goteamsnotify

package module
v2.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2024 License: MIT Imports: 14 Imported by: 57

README

goteamsnotify

A package to send messages to a Microsoft Teams channel.

Latest release Go Reference License go.mod Go version Lint and Build Project Analysis

Table of contents

Project home

See our GitHub repo for the latest code, to file an issue or submit improvements for review and potential inclusion into the project.

Overview

The goteamsnotify package (aka, go-teams-notify) allows sending messages to a Microsoft Teams channel. These messages can be composed of legacy MessageCard or Adaptive Card card formats.

Simple messages can be created by specifying only a title and a text body. More complex messages may be composed of multiple sections (MessageCard) or containers (Adaptive Card), key/value pairs (aka, Facts) and externally hosted images. See the Features list for more information.

NOTE: Adaptive Card support is currently limited. The goal is to expand this support in future releases to include additional features supported by Microsoft Teams.

Features

  • Submit simple or complex messages to Microsoft Teams
    • simple messages consist of only a title and a text body (one or more strings)
    • complex messages may consist of multiple sections (MessageCard), containers (Adaptive Card) key/value pairs (aka, Facts) and externally hosted images
  • Support for Actions, allowing users to take quick actions within Microsoft Teams
  • Support for user mentions (Adaptive Card format)
  • Configurable validation of webhook URLs
    • enabled by default, attempts to match most common known webhook URL patterns
    • option to disable validation entirely
    • option to use custom validation patterns
  • Configurable validation of MessageCard type
    • default assertion that bare-minimum required fields are present
    • support for providing a custom validation function to override default validation behavior
  • Configurable validation of Adaptive Card type
    • default assertion that bare-minimum required fields are present
    • support for providing a custom validation function to override default validation behavior
  • Configurable timeouts
  • Configurable retry support

Project Status

In short:

  • The upstream project is no longer being actively developed or maintained.
  • This fork is now a standalone project, accepting contributions, bug reports and feature requests.
  • Others have also taken an interest in maintaining their own forks of the original project. See those forks for other ideas/changes that you may find useful.

For more details, see the Releases section or our Changelog.

Supported Releases

Series Example Status
v1.x.x v1.3.1 Not Supported (EOL)
v2.x.x v2.6.0 Supported
v3.x.x v3.0.0-alpha.1 TBD

The current plan is to continue extending the v2 branch with new functionality while retaining backwards compatibility. Any breakage in compatibility for the v2 series is considered a bug (please report it).

Long-term, the goal is to learn from missteps made in current releases and correct as many as possible for a future v3 series.

Changelog

See the CHANGELOG.md file for the changes associated with each release of this application. Changes that have been merged to master, but not yet an official release may also be noted in the file under the Unreleased section. A helpful link to the Git commit history since the last official release is also provided for further review.

Usage

Add this project as a dependency

See the Examples section for more details.

Webhook URLs
Expected format

Valid webhook URLs for Microsoft Teams use one of several (confirmed) FQDNs patterns:

  • outlook.office.com
  • outlook.office365.com
  • *.webhook.office.com
    • e.g., example.webhook.office.com

Using a webhook URL with any of these FQDN patterns appears to give identical results.

Here are complete, equivalent example webhook URLs from Microsoft's documentation using the FQDNs above:

All of these patterns when provided to this library should pass the default validation applied. See the example further down for the option of disabling webhook URL validation entirely.

How to create a webhook URL (Connector)
  1. Open Microsoft Teams
  2. Navigate to the channel where you wish to receive incoming messages from this application
  3. Select next to the channel name and then choose Connectors.
  4. Scroll through the list of Connectors to Incoming Webhook, and choose Add.
  5. Enter a name for the webhook, upload an image to associate with data from the webhook, and choose Create.
  6. Copy the webhook URL to the clipboard and save it. You'll need the webhook URL for sending information to Microsoft Teams.
    • NOTE: While you can create another easily enough, you should treat this webhook URL as sensitive information as anyone with this unique URL is able to send messages (without authentication) into the associated channel.
  7. Choose Done.

Credit: docs.microsoft.com, gist comment from shadabacc3934

Examples
Basic

This is an example of a simple client application which uses this library.

  • Adaptive Card
  • MessageCard
Specify proxy server

This is an example of a simple client application which uses this library to route a generated message through a specified proxy server.

  • Adaptive Card
  • MessageCard
User Mention

These examples illustrates the use of one or more user mentions. This feature is not available in the legacy MessageCard card format.

Tables

These examples illustrates the use of a Table. This feature is not available in the legacy MessageCard card format.

Set custom user agent

This example illustrates setting a custom user agent.

Add an Action

This example illustrates adding an OpenUri (MessageCard) or OpenUrl Action. When used, this action triggers opening a URL in a separate browser or application.

Toggle visibility

These examples illustrates using ToggleVisibility Actions to control the visibility of various Elements of an Adaptive Card message.

Disable webhook URL prefix validation

This example disables the validation webhook URLs, including the validation of known prefixes so that custom/private webhook URL endpoints can be used (e.g., testing purposes).

Enable custom patterns' validation

This example demonstrates how to enable custom validation patterns for webhook URLs.

Used by

See the Known importers lists below for a dynamically updated list of projects using either this library or the original project.

References

Documentation

Overview

Package goteamsnotify is used to send messages to a Microsoft Teams channel.

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

  • Submit messages to Microsoft Teams consisting of one or more sections, Facts (key/value pairs), Actions or images (hosted externally)
  • Support for MessageCard and Adaptive Card messages
  • Support for Actions, allowing users to take quick actions within Microsoft Teams
  • Support for user mentions
  • Configurable validation
  • Configurable timeouts
  • Configurable retry support
  • Support for overriding the default http.Client
  • Support for overriding the default project-specific user agent

Usage

See our main README for supported settings and examples.

Index

Constants

View Source
const (
	// PotentialActionOpenURIType is the type that must be used for OpenUri
	// potential action.
	//
	// Deprecated: use messagecard.PotentialActionOpenURIType instead.
	PotentialActionOpenURIType = "OpenUri"

	// PotentialActionHTTPPostType is the type that must be used for HttpPOST
	// potential action.
	//
	// Deprecated: use messagecard.PotentialActionHTTPPostType instead.
	PotentialActionHTTPPostType = "HttpPOST"

	// PotentialActionActionCardType is the type that must be used for
	// ActionCard potential action.
	//
	// Deprecated: use messagecard.PotentialActionActionCardType instead.
	PotentialActionActionCardType = "ActionCard"

	// PotentialActionInvokeAddInCommandType is the type that must be used for
	// InvokeAddInCommand potential action.
	//
	// Deprecated: use messagecard.PotentialActionInvokeAddInCommandType
	// instead.
	PotentialActionInvokeAddInCommandType = "InvokeAddInCommand"

	// PotentialActionActionCardInputTextInputType is the type that must be
	// used for ActionCard TextInput type.
	//
	// Deprecated: use messagecard.PotentialActionActionCardInputTextInputType
	// instead.
	PotentialActionActionCardInputTextInputType = "TextInput"

	// PotentialActionActionCardInputDateInputType is the type that must be
	// used for ActionCard DateInput type.
	//
	// Deprecated: use messagecard.PotentialActionActionCardInputDateInputType
	// instead.
	PotentialActionActionCardInputDateInputType = "DateInput"

	// PotentialActionActionCardInputMultichoiceInput is the type that must be
	// used for ActionCard MultichoiceInput type.
	//
	// Deprecated: use
	// messagecard.PotentialActionActionCardInputMultichoiceInputType instead.
	PotentialActionActionCardInputMultichoiceInput = "MultichoiceInput"
)
View Source
const (
	WebhookURLOfficecomPrefix  = "https://outlook.office.com"
	WebhookURLOffice365Prefix  = "https://outlook.office365.com"
	WebhookURLOrgWebhookPrefix = "https://example.webhook.office.com"
)

Known webhook URL prefixes for submitting messages to Microsoft Teams

View Source
const DefaultUserAgent string = "go-teams-notify/2.2"

DefaultUserAgent is the project-specific user agent used when submitting messages unless overridden by client code. This replaces the Go default user agent value of "Go-http-client/1.1".

The major.minor numbers reflect when this project first diverged from the "upstream" or parent project.

View Source
const DefaultWebhookSendTimeout = 5 * time.Second

DefaultWebhookSendTimeout specifies how long the message operation may take before it times out and is cancelled.

View Source
const (

	// DefaultWebhookURLValidationPattern is a minimal regex for matching known valid
	// webhook URL prefix patterns.
	DefaultWebhookURLValidationPattern = `^https:\/\/(?:.*\.webhook|outlook)\.office(?:365)?\.com`
)

Regular Expression related constants that we can use to validate incoming webhook URLs provided by the user.

View Source
const DisableWebhookURLValidation string = "DISABLE_WEBHOOK_URL_VALIDATION"

DisableWebhookURLValidation is a special keyword used to indicate to validation function(s) that webhook URL validation should be disabled.

Deprecated: prefer using API.SkipWebhookURLValidationOnSend(bool) method instead

View Source
const ExpectedWebhookURLResponseText string = "1"

ExpectedWebhookURLResponseText represents the expected response text provided by the remote webhook endpoint when submitting messages.

View Source
const PotentialActionMaxSupported = 4

PotentialActionMaxSupported is the maximum number of actions allowed in a MessageCardPotentialAction collection.

https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference#actions

Deprecated: use messagecard.PotentialActionMaxSupported instead.

Variables

View Source
var ErrInvalidWebhookURLResponseText = errors.New("invalid webhook URL response text")

ErrInvalidWebhookURLResponseText is returned when the remote webhook endpoint indicates via response text that a message submission was unsuccessful.

View Source
var ErrPotentialActionsLimitReached = errors.New("potential actions collection limit reached")

ErrPotentialActionsLimitReached indicates that the maximum supported number of potentialAction collection values has been reached for either a MessageCard or a MessageCardSection.

Deprecated: use messagecard.ErrPotentialActionsLimitReached instead.

View Source
var ErrWebhookURLUnexpected = errors.New("webhook URL does not match one of expected patterns")

ErrWebhookURLUnexpected is returned when a provided webhook URL does not match a set of confirmed webhook URL patterns.

View Source
var ErrWebhookURLUnexpectedPrefix = ErrWebhookURLUnexpected

ErrWebhookURLUnexpectedPrefix is returned when a provided webhook URL does not match a set of confirmed webhook URL prefixes.

Deprecated: Use ErrWebhookURLUnexpected instead.

Functions

func ConvertEOLToBreak deprecated added in v2.2.0

func ConvertEOLToBreak(s string) string

ConvertEOLToBreak converts \r\n (windows), \r (mac) and \n (unix) into <br> statements.

This function is intended for processing text intended for a MessageCard. Using this helper function for text intended for an Adaptive Card is unsupported and unlikely to produce the desired results.

Deprecated: use messagecard.ConvertEOLToBreak instead.

func DisableLogging added in v2.2.0

func DisableLogging()

DisableLogging reapplies default package-level logging settings of muting all logging output.

func EnableLogging added in v2.2.0

func EnableLogging()

EnableLogging enables logging output from this package. Output is muted by default unless explicitly requested (by calling this function).

func FormatAsCodeBlock deprecated added in v2.2.0

func FormatAsCodeBlock(input string) (string, error)

FormatAsCodeBlock accepts an arbitrary string, quoted or not, and calls a helper function which attempts to format as a valid Markdown code block for submission to Microsoft Teams.

This function is intended for processing text intended for a MessageCard. Using this helper function for text intended for an Adaptive Card is unsupported and unlikely to produce the desired results.

Deprecated: use messagecard.FormatAsCodeBlock instead.

func FormatAsCodeSnippet deprecated added in v2.2.0

func FormatAsCodeSnippet(input string) (string, error)

FormatAsCodeSnippet accepts an arbitrary string, quoted or not, and calls a helper function which attempts to format as a single-line valid Markdown code snippet for submission to Microsoft Teams.

This function is intended for processing text intended for a MessageCard. Using this helper function for text intended for an Adaptive Card is unsupported and unlikely to produce the desired results.

Deprecated: use messagecard.FormatAsCodeSnippet instead.

func InList added in v2.7.0

func InList(needle string, haystack []string, ignoreCase bool) bool

InList is a helper function to emulate Python's `if "x" in list:` functionality. The caller can optionally ignore case of compared items.

func IsValidInput deprecated

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.

Deprecated: use API.ValidateWebhook() and MessageCard.Validate() methods instead.

func IsValidMessageCard deprecated

func IsValidMessageCard(webhookMessage MessageCard) (bool, error)

IsValidMessageCard performs validation/checks for known issues with MessardCard values.

Deprecated: use MessageCard.Validate() instead.

func IsValidWebhookURL deprecated

func IsValidWebhookURL(webhookURL string) (bool, error)

IsValidWebhookURL performs validation checks on the webhook URL used to submit messages to Microsoft Teams.

Deprecated: use API.ValidateWebhook() method instead.

func TryToFormatAsCodeBlock deprecated added in v2.2.0

func TryToFormatAsCodeBlock(input string) string

TryToFormatAsCodeBlock acts as a wrapper for FormatAsCodeBlock. If an error is encountered in the FormatAsCodeBlock function, this function will return the original string, otherwise if no errors occur the newly formatted string will be returned.

This function is intended for processing text intended for a MessageCard. Using this helper function for text intended for an Adaptive Card is unsupported and unlikely to produce the desired results.

Deprecated: use messagecard.TryToFormatAsCodeBlock instead.

func TryToFormatAsCodeSnippet deprecated added in v2.2.0

func TryToFormatAsCodeSnippet(input string) string

TryToFormatAsCodeSnippet acts as a wrapper for FormatAsCodeSnippet. If an error is encountered in the FormatAsCodeSnippet function, this function will return the original string, otherwise if no errors occur the newly formatted string will be returned.

This function is intended for processing text intended for a MessageCard. Using this helper function for text intended for an Adaptive Card is unsupported and unlikely to produce the desired results.

Deprecated: use messagecard.TryToFormatAsCodeSnippet instead.

Types

type API

type API interface {
	Send(webhookURL string, webhookMessage MessageCard) error
	SendWithContext(ctx context.Context, webhookURL string, webhookMessage MessageCard) error
	SendWithRetry(ctx context.Context, webhookURL string, webhookMessage MessageCard, retries int, retriesDelay int) error
	SkipWebhookURLValidationOnSend(skip bool) API
	AddWebhookURLValidationPatterns(patterns ...string) API
	ValidateWebhook(webhookURL string) error
}

API is the legacy interface representing a client used to submit messages to a Microsoft Teams channel.

func NewClient deprecated

func NewClient() API

NewClient - create a brand new client for MS Teams notify

Deprecated: use NewTeamsClient() function instead.

type MessageCard deprecated

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"`

	// ValidateFunc is a validation function that validates a MessageCard
	ValidateFunc func() error `json:"-"`

	// Sections is a collection of sections to include in the card.
	Sections []*MessageCardSection `json:"sections,omitempty"`

	// PotentialActions is a collection of actions for a MessageCard.
	PotentialActions []*MessageCardPotentialAction `json:"potentialAction,omitempty"`
	// contains filtered or unexported fields
}

MessageCard represents a legacy actionable message card used via Office 365 or Microsoft Teams connectors.

Deprecated: use messagecard.MessageCard instead.

func NewMessageCard deprecated

func NewMessageCard() MessageCard

NewMessageCard creates a new message card with fields required by the legacy message card format already predefined.

Deprecated: use messagecard.NewMessageCard instead.

func (*MessageCard) AddPotentialAction deprecated added in v2.6.0

func (mc *MessageCard) AddPotentialAction(actions ...*MessageCardPotentialAction) error

AddPotentialAction adds one or many MessageCardPotentialAction values to a PotentialActions collection on a MessageCard.

Deprecated: use (messagecard.MessageCard).AddPotentialAction instead.

func (*MessageCard) AddSection deprecated

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.

Deprecated: use (messagecard.MessageCard).AddSection instead.

func (*MessageCard) Payload deprecated added in v2.7.0

func (mc *MessageCard) Payload() io.Reader

Payload returns the prepared MessageCard payload. The caller should call Prepare() prior to calling this method, results are undefined otherwise.

Deprecated: use (messagecard.MessageCard).Payload instead.

func (*MessageCard) Prepare deprecated added in v2.7.0

func (mc *MessageCard) Prepare() error

Prepare handles tasks needed to construct a payload from a MessageCard for delivery to an endpoint.

Deprecated: use (messagecard.MessageCard).Prepare instead.

func (*MessageCard) PrettyPrint deprecated added in v2.7.0

func (mc *MessageCard) PrettyPrint() string

PrettyPrint returns a formatted JSON payload of the MessageCard if the Prepare() method has been called, or an empty string otherwise.

Deprecated: use (messagecard.MessageCard).PrettyPrint instead.

func (*MessageCard) Validate deprecated added in v2.5.0

func (mc *MessageCard) Validate() error

Validate validates a MessageCard calling ValidateFunc if defined, otherwise, a default validation occurs.

Deprecated: use (messagecard.MessageCard).Validate instead.

type MessageCardPotentialAction deprecated added in v2.6.0

type MessageCardPotentialAction struct {
	// Type of the potential action. Can be OpenUri, HttpPOST, ActionCard or
	// InvokeAddInCommand.
	Type string `json:"@type"`

	// Name property defines the text that will be displayed on screen for the
	// action.
	Name string `json:"name"`

	// MessageCardPotentialActionOpenURI is a set of options for openUri
	// potential action.
	MessageCardPotentialActionOpenURI

	// MessageCardPotentialActionHTTPPOST is a set of options for httpPOST
	// potential action.
	MessageCardPotentialActionHTTPPOST

	// MessageCardPotentialActionActionCard is a set of options for actionCard
	// potential action.
	MessageCardPotentialActionActionCard

	// MessageCardPotentialActionInvokeAddInCommand is a set of options for
	// invokeAddInCommand potential action.
	MessageCardPotentialActionInvokeAddInCommand
}

MessageCardPotentialAction represents potential actions an user can do in a message card. See Legacy actionable message card reference > Actions for more information.

Deprecated: use messagecard.PotentialAction instead.

func NewMessageCardPotentialAction deprecated added in v2.6.0

func NewMessageCardPotentialAction(potentialActionType string, name string) (*MessageCardPotentialAction, error)

NewMessageCardPotentialAction creates a new MessageCardPotentialAction using the provided potential action type and name. The name value defines the text that will be displayed on screen for the action. An error is returned if invalid values are supplied.

Deprecated: use messagecard.NewMessageCardPotentialAction instead.

type MessageCardPotentialActionActionCard deprecated added in v2.6.0

type MessageCardPotentialActionActionCard struct {
	// Inputs is a collection of inputs an user can provide before processing
	// the actions. Only used for ActionCard action type. Three types of
	// inputs are available: TextInput, DateInput and MultichoiceInput
	Inputs []MessageCardPotentialActionActionCardInput `json:"inputs,omitempty"`

	// Actions are the available actions. Only used for ActionCard action
	// type.
	Actions []MessageCardPotentialActionActionCardAction `json:"actions,omitempty"`
}

MessageCardPotentialActionActionCard represents an actionCard potential action.

Deprecated: use messagecard.PotentialActionActionCard instead.

type MessageCardPotentialActionActionCardAction deprecated added in v2.6.0

type MessageCardPotentialActionActionCardAction struct {
	// Type of the action. Can be OpenUri, HttpPOST, ActionCard or
	// InvokeAddInCommand.
	Type string `json:"@type"`

	// Name property defines the text that will be displayed on screen for the
	// action.
	Name string `json:"name"`

	// MessageCardPotentialActionOpenURI is used to specify a openUri action
	// card's action.
	MessageCardPotentialActionOpenURI

	// MessageCardPotentialActionHTTPPOST is used to specify a httpPOST action
	// card's action.
	MessageCardPotentialActionHTTPPOST
}

MessageCardPotentialActionActionCardAction is used for configuring ActionCard actions.

Deprecated: use messagecard.PotentialActionActionCardAction instead.

type MessageCardPotentialActionActionCardInput deprecated added in v2.6.0

type MessageCardPotentialActionActionCardInput struct {
	// Type of the ActionCard input.
	// Must be either TextInput, DateInput or MultichoiceInput
	Type string `json:"@type"`

	// ID uniquely identifies the input so it is possible to reference it in
	// the URL or body of an HttpPOST action.
	ID string `json:"id,omitempty"`

	// Title defines a title for the input.
	Title string `json:"title,omitempty"`

	// Value defines the initial value of the input. For multi-choice inputs,
	// value must be equal to the value property of one of the input's
	// choices.
	Value string `json:"value,omitempty"`

	// MessageCardPotentialActionInputMultichoiceInput must be defined for
	// MultichoiceInput input type.
	MessageCardPotentialActionActionCardInputMultichoiceInput

	// MessageCardPotentialActionInputTextInput must be defined for InputText
	// input type.
	MessageCardPotentialActionActionCardInputTextInput

	// MessageCardPotentialActionInputDateInput must be defined for DateInput
	// input type.
	MessageCardPotentialActionActionCardInputDateInput

	// IsRequired indicates whether users are required to type a value before
	// they are able to take an action that would take the value of the input
	// as a parameter.
	IsRequired bool `json:"isRequired,omitempty"`
}

MessageCardPotentialActionActionCardInput represents an ActionCard input.

Deprecated: use messagecard.PotentialActionActionCardInput instead.

type MessageCardPotentialActionActionCardInputDateInput deprecated added in v2.6.0

type MessageCardPotentialActionActionCardInputDateInput struct {
	// IncludeTime indicates whether the date input should allow for the
	// selection of a time in addition to the date.
	IncludeTime bool `json:"includeTime,omitempty"`
}

MessageCardPotentialActionActionCardInputDateInput represents a DateInput input used for potential action.

Deprecated: use messagecard.PotentialActionActionCardInputDateInput instead.

type MessageCardPotentialActionActionCardInputMultichoiceInput deprecated added in v2.6.0

type MessageCardPotentialActionActionCardInputMultichoiceInput struct {
	// Choices defines the values that can be selected for the multichoice
	// input.
	Choices []struct {
		Display string `json:"display,omitempty"`
		Value   string `json:"value,omitempty"`
	} `json:"choices,omitempty"`

	// Style defines the style of the input. When IsMultiSelect is false,
	// setting the style property to expanded will instruct the host
	// application to try and display all choices on the screen, typically
	// using a set of radio buttons.
	Style string `json:"style,omitempty"`

	// IsMultiSelect indicates whether or not the user can select more than
	// one choice. The specified choices will be displayed as a list of
	// checkboxes. Default value is false.
	IsMultiSelect bool `json:"isMultiSelect,omitempty"`
}

MessageCardPotentialActionActionCardInputMultichoiceInput represents a MultichoiceInput input used for potential action.

Deprecated: use messagecard.PotentialActionActionCardInputMultichoiceInput instead.

type MessageCardPotentialActionActionCardInputTextInput deprecated added in v2.6.0

type MessageCardPotentialActionActionCardInputTextInput struct {
	// MaxLength indicates the maximum number of characters that can be
	// entered.
	MaxLength int `json:"maxLength,omitempty"`

	// IsMultiline indicates whether the text input should accept multiple
	// lines of text.
	IsMultiline bool `json:"isMultiline,omitempty"`
}

MessageCardPotentialActionActionCardInputTextInput represents a TextInput input used for potential action.

Deprecated: use messagecard.PotentialActionActionCardInputTextInput instead.

type MessageCardPotentialActionHTTPPOST deprecated added in v2.6.0

type MessageCardPotentialActionHTTPPOST struct {
	// Target defines the URL endpoint of the service that implements the
	// action. Only used for HttpPOST action type.
	Target string `json:"target,omitempty"`

	// Headers is a collection of MessageCardPotentialActionHeader objects
	// representing a set of HTTP headers that will be emitted when sending
	// the POST request to the target URL. Only used for HttpPOST action type.
	Headers []MessageCardPotentialActionHTTPPOSTHeader `json:"headers,omitempty"`

	// Body is the body of the POST request. Only used for HttpPOST action
	// type.
	Body string `json:"body,omitempty"`

	// BodyContentType is optional and specifies the MIME type of the body in
	// the POST request. Only used for HttpPOST action type.
	BodyContentType string `json:"bodyContentType,omitempty"`
}

MessageCardPotentialActionHTTPPOST represents a HttpPOST potential action.

Deprecated: use messagecard.PotentialActionHTTPPOST instead.

type MessageCardPotentialActionHTTPPOSTHeader deprecated added in v2.6.0

type MessageCardPotentialActionHTTPPOSTHeader struct {
	// Name is the header name.
	Name string `json:"name,omitempty"`

	// Value is the header value.
	Value string `json:"value,omitempty"`
}

MessageCardPotentialActionHTTPPOSTHeader defines a HTTP header used for HttpPOST action type.

Deprecated: use messagecard.PotentialActionHTTPPOSTHeader instead.

type MessageCardPotentialActionInvokeAddInCommand deprecated added in v2.6.0

type MessageCardPotentialActionInvokeAddInCommand struct {
	// AddInID specifies the add-in ID of the required add-in. Only used for
	// InvokeAddInCommand action type.
	AddInID string `json:"addInId,omitempty"`

	// DesktopCommandID specifies the ID of the add-in command button that
	// opens the required task pane. Only used for InvokeAddInCommand action
	// type.
	DesktopCommandID string `json:"desktopCommandId,omitempty"`

	// InitializationContext is an optional field which provides developers a
	// way to specify any valid JSON object. The value is serialized into a
	// string and made available to the add-in when the action is executed.
	// This allows the action to pass initialization data to the add-in. Only
	// used for InvokeAddInCommand action type.
	InitializationContext interface{} `json:"initializationContext,omitempty"`
}

MessageCardPotentialActionInvokeAddInCommand represents an invokeAddInCommand potential action.

Deprecated: use messagecard.PotentialActionInvokeAddInCommand instead.

type MessageCardPotentialActionOpenURI deprecated added in v2.6.0

type MessageCardPotentialActionOpenURI struct {
	// Targets is a collection of name/value pairs that defines one URI per
	// target operating system. Only used for OpenUri action type.
	Targets []MessageCardPotentialActionOpenURITarget `json:"targets,omitempty"`
}

MessageCardPotentialActionOpenURI represents a OpenUri potential action.

Deprecated: use messagecard.PotentialActionOpenURI instead.

type MessageCardPotentialActionOpenURITarget deprecated added in v2.6.0

type MessageCardPotentialActionOpenURITarget struct {
	// OS defines the operating system the target uri refers to. Supported
	// operating system values are default, windows, iOS and android. The
	// default operating system will in most cases simply open the URI in a
	// web browser, regardless of the actual operating system.
	OS string `json:"os,omitempty"`

	// URI defines the URI being called.
	URI string `json:"uri,omitempty"`
}

MessageCardPotentialActionOpenURITarget is used for OpenUri action type. It defines one URI per target operating system.

Deprecated: use messagecard.PotentialActionOpenURITarget instead.

type MessageCardSection deprecated

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"`

	// 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"`

	// PotentialActions is a collection of actions for a MessageCardSection.
	// This is separate from the actions collection for the MessageCard.
	PotentialActions []*MessageCardPotentialAction `json:"potentialAction,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"`
}

MessageCardSection represents a section to include in a message card.

Deprecated: use messagecard.Section instead.

func NewMessageCardSection deprecated

func NewMessageCardSection() *MessageCardSection

NewMessageCardSection creates an empty message card section.

Deprecated: use messagecard.NewMessageCardSection instead.

func (*MessageCardSection) AddFact deprecated

func (mcs *MessageCardSection) AddFact(fact ...MessageCardSectionFact) error

AddFact adds one or many additional MessageCardSectionFact values to a MessageCardSection.

Deprecated: use (messagecard.Section).AddFact instead.

func (*MessageCardSection) AddFactFromKeyValue deprecated

func (mcs *MessageCardSection) AddFactFromKeyValue(key string, values ...string) error

AddFactFromKeyValue accepts a key and slice of values and converts them to MessageCardSectionFact values.

Deprecated: use (messagecard.Section).AddFactFromKeyValue instead.

func (*MessageCardSection) AddHeroImage deprecated

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.

Deprecated: use (messagecard.Section).AddHeroImage instead.

func (*MessageCardSection) AddHeroImageStr deprecated

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.

Deprecated: use (messagecard.Section).AddHeroImageStr instead.

func (*MessageCardSection) AddImage deprecated

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.

Deprecated: use (messagecard.Section).AddImage instead.

func (*MessageCardSection) AddPotentialAction deprecated added in v2.6.0

func (mcs *MessageCardSection) AddPotentialAction(actions ...*MessageCardPotentialAction) error

AddPotentialAction adds one or many MessageCardPotentialAction values to a PotentialActions collection on a MessageCardSection. This is separate from the actions collection for the MessageCard.

Deprecated: use (messagecard.Section).AddPotentialAction instead.

type MessageCardSectionFact deprecated

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.

Deprecated: use messagecard.SectionFact instead.

func NewMessageCardSectionFact deprecated

func NewMessageCardSectionFact() MessageCardSectionFact

NewMessageCardSectionFact creates an empty message card section fact.

Deprecated: use messagecard.NewMessageCardSectionFact instead.

type MessageCardSectionImage deprecated

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.

Deprecated: use messagecard.SectionImage instead.

func NewMessageCardSectionImage deprecated

func NewMessageCardSectionImage() MessageCardSectionImage

NewMessageCardSectionImage creates an empty image for use with message card section.

Deprecated: use messagecard.NewMessageCardSectionImage instead.

type MessageSender added in v2.7.0

type MessageSender interface {
	HTTPClient() *http.Client
	UserAgent() string
	ValidateWebhook(webhookURL string) error
	// contains filtered or unexported methods
}

MessageSender describes the behavior of a baseline Microsoft Teams client.

An unexported method is used to prevent client code from implementing this interface in order to support future changes (and not violate backwards compatibility).

type TeamsClient added in v2.7.0

type TeamsClient struct {
	// contains filtered or unexported fields
}

TeamsClient provides functionality for submitting messages to a Microsoft Teams channel.

func NewTeamsClient added in v2.7.0

func NewTeamsClient() *TeamsClient

NewTeamsClient constructs a minimal client for submitting messages to a Microsoft Teams channel.

func (*TeamsClient) AddWebhookURLValidationPatterns added in v2.7.0

func (c *TeamsClient) AddWebhookURLValidationPatterns(patterns ...string) *TeamsClient

AddWebhookURLValidationPatterns collects given patterns for validation of the webhook URL.

func (*TeamsClient) HTTPClient added in v2.7.0

func (c *TeamsClient) HTTPClient() *http.Client

HTTPClient returns the internal pointer to an http.Client. This can be used to further modify specific http.Client field values.

func (*TeamsClient) Send added in v2.7.0

func (c *TeamsClient) Send(webhookURL string, message teamsMessage) error

Send is a wrapper function around the SendWithContext method in order to provide backwards compatibility.

func (*TeamsClient) SendWithContext added in v2.7.0

func (c *TeamsClient) SendWithContext(ctx context.Context, webhookURL string, message teamsMessage) error

SendWithContext submits a given message to a Microsoft Teams channel using the provided webhook URL. The http client request honors the cancellation or timeout of the provided context.

func (*TeamsClient) SendWithRetry added in v2.7.0

func (c *TeamsClient) SendWithRetry(ctx context.Context, webhookURL string, message teamsMessage, retries int, retriesDelay int) error

SendWithRetry provides message retry support when submitting messages to a Microsoft Teams channel. The caller is responsible for providing the desired context timeout, the number of retries and retries delay.

func (*TeamsClient) SetHTTPClient added in v2.7.0

func (c *TeamsClient) SetHTTPClient(httpClient *http.Client) *TeamsClient

SetHTTPClient accepts a custom http.Client value which replaces the existing default http.Client.

func (*TeamsClient) SetUserAgent added in v2.7.0

func (c *TeamsClient) SetUserAgent(userAgent string) *TeamsClient

SetUserAgent accepts a custom user agent string. This custom user agent is used when submitting messages to Microsoft Teams.

func (*TeamsClient) SkipWebhookURLValidationOnSend added in v2.7.0

func (c *TeamsClient) SkipWebhookURLValidationOnSend(skip bool) *TeamsClient

SkipWebhookURLValidationOnSend allows the caller to optionally disable webhook URL validation.

func (*TeamsClient) UserAgent added in v2.7.0

func (c *TeamsClient) UserAgent() string

UserAgent returns the configured user agent string for the client. If a custom value is not set the default package user agent is returned.

func (*TeamsClient) ValidateWebhook added in v2.7.0

func (c *TeamsClient) ValidateWebhook(webhookURL string) error

ValidateWebhook applies webhook URL validation unless explicitly disabled.

Directories

Path Synopsis
Package adaptivecard provides support for generating Microsoft Teams messages using the Adaptive Card format.
Package adaptivecard provides support for generating Microsoft Teams messages using the Adaptive Card format.
examples
adaptivecard/table-manually-created
This is an example of a client application which uses this library to generate a message with a table within a specific Microsoft Teams channel.
This is an example of a client application which uses this library to generate a message with a table within a specific Microsoft Teams channel.
adaptivecard/table-unordered-grid
This is an example of a client application which uses this library to generate a message with a table within a specific Microsoft Teams channel.
This is an example of a client application which uses this library to generate a message with a table within a specific Microsoft Teams channel.
adaptivecard/table-with-headers
This is an example of a client application which uses this library to generate a message with a table within a specific Microsoft Teams channel.
This is an example of a client application which uses this library to generate a message with a table within a specific Microsoft Teams channel.
adaptivecard/toggle-visibility-column-action
This example illustrates how to toggle visibility for a container using a column's select action.
This example illustrates how to toggle visibility for a container using a column's select action.
adaptivecard/toggle-visibility-container-action
This example illustrates how to toggle visibility for a text block using a container's select action.
This example illustrates how to toggle visibility for a text block using a container's select action.
adaptivecard/toggle-visibility-multiple-buttons
This example uses three action "buttons" on the main card body to illustrate toggling visibility states for multiple elements.
This example uses three action "buttons" on the main card body to illustrate toggling visibility states for multiple elements.
adaptivecard/toggle-visibility-single-button
This example uses a single "button" to illustrate toggling visibility for a "details" text block.
This example uses a single "button" to illustrate toggling visibility for a "details" text block.
internal
validator
Package validator provides logic to assist with validation tasks.
Package validator provides logic to assist with validation tasks.
Package messagecard provides support for generating Microsoft Teams messages using the legacy "actionable message card" (aka, "MessageCard") format.
Package messagecard provides support for generating Microsoft Teams messages using the legacy "actionable message card" (aka, "MessageCard") format.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL