Skip to content

CLI tools / GitHub Actions to post Google Calendar events to Slack.

License

Notifications You must be signed in to change notification settings

ebc-2in2crc/slack-notify

Repository files navigation

English | 日本語

slack-notify

MIT License Go Report Card Go Version Version

slack-notify is a command and GitHub Action to link events in your Google Calendar to Slack.

Description

slack-notify does the following

  • Retrieve events from Google Calendar
  • Post the retrieved events to Slack
  • The message to post on Slack is customizable

Usage

$ slack-notify \
  -credentials ${GOOGLE_CREDENTIALS} \
  -calendar-id ${GOOGLE_CALENDAR_ID} \
  -slack-token ${SLACK_TOKEN} \
  -slack-channel-id ${SLACK_CHANNEL_ID} \
  -location Asia/Tokyo \
  -message "Here is an update on today's event." \
  -alternative-message "There are no events today."

# usage
$ slack-notify -h
Usage of slack-notify:
  -alternative-message string
    	Specify alternative message
  -calendar-id string
    	Specify Google Calendar ID
  -credentials string
    	Specify credentials
  -credentials-file string
    	Specify credentials file
  -dry-run
    	Specify dry-run
  -event-filter-regexp string
    	Specify event filter regexp (default ".")
  -location string
    	Specify Location (default "UTC")
  -message string
    	Specify message
  -message-template-file string
        Specify custom message template file
  -slack-channel-id string
    	Specify Slack Channel ID
  -slack-token string
    	Specify Slack Access Token
  -target-date string
    	Specify targetDate date. e.g. 2020-01-01
  -timeout duration
    	Specify timeout (default 15m0s)
  -v	Show version
  -webhook string
        Specify Slack Webhook URL

Customizing Messages

By default, the message posted to Slack uses the following template. Please refer to text/template for the template.

{{.Msg}}

{{range .Events -}}
• {{.Summary}}
{{end}}`

The actual message posted to Slack will be as follows.

Announcing today's events.

• A certain event
• Another event
• Yet another event

The data passed to the template is a structure like the following.

type EventData struct {
    Msg    string // The message specified with -message
    Events []*calendar.Event
}

To customize the message, specify the template file with -message-template-file.

$ cat template.txt
{{.Msg}}

{{range $i, $v := .Events -}}
{{$i}}. {{$v.Summary}}
{{end}}

$ slack-notify \
  -message-template-file template.txt \
  # Omitted

The actual message posted to Slack will be as follows.

Announcing today's events.

0. A certain event
1. Another event
2. Yet another event

Installation

Developer

$ go install github.com/ebc-2in2crc/slack-notify/cmd/slack-notify@latest

User

Download from the following URL.

You can also use Homebrew.

$ brew install ebc-2in2crc/tap/slack-notify

GitHub Action

このアクションはインストールのみを実行します。 The action ebc-2in2crc/slack-notify@v0 installs the slack-notify binary for Linux in /usr/local/bin. This action only performs the installation.

jobs:
  slack-notify:
    name: slack-notify
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Install slack-notify
        uses: ebc-2in2crc/slack-notify@v0
      - name: Notify
        run: |-
          slack-notify -v

Contribution

  1. Fork this repository
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Rebase your local changes against the master branch
  5. Run test suite with the make test command and confirm that it passes
  6. Run make fmt and make lint
  7. Create new Pull Request

Licence

MIT

Author

ebc-2in2crc