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

Support message attachments legacy fields #39

Merged
merged 5 commits into from
Apr 5, 2024

Conversation

twouters
Copy link
Contributor

@twouters twouters commented Oct 9, 2023

As documented at https://api.slack.com/reference/messaging/attachments

Some bots that are used at my employer use the legacy attachments formatting instead of blocks so I hacked this in.
This should probably be a separate function and could be refactored to reduce some nesting, but this is what I'm running right now.

The current version is missing support for the following items because I haven't got around to handle images inside messages but it shouldn't be too hard to implement by refactoring renderImageBlock a bit:

  • author_icon
  • footer_icon
  • image_url
  • thumb_url

Not sure if this warrants a draft to wait until images are handled or if this can be added as is (after review).

@twouters twouters closed this Oct 9, 2023
@twouters twouters reopened this Oct 9, 2023
@twouters
Copy link
Contributor Author

twouters commented Oct 9, 2023

forgot to mention that the code doesn't take the mrkdwn_in field into account, because Slack does parse some stuff like custom emoji even though the fields aren't mentioned in mrkdwn_in

@twouters twouters force-pushed the feature/attachments-legacy-fields branch from a86bf1c to f5d821f Compare October 9, 2023 17:16
blocks.go Outdated
}
ts, _ := attachment.Ts.Int64()
t := time.Unix(ts, 0)
htmlText.WriteString(fmt.Sprintf("%s", t.Local().Format("Jan 02, 2006 15:04:05")))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just noticed that the docker image doesn't have the tzdata package installed, which is probably required to use the local timezone instead of UTC here.

@twouters twouters force-pushed the feature/attachments-legacy-fields branch from f5d821f to ec3b339 Compare October 9, 2023 19:09
@twouters twouters force-pushed the feature/attachments-legacy-fields branch from 84e9fd4 to 801e70c Compare October 10, 2023 09:42
@twouters twouters force-pushed the feature/attachments-legacy-fields branch from 801e70c to 0f5eedc Compare October 10, 2023 13:53
@tulir tulir merged commit d693066 into mautrix:main Apr 5, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants