Skip to content

Commit

Permalink
Merge pull request #245 from atc0005/sync-from-master
Browse files Browse the repository at this point in the history
Sync latest changes from master branch
  • Loading branch information
atc0005 authored Dec 7, 2023
2 parents 37b4b0a + bbbd54b commit 39566f2
Show file tree
Hide file tree
Showing 11 changed files with 265 additions and 61 deletions.
55 changes: 41 additions & 14 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,49 @@

# https://help.github.com/en/github/administering-a-repository/configuration-options-for-dependency-updates

######################################################################
# Monitor Go module dependency updates
######################################################################

version: 2
updates:

# Enable version updates for Go modules
- package-ecosystem: "gomod"

# Look for a `go.mod` file in the `root` directory
directory: "/"

# Default is a maximum of five pull requests for version updates
open-pull-requests-limit: 10

target-branch: "master"

# Daily update checks; default version checks are performed at 05:00 UTC
schedule:
interval: "daily"
time: "02:00"
timezone: "America/Chicago"

# Assign everything to me by default
assignees:
- "atc0005"
labels:
- "dependencies"

allow:
# Allow both direct and indirect updates for all packages
- dependency-type: "all"
commit-message:
prefix: "go.mod"

- package-ecosystem: "gomod"
directory: "/"
open-pull-requests-limit: 10
target-branch: "development"
schedule:
interval: "daily"
time: "02:00"
timezone: "America/Chicago"
assignees:
- "atc0005"
labels:
- "dependencies"
allow:
- dependency-type: "all"
commit-message:
# Prefix all commit messages with "go.mod"
prefix: "go.mod"

######################################################################
# Monitor GitHub Actions dependency updates
######################################################################

- package-ecosystem: "github-actions"
directory: "/"
Expand All @@ -59,3 +68,21 @@ updates:
- dependency-type: "all"
commit-message:
prefix: "ghaw"

- package-ecosystem: "github-actions"
directory: "/"
open-pull-requests-limit: 10
target-branch: "development"
schedule:
interval: "daily"
time: "02:00"
timezone: "America/Chicago"
assignees:
- "atc0005"
labels:
- "dependencies"
- "CI"
allow:
- dependency-type: "all"
commit-message:
prefix: "ghaw"
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ A package to send messages to a Microsoft Teams channel.
- [How to create a webhook URL (Connector)](#how-to-create-a-webhook-url-connector)
- [Examples](#examples)
- [Basic](#basic)
- [Specify proxy server](#specify-proxy-server)
- [User Mention](#user-mention)
- [Tables](#tables)
- [Set custom user agent](#set-custom-user-agent)
Expand Down Expand Up @@ -192,6 +193,16 @@ This is an example of a simple client application which uses this library.
- `MessageCard`
- File: [basic](./examples/messagecard/basic/main.go)

#### 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`
- File: [basic](./examples/adaptivecard/proxy/main.go)
- `MessageCard`
- File: [basic](./examples/messagecard/proxy/main.go)

#### User Mention

These examples illustrates the use of one or more user mentions. This feature
Expand Down
27 changes: 13 additions & 14 deletions adaptivecard/adaptivecard.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ const (

// Attachment constants.
//
// https://docs.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-reference
// https://docs.microsoft.com/en-us/dotnet/api/microsoft.bot.schema.attachmentlayouttypes
// https://docs.microsoft.com/en-us/javascript/api/botframework-schema/attachmentlayouttypes
// https://github.com/matthidinger/ContosoScubaBot/blob/master/Cards/1-Schools.JSON
// - https://docs.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-reference
// - https://docs.microsoft.com/en-us/dotnet/api/microsoft.bot.schema.attachmentlayouttypes
// - https://docs.microsoft.com/en-us/javascript/api/botframework-schema/attachmentlayouttypes
// - https://github.com/matthidinger/ContosoScubaBot/blob/master/Cards/1-Schools.JSON
const (

// AttachmentContentType is the supported type value for an attached
Expand Down Expand Up @@ -291,12 +291,11 @@ const (
// Valid types for an Adaptive Card element. Not all types are supported by
// Microsoft Teams.
//
// https://adaptivecards.io/explorer/AdaptiveCard.html
//
// TODO: Confirm whether all types are supported.
//
// https://docs.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-reference#support-for-adaptive-cards
// https://docs.microsoft.com/en-us/adaptive-cards/authoring-cards/universal-action-model#schema
// - https://adaptivecards.io/explorer/AdaptiveCard.html
// - https://docs.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-reference#support-for-adaptive-cards
// - https://docs.microsoft.com/en-us/adaptive-cards/authoring-cards/universal-action-model#schema
const (
TypeElementActionSet string = "ActionSet"
TypeElementColumnSet string = "ColumnSet"
Expand Down Expand Up @@ -736,9 +735,9 @@ type Actions []Action
// Action represents an action that a user may take on a card. Actions
// typically get rendered in an "action bar" at the bottom of a card.
//
// https://adaptivecards.io/explorer/ActionSet.html
// https://adaptivecards.io/explorer/AdaptiveCard.html
// https://docs.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-reference
// - https://adaptivecards.io/explorer/ActionSet.html
// - https://adaptivecards.io/explorer/AdaptiveCard.html
// - https://docs.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-reference
//
// TODO: Extend with additional supported fields.
type Action struct {
Expand Down Expand Up @@ -784,9 +783,9 @@ type Action struct {
// type (e.g., Column, ColumnSet, Container) is tapped or selected.
// Action.ShowCard is not supported.
//
// https://adaptivecards.io/explorer/Container.html
// https://adaptivecards.io/explorer/ColumnSet.html
// https://adaptivecards.io/explorer/Column.html
// - https://adaptivecards.io/explorer/Container.html
// - https://adaptivecards.io/explorer/ColumnSet.html
// - https://adaptivecards.io/explorer/Column.html
//
// TODO: Extend with additional supported fields.
type ISelectAction struct {
Expand Down
28 changes: 14 additions & 14 deletions adaptivecard/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ See the provided examples in this repo, the Godoc generated documentation at
https://pkg.go.dev/github.com/atc0005/go-teams-notify/v2 and the following
resources for more information:
https://adaptivecards.io/explorer
https://docs.microsoft.com/en-us/adaptive-cards/
https://docs.microsoft.com/en-us/adaptive-cards/authoring-cards/getting-started
https://docs.microsoft.com/en-us/adaptive-cards/authoring-cards/text-features
https://docs.microsoft.com/en-us/adaptive-cards/authoring-cards/universal-action-model
https://docs.microsoft.com/en-us/adaptive-cards/getting-started/bots
https://docs.microsoft.com/en-us/adaptive-cards/resources/principles
https://docs.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-format
https://docs.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-format#mention-support-within-adaptive-cards
https://docs.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-reference#support-for-adaptive-cards
https://docs.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/what-are-cards
https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-using
https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-using#send-adaptive-cards-using-an-incoming-webhook
https://stackoverflow.com/questions/50753072/microsoft-teams-webhook-generating-400-for-adaptive-card
- https://adaptivecards.io/explorer
- https://docs.microsoft.com/en-us/adaptive-cards/
- https://docs.microsoft.com/en-us/adaptive-cards/authoring-cards/getting-started
- https://docs.microsoft.com/en-us/adaptive-cards/authoring-cards/text-features
- https://docs.microsoft.com/en-us/adaptive-cards/authoring-cards/universal-action-model
- https://docs.microsoft.com/en-us/adaptive-cards/getting-started/bots
- https://docs.microsoft.com/en-us/adaptive-cards/resources/principles
- https://docs.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-format
- https://docs.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-format#mention-support-within-adaptive-cards
- https://docs.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-reference#support-for-adaptive-cards
- https://docs.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/what-are-cards
- https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-using
- https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-using#send-adaptive-cards-using-an-incoming-webhook
- https://stackoverflow.com/questions/50753072/microsoft-teams-webhook-generating-400-for-adaptive-card
*/
package adaptivecard
12 changes: 6 additions & 6 deletions adaptivecard/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ package adaptivecard

import "strings"

// https://docs.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-format#newlines-for-adaptive-cards
// https://docs.microsoft.com/en-us/adaptive-cards/authoring-cards/text-features
// - https://docs.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-format#newlines-for-adaptive-cards
// - https://docs.microsoft.com/en-us/adaptive-cards/authoring-cards/text-features

// Newline and break statement patterns stripped out of text content sent to
// Microsoft Teams (by request).
Expand Down Expand Up @@ -42,8 +42,8 @@ const (
// text in desktop, web and mobile, so even with using this helper function
// some differences are to be expected.
//
// https://docs.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-format#newlines-for-adaptive-cards
// https://docs.microsoft.com/en-us/adaptive-cards/authoring-cards/text-features
// - https://docs.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-format#newlines-for-adaptive-cards
// - https://docs.microsoft.com/en-us/adaptive-cards/authoring-cards/text-features
func ConvertEOL(s string) string {
s = strings.ReplaceAll(s, windowsEOLEscaped, unixEOLActual+unixEOLActual)
s = strings.ReplaceAll(s, windowsEOLActual, unixEOLActual+unixEOLActual)
Expand All @@ -66,8 +66,8 @@ func ConvertEOL(s string) string {
// MessageCard format supports <br> statements for text spacing/formatting
// where the Adaptive Card format does not.
//
// https://docs.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-format#newlines-for-adaptive-cards
// https://docs.microsoft.com/en-us/adaptive-cards/authoring-cards/text-features
// - https://docs.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-format#newlines-for-adaptive-cards
// - https://docs.microsoft.com/en-us/adaptive-cards/authoring-cards/text-features
func ConvertBreakToEOL(s string) string {
return strings.ReplaceAll(s, breakStatement, unixEOLActual+unixEOLActual)
}
89 changes: 89 additions & 0 deletions examples/adaptivecard/proxy/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright 2022 Adam Chalkley
//
// https://github.com/atc0005/go-teams-notify
//
// Licensed under the MIT License. See LICENSE file in the project root for
// full license information.

/*
This is an example of a client application which uses this library to:
- generate a basic Microsoft Teams message in Adaptive Card format
- submit the message using an explicit proxy server URL
Of note:
- message is in Adaptive Card format
- default timeout
- package-level logging is disabled by default
- validation of known webhook URL prefixes is *enabled*
- simple message submitted to Microsoft Teams consisting of title and
formatted message body
See https://docs.microsoft.com/en-us/adaptive-cards/authoring-cards/text-features
for the list of supported Adaptive Card text formatting options.
*/

package main

import (
"log"
"net/http"
"net/url"
"os"

goteamsnotify "github.com/atc0005/go-teams-notify/v2"
"github.com/atc0005/go-teams-notify/v2/adaptivecard"
)

func main() {

// Initialize a new Microsoft Teams client.
mstClient := goteamsnotify.NewTeamsClient()

proxyURLString := "http://proxy.example.com:3128"
proxyUrl, err := url.Parse(proxyURLString)

if err != nil {
log.Printf(
"failed to parse proxy URL %q: %v",
proxyURLString,
err,
)
os.Exit(1)
}

httpClient := mstClient.HTTPClient()
httpClient.Transport = &http.Transport{Proxy: http.ProxyURL(proxyUrl)}

// Set webhook url.
webhookUrl := "https://outlook.office.com/webhook/YOUR_WEBHOOK_URL_OF_TEAMS_CHANNEL"

// The title for message (first TextBlock element).
msgTitle := "Hello world"

// Formatted message body.
msgText := "Here are some examples of formatted stuff like " +
"\n * this list itself \n * **bold** \n * *italic* \n * ***bolditalic***"

// Create message using provided formatted title and text.
msg, err := adaptivecard.NewSimpleMessage(msgText, msgTitle, true)
if err != nil {
log.Printf(
"failed to create message: %v",
err,
)
os.Exit(1)
}

// Send the message with default timeout/retry settings.
if err := mstClient.Send(webhookUrl, msg); err != nil {
log.Printf(
"failed to send message: %v",
err,
)
os.Exit(1)
}
}
73 changes: 73 additions & 0 deletions examples/messagecard/proxy/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright 2021 Adam Chalkley
//
// https://github.com/atc0005/go-teams-notify
//
// Licensed under the MIT License. See LICENSE file in the project root for
// full license information.

/*
This is an example of a client application which uses this library to:
- generate a Microsoft Teams message in MessageCard format
- submit the message using an explicit proxy server URL
Of note:
- message is in MessageCard format
- default timeout
- package-level logging is disabled by default
- validation of known webhook URL prefixes is *enabled*
- simple message submitted to Microsoft Teams consisting of title and
formatted message body
*/

package main

import (
"log"
"net/http"
"net/url"
"os"

goteamsnotify "github.com/atc0005/go-teams-notify/v2"
"github.com/atc0005/go-teams-notify/v2/messagecard"
)

func main() {

// Initialize a new Microsoft Teams client.
mstClient := goteamsnotify.NewTeamsClient()

proxyURLString := "http://proxy.example.com:3128"
proxyUrl, err := url.Parse(proxyURLString)

if err != nil {
log.Printf(
"failed to parse proxy URL %q: %v",
proxyURLString,
err,
)
os.Exit(1)
}

httpClient := mstClient.HTTPClient()
httpClient.Transport = &http.Transport{Proxy: http.ProxyURL(proxyUrl)}

// Set webhook url.
webhookUrl := "https://outlook.office.com/webhook/YOUR_WEBHOOK_URL_OF_TEAMS_CHANNEL"

// Setup message card.
msgCard := messagecard.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 the message with default timeout/retry settings.
if err := mstClient.Send(webhookUrl, msgCard); err != nil {
log.Printf("failed to send message: %v", err)
os.Exit(1)
}
}
Loading

0 comments on commit 39566f2

Please sign in to comment.