Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add Events API in socket mode for Slack adapter#2161

Open
kolsys wants to merge 1 commit into42wim:masterfrom
kolsys:master
Open

Add Events API in socket mode for Slack adapter#2161
kolsys wants to merge 1 commit into42wim:masterfrom
kolsys:master

Conversation

Copy link

kolsys commented Jul 1, 2024

This is beta version for modern Slack applications.
Changes implement Slack Events API in socket mode, see #964.

Fixes #2159
It also fixes files upload to Slack for modern Apps.

To activate Ecvents API in SocketMode you must:

  1. Create new modern App with following OAuth Bot scope (or upgrade Legacy)
channels:history
channels:read
chat:write
files:read
files:write
groups:history
groups:read
im:history
im:read
mpim:history
mpim:read
users.profile:read
users:read
  1. Acivate Socket mode
  2. Subscribe to the following events:
channel_history_changed
group_history_changed
im_history_changed
message.channels
message.groups
message.im
message.mpim
  1. Add AppToken to the toml:
[slack]
[slack.mybot]
Token="xoxb-*******"
AppToken="xapp-**********"

xandr0s, InternetWorkAcct, and siccovansas reacted with thumbs up emoji adairrr reacted with rocket emoji
}
}

func (b *Bslack) handleSlackClientSocketMode(messages chan *config.Message) {
Copy link

qlty-cloud-legacy bot Jul 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method Bslack.handleSlackClientSocketMode has 107 lines of code (exceeds 50 allowed). Consider refactoring.

}
}

func (b *Bslack) handleSlackClientSocketMode(messages chan *config.Message) {
Copy link

qlty-cloud-legacy bot Jul 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method Bslack.handleSlackClientSocketMode has a Cognitive Complexity of 47 (exceeds 20 allowed). Consider refactoring.

kolsys force-pushed the master branch from 9127b70 to 9ac2c4b Compare July 1, 2024 12:33
Copy link

qlty-cloud-legacy bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR diff size of 236869 lines exceeds the maximum allowed for the inline comments feature.

Jaykul reacted with hooray emoji
- Added support of Event API in socketMode
- Fix files upload for new applications
kolsys force-pushed the master branch from 9ac2c4b to 5b86262 Compare July 1, 2024 12:37
Copy link

qlty-cloud-legacy bot commented Jul 1, 2024

Code Climate has analyzed commit 5b86262 and detected 4 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 4

View more on Code Climate.

nosovk approved these changes Jul 4, 2024
Copy link

petqa commented Jul 7, 2024

FROM golang:1.22.0-alpine3.19 AS builder

COPY matterbridge /go/src/matterbridge
RUN apk --no-cache add git \
&& go version \
&& cd /go/src/matterbridge \
&& CGO_ENABLED=0 go build -mod vendor -o /bin/matterbridge

FROM alpine:3.19
RUN apk --no-cache add ca-certificates mailcap
COPY --from=builder /bin/matterbridge /bin/matterbridge
RUN mkdir /etc/matterbridge \
&& touch /etc/matterbridge/matterbridge.toml \
&& ln -sf /matterbridge.toml /etc/matterbridge/matterbridge.toml
ENTRYPOINT ["/bin/matterbridge", "-conf", "/etc/matterbridge/matterbridge.toml"]

@kolsys Could you please update the Dockerfile? The current version in the master branch doesn't work correctly.

Copy link
Author

kolsys commented Jul 9, 2024

FROM golang:1.22.0-alpine3.19 AS builder

COPY matterbridge /go/src/matterbridge
RUN apk --no-cache add git \
&& go version \
&& cd /go/src/matterbridge \
&& CGO_ENABLED=0 go build -mod vendor -o /bin/matterbridge

FROM alpine:3.19
RUN apk --no-cache add ca-certificates mailcap
COPY --from=builder /bin/matterbridge /bin/matterbridge
RUN mkdir /etc/matterbridge \
&& touch /etc/matterbridge/matterbridge.toml \
&& ln -sf /matterbridge.toml /etc/matterbridge/matterbridge.toml
ENTRYPOINT ["/bin/matterbridge", "-conf", "/etc/matterbridge/matterbridge.toml"]

@kolsys Could you please update the Dockerfile? The current version in the master branch doesn't work correctly.

Whats wrong with the master version? I've build and run it.

Copy link

xeonic-ant commented Jul 12, 2024

Hi. We experiencing errors downloading images. Look like the file URL is empty.
Bot configured according your recommendations.

config

[api.api]
BindAddress="0.0.0.0:4242"
Buffer=1000
RemoteNickFormat="{NICK}"
[general]
MediaDownloadPath="/var/www/matterbridge"
MediaServerDownload="http://matterbridge.matterbridge-namespace/matterbridge"
[slack]
[slack.one]
Token="xoxb-*****"
AppToken="xapp-********"
PrefixMessagesWithNick=true
Debug=true
RemoteNickFormat="[{PROTOCOL}] <{NICK}> "
PreserveThreading=true
UseFullName=true
[mattermost]
[mattermost.two]
Server="company.com:443"
Team="team1"
Token="*****************"
RemoteNickFormat="[{PROTOCOL}] <{NICK}> "
PrefixMessagesWithNick=true
PreserveThreading=true
UseUserName=true
Debug=true
[[gateway]]
name="api"
enable=true
[[gateway.inout]]
account="api.api"
channel="api"
[[gateway]]
name="client"
enable=true
[[gateway.inout]]
account="mattermost.two"
channel="channel2"
[[gateway.inout]]
account="slack.one"
channel="channel1"

Also tried without MediaDownloadPath/MediaServerDownload options - result is the same.

logs

time="2024-07-12T11:23:12Z" level=debug msg="Message event: {"client_msg_id":"3c60172b-85be-20cb-bed3-1b041bdd51af","typ e":"message","user":"U05******","text":"test40","thread_ts": "1720779786.805609","ts":"1720783391.651979","channel":"C061 W7QFYPM","channel_type":"channel","event_ts":"1720783391.651 979","subtype":"file_share","upload":false,"files":[{"id":"F 07BZLYLJ6A","created":0,"timestamp":0,"name":"","title":""," mimetype":"","filetype":"png","pretty_type":"","user":"","ed itable":false,"size":0,"mode":"","is_external":false,"extern al_type":"","is_public":false,"public_url_shared":false,"dis play_as_bot":false,"username":"","url_private":"","url_priva te_download":"","thumb_64":"","thumb_80":"","thumb_360":""," thumb_360_w":0,"thumb_360_h":0,"thumb_480":"","thumb_480_w": 0,"thumb_480_h":0,"thumb_160":"","thumb_720":"","thumb_720_w ":0,"thumb_720_h":0,"thumb_800":"","thumb_800_w":0,"thumb_80 0_h":0,"thumb_960":"","thumb_960_w":0,"thumb_960_h":0,"thumb _1024":"","thumb_1024_w":0,"thumb_1024_h":0,"image_exif_rota tion":0,"original_w":0,"original_h":0,"permalink":"","permal ink_public":""}],"blocks":[{"type":"rich_text","block_id":"o 6CuE","elements":[{"type":"rich_text_section","elements":[{" type":"text","text":"test40"}]}]}],"root":null}" func=handleSlackClientSocketMode file="bridge/slack/handlers.go:99" prefix=slack
time="2024-07-12T11:23:12Z" level=debug msg="Trying to download "" with size 0" func=HandleDownloadSize file="bridge/helper/helper.go:162" prefix=slack
time="2024-07-12T11:23:12Z" level=error msg="Could not download incoming file: &errors.errorString{s:"download failed &url.Error{Op:\"Get\", URL:\"\", Err:(*errors.errorString)(0xc0009131e0)}"}" func=handleAttachments file="bridge/slack/handlers.go:460" prefix=slack

we are running bridge in k8s (without nat) but webockets seems to be work, pings look fine

slack-go/slack/socketmode2024/07/12 12:56:36 socket_mode_managed_conn.go:627: WebSocket ping message received: Ping from applink-13
slack-go/slack/socketmode2024/07/12 12:56:46 socket_mode_managed_conn.go:627: WebSocket ping message received: Ping from applink-13
time="2024-07-12T12:56:52Z" level=debug msg="WsReceiver response: &model.WebSocketResponse{Status:"OK", SeqReply:127, Data:map[string]interface {}{"node_id":"", "server_time":1.720789012475e+12, "text":"pong", "version":"9.2.2"}, Error:(*model.AppError)(nil)}" prefix=matterclient
time="2024-07-12T12:56:52Z" level=debug msg="getting response: &model.WebSocketResponse{Status:"OK", SeqReply:127, Data:map[string]interface {}{"node_id":"", "server_time":1.720789012475e+12, "text":"pong", "version":"9.2.2"}, Error:(*model.AppError)(nil)}" prefix=matterclient

Copy link
Author

kolsys commented Jul 12, 2024 *
edited
Loading

@xeonic-ant
Hi. Looks like the RTM attachment message format is not fully compatible with Event API and it's required to write more complex converter for message than my workaround:
https://github.com/42wim/matterbridge/pull/2161/files#diff-014f29c022fd23b8c7f870b5cfa1cb6905ca8a8eb1c83d0209d77d279f4962b9R97

Copy link

mfw78 commented Aug 16, 2024

Just confirming, is there any ability within this using the new slack app to post in a channel within slack using a nickname that isn't the same name as the bot (so as to preserve / bridge the nickname and avatar?)

unode mentioned this pull request Sep 23, 2024
Copy link

sbe-arg commented Dec 2, 2024

Any further progress on this one?

Copy link
Author

kolsys commented Dec 4, 2024

Any further progress on this one?

I will no support this patch because we've stopped to using Slack. But this version is work. You are welcome to modify this patch to extend support support of socket mode.

sbe-arg and InternetWorkAcct reacted with thumbs up emoji nosovk reacted with confused emoji

Copy link

jmomort commented Dec 28, 2024

Worked for me

Copy link

sbe-arg commented Dec 29, 2024

but can we get it merged?

nosovk, cxumol, GGonnerman, and Arusekk reacted with eyes emoji

Copy link

rwaffen commented Mar 21, 2025 *
edited
Loading

how do i build upon your fork? i want to use it for slack <-> irc bridging.

~ go install github.com/tippl/matterbridge@master
go: downloading github.com/tippl/matterbridge v0.0.0-20250130180600-cbb877b29f7e
go: github.com/tippl/matterbridge@master: version constraints conflict:
github.com/tippl/matterbridge@v0.0.0-20250130180600-cbb877b2 9f7e: parsing go.mod:
module declares its path as: github.com/42wim/matterbridge
but was required as: github.com/tippl/matterbridge

Copy link

bastelfreak commented May 6, 2025 *
edited
Loading

hi!
thanks a lot for the awesome PR and your documentation about the permissions. I was able to build it locally and I'm now syncing IRC <> slack with classic setup <> another slack with the new setup

edit: build instructions were as easy as:

git clone https://github.com/kolsys/matterbridge
cd matterbridge
go install

(thanks to a friend who pointed that out)

nosovk and rwaffen reacted with thumbs up emoji rwaffen reacted with hooray emoji

Copy link

sbe-arg commented May 6, 2025

No maintainers? @42wim

Copy link

BolajiAyodeji commented May 30, 2025

Hi! Any updates on merging this PR? Seems to have stalled.

Copy link

Jaykul commented Sep 20, 2025

Just confirming, is there any ability within this using the new slack app to post in a channel within slack using a nickname that isn't the same name as the bot (so as to preserve / bridge the nickname and avatar?)

you just need to add the chat:write.customize permission

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

2 more reviewers

qlty-cloud-legacy[bot] qlty-cloud-legacy[bot] left review comments

nosovk nosovk approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Slack app classic deprecation, can't add new bots since 06/06/2024