Documentation ¶
Overview ¶
Package mattermost provides message notification integration for mattermost.com.
Usage:
package main import ( "os" "github.com/casdoor/notify" "github.com/casdoor/notify/service/mattermost" ) func main() { // Init notifier notifier := notify.New() ctx := context.Background() // Provide your Mattermost server url mattermostService := mattermost.New("https://myserver.cloud.mattermost.com") // Provide username as loginID and password to login into above server. // NOTE: This generates auth token which will get expired, invoking this method again // after expiry will generate new token and uses for further requests. err := mattermostService.LoginWithCredentials(ctx, "someone@gmail.com", "somepassword") if err != nil { fmt.Println(err) os.Exit(1) } // Passing a Mattermost channel/chat id as receiver for our messages. // Where to send our messages. mattermostService.AddReceivers("CHANNEL_ID") // Tell our notifier to use the Mattermost service. You can repeat the above process // for as many services as you like and just tell the notifier to use them. notifier.UseServices(mattermostService) // Add presend and postsend hooks that you need to execute before every requests and after // every response respectively. Multiple presend and postsend are executed in the order defined here. // refer service/http for the more info. // PreSend hook mattermostService.PreSend(func(req *stdhttp.Request) error { log.Printf("Sending message to %s server", req.URL) return nil }) // PostSend hook mattermostService.PostSend(func(req *stdhttp.Request, resp *stdhttp.Response) error { log.Printf("Message sent to %s server with status %d", req.URL, resp.StatusCode) return nil }) // Send a message err = notifier.Send( ctx, "Hello from notify :wave:", "Message written in Go!", ) if err != nil { fmt.Println(err) os.Exit(1) } }
Package mattermost provides message notification integration for mattermost.com.
Index ¶
- type Service
- func (s *Service) AddReceivers(channelIDs ...string)
- func (s *Service) LoginWithCredentials(ctx context.Context, loginID, password string) error
- func (s *Service) PostSend(hook http.PostSendHookFn)
- func (s *Service) PreSend(hook http.PreSendHookFn)
- func (s *Service) Send(ctx context.Context, subject, message string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service encapsulates the notify httpService client and contains mattermost channel ids.
func (*Service) AddReceivers ¶
AddReceivers takes Mattermost channel IDs or Chat IDs and adds them to the internal channel ID list. The Send method will send a given message to all these channels.
func (*Service) LoginWithCredentials ¶
LoginWithCredentials provides helper for authentication using Mattermost user/admin credentials.
func (*Service) PostSend ¶
func (s *Service) PostSend(hook http.PostSendHookFn)
PostSend adds a post-send hook to the service. The hook will be executed after sending a request to a receiver.
func (*Service) PreSend ¶
func (s *Service) PreSend(hook http.PreSendHookFn)
PreSend adds a pre-send hook to the service. The hook will be executed before sending a request to a receiver.