42wim / matterbridge

bridge between mattermost, IRC, gitter, xmpp, slack, discord, telegram, rocketchat, twitch, ssh-chat, zulip, whatsapp, keybase, matrix, microsoft teams, nextcloud, mumble, vk and more with REST API (mattermost not required!)
Apache License 2.0
6.57k stars 616 forks source link

Avatar spoofing not working with Slack when following documentation #1556

Open KidA001 opened 3 years ago

KidA001 commented 3 years ago

Describe the bug With a local mediaserver setup and validated along with webhooks enabled, avatars are not being displayed from Telegram to Slack.

My matterbridge.toml

[general]
MediaDownloadPath="/var/www/matterbridge"
MediaServerDownload="http://{redacted}/media"

[slack]
[slack.collidervc]
RemoteNickFormat="{LABEL} | @{NICK}"
MessageSplit=true
WebhookUrl="secret-in-env-file"
Debug="true"

[telegram.Telegram]
Token="secret-in-env-file"
RemoteNickFormat="({PROTOCOL}) {NICK} "
MessageFormat="HTMLNick"
EditSuffix=" (edited)"
Label="Telegram | Testing Relay"
MessageSplit=true

[[gateway]]
name="gateway1"
enable=true

[[gateway.in]]
account="telegram.Telegram"
channel="-572179530"

[[gateway.out]]
account="slack.collidervc"
channel="collider-bot-testing"

I have validated that avatar PNGs are being downloaded to /var/www/matterbridge and I have also validated that they are publicly available from the MediaServerDownload url.

Here are my logs from matterbridge which show the dowload is successful but Avatar is still empty

time="2021-07-27T10:45:06Z" level=debug msg="Trying to download "1843720526.png" with size 3373" func=HandleDownloadSize file="bridge/helper/helper.go:159" prefix=telegram
time="2021-07-27T10:45:06Z" level=debug msg="Download OK "1843720526.png" 3373" func=HandleDownloadData file="bridge/helper/helper.go:175" prefix=telegram
time="2021-07-27T10:45:06Z" level=debug msg="<= Sending message from Collider on telegram.Telegram to gateway" func=handleRecv file="bridge/telegram/handlers.go:173" prefix=telegram
time="2021-07-27T10:45:06Z" level=debug msg="<= Message is config.Message{Text:"test", Channel:"-572179530", Username:"Collider", UserID:"1843720526", Avatar:"", Account:"telegram.Telegram", Event:"", Protocol:"", Gateway:"", ParentID:"", Timestamp:time.Time{wall:0x0, ext:0, loc:(*time.Location)(nil)}, ID:"80", Extra:map[string][]interface {}{}}" func=handleRecv file="bridge/telegram/handlers.go:174" prefix=telegram
time="2021-07-27T10:45:06Z" level=debug msg="mediaserver path placing file: /var/www/matterbridge/bb735cc0/1843720526.png" func=handleFilesLocal file="gateway/handlers.go:158" prefix=gateway
time="2021-07-27T10:45:06Z" level=debug msg="mediaserver download URL = http://{redacted}/media/bb735cc0/1843720526.png" func=handleFiles file="gateway/handlers.go:112" prefix=gateway
time="2021-07-27T10:45:06Z" level=debug msg="=> Sending config.Message{Text:"test", Channel:"-572179530", Username:"Collider", UserID:"1843720526", Avatar:"", Account:"telegram.Telegram", Event:"", Protocol:"telegram", Gateway:"gateway1", ParentID:"", Timestamp:time.Time{wall:0xc03816cc8ef21770, ext:487920212311, loc:(*time.Location)(0x339f980)}, ID:"80", Extra:map[string][]interface {}{}} from telegram.Telegram (-572179530) to slack.collidervc (collider-bot-testing)" func=SendMessage file="gateway/gateway.go:479" prefix=gateway
time="2021-07-27T10:45:06Z" level=debug msg="=> Receiving config.Message{Text:"test", Channel:"collider-bot-testing", Username:"Telegram | Testing Relay | @Collider", UserID:"1843720526", Avatar:"", Account:"telegram.Telegram", Event:"", Protocol:"telegram", Gateway:"gateway1", ParentID:"", Timestamp:time.Time{wall:0xc03816cc8ef21770, ext:487920212311, loc:(*time.Location)(0x339f980)}, ID:"", Extra:map[string][]interface {}{}}" func=Send file="bridge/slack/slack.go:195" prefix=slack
time="2021-07-27T10:45:06Z" level=debug msg="=> Send from telegram.Telegram (-572179530) to slack.collidervc (collider-bot-testing) took 260.931679ms" func=func1 file="gateway/gateway.go:488" prefix=gateway

I have sent multiple chats from different users to wait for the avatar to download, but still nothing is displayed

I'm also a bit confused as per slacks documentation: You cannot override the default channel (chosen by the user who installed your app), username, or icon when you're using Incoming Webhooks to post messages. Instead, these values will always inherit from the associated Slack app configuration.

To Reproduce Steps to reproduce the behavior: use setup as above

Expected behavior Avatar to display from Telegram to Slack when Mediaserver is present

Screenshots/debug logs image image

Environment (please complete the following information):

42wim commented 3 years ago

Could be that slack changed/deprecated this. Can you try with adding a static IconURL ? like

iconurl="http://{redacted}/media/bb735cc0/1843720526.png" to your [slack.collidervc] config?

KidA001 commented 3 years ago

@42wim tested with above and manually setting the iconurl works in slack, but still doesn't work automatically pulling the icon from Telegram to Slack with mediaserver enabled

Is there any other logs or config I should share to see what's going on?

KidA001 commented 3 years ago

When iconurl was set it was present in the request in chat.go:233

Now that it's removed it's not adding any url for the icon even though my mediaserver is setup and the users have icons

slack-go/slack2021/08/02 10:35:17 users.go:354: GetUsersContext: got 45 users; metadata { [] []}
slack-go/slack2021/08/02 10:35:42 chat.go:233: Sending request: blocks=%5B%7B%22type%22%3A%22section%22%2C%22text%22%3A%7B%22type%22%3A%22mrkdwn%22%2C%22text%22%3A%22removed+manual+icon%22%7D%2C%22block_id%22%3A%22matterbridge_c43skora0v1vioqhme2g%22%7D%5D&channel={redacted}&link_names=1&text=removed+manual+icon&token=xoxb-{redacted}&unfurl_links=true&username=Telegram+%7C+Testing+Relay+%7C+%40Brian
slack-go/slack2021/08/02 10:35:42 websocket_managed_conn.go:387: Incoming Event: {"type":"message","subtype":"bot_message","text":"removed manual icon","suppress_notification":false,"username":"Telegram | Testing Relay | @Brian","bot_id":"B027R3HH2FK","team":"TBCBBPCRE","bot_profile":{"id":"B027R3HH2FK","deleted":false,"name":"ColliderRelayBot","updated":1626785964,"app_id":"A0279CNSQLD","icons":{"image_36":"https:\/\/a.slack-edge.com\/80588\/img\/plugins\/app\/bot_36.png","image_48":"https:\/\/a.slack-edge.com\/80588\/img\/plugins\/app\/bot_48.png","image_72":"https:\/\/a.slack-edge.com\/80588\/img\/plugins\/app\/service_72.png"},"team_id":"{redacted}"},"blocks":[{"type":"section","block_id":"matterbridge_c43skora0v1vioqhme2g","text":{"type":"mrkdwn","text":"removed manual icon","verbatim":false}}],"source_team":"{redacted}","user_team":"{redacted}","channel":"{redacted}","event_ts":"1627900542.001000","ts":"1627900542.001000"}
KidA001 commented 3 years ago

@42wim I'm really glad to look into this myself. Wondering if you have any inklings on what or where the issue might lie?

I know that Telegram only downloads avatars if a Media Server is present (See here). I've confirmed that the avatar gets downloaded to my Media server, and that the path to the Icon is publicly available on my server. What I'm not seeing is the avatar url present in the slack message.

Any pointers appreciated, happy to do the work on my end and put up a PR