| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- package providers
- import (
- "context"
- "git.wenlab.co/joe/beaconfire"
- "github.com/slack-go/slack"
- )
- const SLACKFIRE_NAME = "slackfire"
- type OptionsSlack struct {
- AuthToken string
- To []string
- }
- type slackfire struct {
- opt *OptionsSlack
- }
- var _ beaconfire.BeaconFire = &slackfire{}
- func NewSlackfire(opt *OptionsSlack) *slackfire {
- return &slackfire{
- opt: opt,
- }
- }
- func (c slackfire) Name() string {
- return SLACKFIRE_NAME
- }
- func (c *slackfire) Send(bp *beaconfire.BeaconParam) error {
- if len(c.opt.To) <= 0 {
- return beaconfire.ErrNoReceiver
- }
- s := slack.New(c.opt.AuthToken)
- for _, channel := range c.opt.To {
- if _, _, err := s.PostMessageContext(
- context.TODO(),
- channel,
- slack.MsgOptionText(bp.Content, false)); err != nil {
- return err
- }
- }
- return nil
- }
|