Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Botの表示名を変える機能を実装 #68

Merged
merged 6 commits into from
Sep 11, 2024
Merged
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ docker run --rm -it -v "$PWD":/_ -w /_ golang:1-alpine sh -c '
dirname="dist"
filename="epgstation-slack-notification"

(GOOS=darwin GOARCH=arm64 go build -o "${dirname}/darwin/${filename}") &
(GOOS=linux GOARCH=arm GOARM=7 go build -o "${dirname}/linux-arm-7/${filename}") &
(GOOS=darwin GOARCH=arm64 go build -o "${dirname}/darwin-arm64/${filename}") &
(GOOS=linux GOARCH=amd64 go build -o "${dirname}/linux-amd64/${filename}") &
wait
'
12 changes: 12 additions & 0 deletions epgstation-slack-config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ commands:
# EPGStation の config/config.yml にコマンドの設定はしてあるけど通知を無効化したいときなどは false にする
enable: true

# Slack の Bot のユーザー名
# chat:write.customize の権限が与えられている場合のみ変更される
userName: "録画予約新規追加通知"

# Slack で使用されるメッセージ
# Box Kit のヘッダーセクションで使われ, 通知の際はこのメッセージが表示される
# 絵文字も使える
Expand Down Expand Up @@ -55,25 +59,30 @@ commands:
reserve-update:
<<: *pre-command-default
enable: true
userName: "録画情報更新通知"
message: ":up: {{ .ChannelName }} で {{ .Name }} の録画情報が更新されました"

reserve-deleted:
<<: *pre-command-default
enable: true
userName: "録画予約削除通知"
message: ":black_square_for_stop: {{ .ChannelName }} で {{ .Name }} の録画予約が削除されました"

recording-pre-start:
<<: *pre-command-default
enable: true
userName: "録画準備開始通知"
message: ":soon: {{ .ChannelName }} で {{ .Name }} の録画準備が開始しました"

recording-prep-rec-failed:
<<: *pre-command-default
enable: true
userName: "録画準備失敗通知"
message: ":x: {{ .ChannelName }} で {{ .Name }} の録画準備に失敗しました"

recording-start: &rec-command-default
enable: true
userName: "録画開始通知"
# struct の内容は /pkg/app/recording_notification.go の RecordingDetail を参照
message: ":arrow_forward: {{ .ChannelName }} で {{ .Name }} の録画が開始しました"
fields-section:
Expand Down Expand Up @@ -103,6 +112,7 @@ commands:

recording-finish:
enable: true
userName: "録画終了通知"
message: ":white_check_mark: {{ .ChannelName }} で {{ .Name }} の録画が終了しました"
fields-section:
- title: "RecordedID, ProgramID"
Expand Down Expand Up @@ -135,10 +145,12 @@ commands:
recording-failed:
<<: *rec-command-default
enable: true
userName: "録画エラー通知"
message: ":x: {{ .ChannelName }} で {{ .Name }} の録画中にエラーが発生しました"

encoding-finish:
enable: true
userName: "エンコード終了通知"
# struct の内容は /pkg/app/encoding_notification.go の EncodingDetail を参照
message: ":white_check_mark: {{ .HalfWidthChannelName }} の {{ .HalfWidthName }} のエンコードが終了しました"
fields-section:
Expand Down
7 changes: 5 additions & 2 deletions pkg/app/encoding_notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package app

import (
"github.com/hiroxto/epgstation-slack-notification/pkg/env"
"github.com/slack-go/slack"
)

// EncodingUseCaseParam EncodingUseCaseのパラメータ
type EncodingUseCaseParam struct {
EnableDebug bool
SlackAPIKey string
SlackChannel string
UserName string
Message string
Fields []Field
EncodingDetail EncodingDetail
Expand Down Expand Up @@ -67,8 +69,9 @@ func EncodingNotificationUseCase(param EncodingUseCaseParam) error {
return err
}

options := buildMessageOptions(message, fields)
_, _, err = slackClient.PostMessage(param.SlackChannel, options)
messageOptions := buildMessageOptions(message, fields)
userNameOption := slack.MsgOptionUsername(param.UserName)
_, _, err = slackClient.PostMessage(param.SlackChannel, messageOptions, userNameOption)

if err != nil {
return err
Expand Down
7 changes: 5 additions & 2 deletions pkg/app/recording_notification.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app

import (
"github.com/slack-go/slack"
"strconv"
"time"

Expand All @@ -12,6 +13,7 @@ type RecordingUseCaseParam struct {
EnableDebug bool
SlackAPIKey string
SlackChannel string
UserName string
Message string
Fields []Field
RecordingDetail RecordingDetail
Expand Down Expand Up @@ -98,8 +100,9 @@ func RecordingNotificationUseCase(param RecordingUseCaseParam) error {
return err
}

options := buildMessageOptions(message, fields)
_, _, err = slackClient.PostMessage(param.SlackChannel, options)
messageOptions := buildMessageOptions(message, fields)
userNameOption := slack.MsgOptionUsername(param.UserName)
_, _, err = slackClient.PostMessage(param.SlackChannel, messageOptions, userNameOption)

if err != nil {
return err
Expand Down
7 changes: 5 additions & 2 deletions pkg/app/reserve_notification.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app

import (
"github.com/slack-go/slack"
"strconv"
"time"

Expand All @@ -12,6 +13,7 @@ type ReserveUseCaseParam struct {
EnableDebug bool
SlackAPIKey string
SlackChannel string
UserName string
Message string
Fields []Field
ReserveDetail ReserveDetail
Expand Down Expand Up @@ -86,8 +88,9 @@ func ReserveNotificationUseCase(param ReserveUseCaseParam) error {
return err
}

options := buildMessageOptions(message, fields)
_, _, err = slackClient.PostMessage(param.SlackChannel, options)
messageOptions := buildMessageOptions(message, fields)
userNameOption := slack.MsgOptionUsername(param.UserName)
_, _, err = slackClient.PostMessage(param.SlackChannel, messageOptions, userNameOption)

if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions pkg/command/encoding_finish_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func encodingFinishCommandAction(context *cli.Context) error {
EnableDebug: context.Bool("debug"),
SlackAPIKey: slackAPIKey,
SlackChannel: slackChannel,
UserName: commandConfig.UserName,
Message: commandConfig.Message,
Fields: app.FieldsFromConfig(commandConfig.FieldsSection),
EncodingDetail: app.EncodingDetailFromEnv(encodingCommandEnv),
Expand Down
1 change: 1 addition & 0 deletions pkg/command/recording_failed_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func recordingFailedCommandAction(context *cli.Context) error {
EnableDebug: context.Bool("debug"),
SlackAPIKey: slackAPIKey,
SlackChannel: slackChannel,
UserName: commandConfig.UserName,
Message: commandConfig.Message,
Fields: app.FieldsFromConfig(commandConfig.FieldsSection),
RecordingDetail: app.RecordingDetailFromEnv(recordingCommandEnv),
Expand Down
1 change: 1 addition & 0 deletions pkg/command/recording_finish_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func recordingFinishCommandAction(context *cli.Context) error {
EnableDebug: context.Bool("debug"),
SlackAPIKey: slackAPIKey,
SlackChannel: slackChannel,
UserName: commandConfig.UserName,
Message: commandConfig.Message,
Fields: app.FieldsFromConfig(commandConfig.FieldsSection),
RecordingDetail: app.RecordingDetailFromEnv(recordingCommandEnv),
Expand Down
1 change: 1 addition & 0 deletions pkg/command/recording_pre_start_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func recordingPreStartCommandAction(context *cli.Context) error {
EnableDebug: context.Bool("debug"),
SlackAPIKey: slackAPIKey,
SlackChannel: slackChannel,
UserName: commandConfig.UserName,
Message: commandConfig.Message,
Fields: app.FieldsFromConfig(commandConfig.FieldsSection),
ReserveDetail: app.ReserveDetailFromEnv(reserveCommandEnv),
Expand Down
1 change: 1 addition & 0 deletions pkg/command/recording_prep_rec_failed_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func recordingPrepRecFailedCommandAction(context *cli.Context) error {
EnableDebug: context.Bool("debug"),
SlackAPIKey: slackAPIKey,
SlackChannel: slackChannel,
UserName: commandConfig.UserName,
Message: commandConfig.Message,
Fields: app.FieldsFromConfig(commandConfig.FieldsSection),
ReserveDetail: app.ReserveDetailFromEnv(reserveCommandEnv),
Expand Down
1 change: 1 addition & 0 deletions pkg/command/recording_start_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func recordingStartCommandAction(context *cli.Context) error {
EnableDebug: context.Bool("debug"),
SlackAPIKey: slackAPIKey,
SlackChannel: slackChannel,
UserName: commandConfig.UserName,
Message: commandConfig.Message,
Fields: app.FieldsFromConfig(commandConfig.FieldsSection),
RecordingDetail: app.RecordingDetailFromEnv(recordingCommandEnv),
Expand Down
1 change: 1 addition & 0 deletions pkg/command/reserve_deleted_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func reserveDeletedCommandAction(context *cli.Context) error {
EnableDebug: context.Bool("debug"),
SlackAPIKey: slackAPIKey,
SlackChannel: slackChannel,
UserName: commandConfig.UserName,
Message: commandConfig.Message,
Fields: app.FieldsFromConfig(commandConfig.FieldsSection),
ReserveDetail: app.ReserveDetailFromEnv(reserveCommandEnv),
Expand Down
1 change: 1 addition & 0 deletions pkg/command/reserve_new_addition_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func reserveNewAdditionCommandAction(context *cli.Context) error {
EnableDebug: context.Bool("debug"),
SlackAPIKey: slackAPIKey,
SlackChannel: slackChannel,
UserName: commandConfig.UserName,
Message: commandConfig.Message,
Fields: app.FieldsFromConfig(commandConfig.FieldsSection),
ReserveDetail: app.ReserveDetailFromEnv(reserveCommandEnv),
Expand Down
1 change: 1 addition & 0 deletions pkg/command/reserve_update_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func reserveUpdateCommandAction(context *cli.Context) error {
EnableDebug: context.Bool("debug"),
SlackAPIKey: slackAPIKey,
SlackChannel: slackChannel,
UserName: commandConfig.UserName,
Message: commandConfig.Message,
Fields: app.FieldsFromConfig(commandConfig.FieldsSection),
ReserveDetail: app.ReserveDetailFromEnv(reserveCommandEnv),
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type CommandsConfig struct {
type CommandConfig struct {
Enable bool `yaml:"enable"`
Channel string `yaml:"channel"`
UserName string `yaml:"userName"`
Message string `yaml:"message"`
FieldsSection []FieldConfig `yaml:"fields-section"`
}
Expand Down
Loading