Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bobgroup-go-utils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bob Public Utils
bobgroup-go-utils
Merge requests
!59
Resolve "Add function to send files to Slack channels"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "Add function to send files to Slack channels"
44-add-function-to-send-files-to-slack-channels
into
main
Overview
0
Commits
1
Pipelines
0
Changes
1
Merged
James Page
requested to merge
44-add-function-to-send-files-to-slack-channels
into
main
3 months ago
Overview
0
Commits
1
Pipelines
0
Changes
1
Expand
Related to
#44 (closed)
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
0a7b47c9
1 commit,
3 months ago
1 file
+
34
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
slack_utils/slack_utils.go
+
34
−
0
Options
@@ -15,6 +15,18 @@ type SlackField struct {
Value
any
}
type
SlackFile
struct
{
File
string
FileSize
int
Content
string
Filename
string
Title
string
InitialComment
string
ThreadTimestamp
string
AltTxt
string
SnippetText
string
}
type
SlackClient
struct
{
Client
*
slack
.
Client
}
@@ -116,6 +128,28 @@ func (s *SlackClient) postMessage(channel string, messageOptions []slack.MsgOpti
return
messageTimestamp
}
func
(
s
*
SlackClient
)
SendFile
(
channel
string
,
file
SlackFile
)
error
{
fileParameters
:=
slack
.
UploadFileV2Parameters
{
Channel
:
channel
,
File
:
file
.
File
,
FileSize
:
file
.
FileSize
,
Content
:
file
.
Content
,
Filename
:
file
.
Filename
,
Title
:
file
.
Title
,
InitialComment
:
file
.
InitialComment
,
ThreadTimestamp
:
file
.
ThreadTimestamp
,
AltTxt
:
file
.
AltTxt
,
SnippetText
:
file
.
SnippetText
,
}
_
,
err
:=
s
.
Client
.
UploadFileV2
(
fileParameters
)
if
err
!=
nil
{
logs
.
ErrorWithMsg
(
err
,
"Error uploading file to slack:"
)
return
err
}
return
nil
}
func
hasEmoji
(
message
string
)
bool
{
emojiRegex
:=
regexp
.
MustCompile
(
`:[a-zA-Z0-9_]+:`
)
return
emojiRegex
.
MatchString
(
message
)
Loading