teams

package module
v0.0.0-...-98e7844 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2018 License: MIT Imports: 8 Imported by: 0

README

GoLang Outgoing WebHook Library

This is a small library to simplify the task of writing BOT Outgoing WebHooks for Microsoft Teams, as outlined in their documentation https://docs.microsoft.com/en-us/microsoftteams/platform/concepts/outgoingwebhook

The sample project (samples/helloworld) provide full documentation on using and deploying this library. In short, you need to implement a main function and an OnMessage function as follows:

import (
	"github.com/aws/aws-lambda-go/lambda"
	teams "github.com/ericdaugherty/msteams-webhook-go"
)

type webHook struct {
}

func (w webHook) OnMessage(req teams.Request) (teams.Response, error) {
	return teams.BuildResponse("Hello " + req.FromUser.Name), nil
}

func main() {
	lambda.Start(teams.NewHandler(false, "", webHook{}))
}

The main function starts the Lambda API and registers your callback. Then you simply process the request and return the response, using the BuildResponse helper method.

This library also supports HMAC authenctication. Simply pass in 'true' and the Base64 encoded String returned by Microsoft Teams when you register your callback URL.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHandler

func NewHandler(authenticateRequests bool, key string, wh WebHook) func(events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error)

NewHandler initializes and returns a Lambda handler to process incoming requests.

Types

type Request

type Request struct {
	Type           string `json:"type"`
	ID             string `json:"id"`
	Timestamp      string `json:"timestamp"`
	LocalTimestamp string `json:"localTimestamp"`
	ServiceURL     string `json:"serviceUrl"`
	ChannelID      string `json:"channelId"`
	FromUser       User   `json:"from"`
	Conversation   struct {
		ID string `json:"id"`
	} `json:"conversation"`
	RecipientUser User   `json:"recipient"`
	TextFormat    string `json:"textFormat"`
	Text          string `json:"text"`
	Attachments   []struct {
		ContentType string `json:"contentType"`
		Content     string `json:"Content"`
	} `json:"attachments"`
	Entities    []interface{} `json:"entities"`
	ChannelData struct {
		TeamsChannelID string `json:"teamsChannelId"`
		TeamsTeamID    string `json:"teamsTeamId"`
	}
}

Request data representing an inbound WebHook request from Microsoft Teams.

type Response

type Response struct {
	Type string `json:"type"`
	Text string `json:"text"`
}

Response represents the data to return to Microsoft Teams.

func BuildResponse

func BuildResponse(text string) Response

BuildResponse is a helper method to build a Response

type User

type User struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

User represents data for a Microsoft Teams user.

type WebHook

type WebHook interface {
	OnMessage(Request) (Response, error)
}

WebHook represnts the interface needed to handle Microsoft Teams WebHook Requests.

Directories

Path Synopsis
samples

Jump to

Keyboard shortcuts

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