Skip to content

Commit

Permalink
cmd/bsky-webhook: show timestamp in embed footer
Browse files Browse the repository at this point in the history
  • Loading branch information
Erisa committed Nov 20, 2024
1 parent a11ba29 commit fed11f9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cmd/bsky-webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"os"
"os/signal"
"path"
"strconv"
"strings"
"syscall"
"time"
Expand Down Expand Up @@ -262,7 +263,7 @@ func readJetstreamMessage(ctx context.Context, jetstreamMessageEncoded []byte, b
imageURL = fmt.Sprintf("https://cdn.bsky.app/img/feed_fullsize/plain/%s/%s", bskyMessage.Did, bskyMessage.Commit.Record.Embed.Images[0].Image.Ref.Link)
}

err = sendToSlack(ctx, jetstreamMessageStr, bskyMessage, imageURL, *profile)
err = sendToSlack(ctx, jetstreamMessageStr, bskyMessage, imageURL, *profile, postTime)
if err != nil {
slog.Error("slack error", "err", err)
}
Expand All @@ -286,14 +287,16 @@ func getBskyProfile(ctx context.Context, bskyMessage BskyMessage, bsky *bluesky.
return profile, nil
}

func sendToSlack(ctx context.Context, jetstreamMessageStr string, bskyMessage BskyMessage, imageURL string, profile bluesky.Profile) error {
func sendToSlack(ctx context.Context, jetstreamMessageStr string, bskyMessage BskyMessage, imageURL string, profile bluesky.Profile, postTime time.Time) error {
attachments := []SlackAttachment{
{
AuthorName: fmt.Sprintf("%s (@%s)", profile.Name, profile.Handle),
AuthorIcon: profile.AvatarURL,
AuthorLink: fmt.Sprintf("https://bsky.app/profile/%s", profile.Handle),
Text: fmt.Sprintf("%s\n<%s|View post on Bluesky ↗>", bskyMessage.Commit.Record.Text, bskyMessage.toURL(&profile.Handle)),
ImageUrl: imageURL,
Footer: "Posted",
Ts: strconv.FormatInt(postTime.Unix(), 10),
},
}

Expand Down
1 change: 1 addition & 0 deletions cmd/bsky-webhook/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type SlackAttachment struct {
Text string `json:"text"`
ImageUrl string `json:"image_url"`
Footer string `json:"footer"`
Ts string `json:"ts"`
}

type SlackBody struct {
Expand Down

0 comments on commit fed11f9

Please sign in to comment.