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

Links don't seem to be clickable #10

Open
chipotle opened this issue Feb 2, 2024 · 9 comments
Open

Links don't seem to be clickable #10

chipotle opened this issue Feb 2, 2024 · 9 comments

Comments

@chipotle
Copy link

chipotle commented Feb 2, 2024

I've been trying to write an autoposter that just posts "#{title} - #{link}" style posts from a blog, and I absolutely cannot get clickable links to be posted.

As far as I can tell, the link_pattern in the detect_facets method isn't working. I did some tests in local code with a much simpler regex pattern and your function, and this seems to be getting the right response. Unfortunately, I can't for the life of me figure out how to get this code into a local copy of the library that my autoposter will actually work with, because I am apparently hopelessly confused by Ruby's dependency management or how to build this specific gem or something. (I used your provided install-local.sh script with my change to the gem, but no matter what I do I get a uninitialized constant Bskyrb::Credentials (NameError) unless I load from the published Gem, which works flawlessly, except that the facets aren't being processed correctly and the links aren't clickable.)

This is the simple dumb pattern I used and the test. It basically just assumes anything that starts with https:// or http:// is a URL up until the next whitespace character. The only change to the enum_for.each loop is in the URI.parse, where I removed the trailing / (if one exists it will be grabbed by the regex).

text = 'New post: "Foobar" https://mywebsite.net/foo-bar/ and also https://other.com/thing and so on'
link_pattern = /(https?):\/\/(\S+)/

facets = []

text.enum_for(:scan, link_pattern).each do |m|
  index_start = Regexp.last_match.offset(0).first
  index_end = Regexp.last_match.offset(0).last
  m.compact!
  path = "#{m[1]}#{m[2..].join("")}".strip
  facets.push(
    "$type" => "app.bsky.richtext.facet",
    "index" => {
      "byteStart" => index_start,
      "byteEnd" => index_end,
    },
    "features" => [
      {
        "uri" => URI.parse("#{m[0]}://#{path}").normalize.to_s, # this is the matched link
        "$type" => "app.bsky.richtext.facet#link",
      },
    ],
  )
end

puts facets.inspect
@ShreyanJain9
Copy link
Owner

Sorry, I haven't looked at this for a while and I know a lot of things might be a bit broken. I'll probably try to fix this over the weekend. Do you mind if I just use your regex?

@chipotle
Copy link
Author

chipotle commented Feb 3, 2024

Certainly use it. But please give it a few tests to make sure I’m not missing something. I am not much of a regex wizard. :)

@derdennis
Copy link

Hello everybody. I found bskyrb with the same intention of posting "Hey, new blogpost at $URL" posts, got everything up and running and stumbled into the same issue with the non-clickable links. I too did not find the correct place to somehow patch things up with the regex from @chipotle.

@ShreyanJain9: Can you already tell, when you will incorporate this into the official gem?

Thank you very much for your great work so far.

@ShreyanJain9
Copy link
Owner

ShreyanJain9 commented Apr 12, 2024

Unfortunately I haven't had time to maintain this gem for a while, though I do plan to come back to it at some point in the future. In the meantime you may want to look at @mackuba's minisky tool, which is lower-level and will take some more effort to use on your part, but Kuba is very helpful and can probably help with a lot of the higher-level pieces you'll have to implement.

@sabat
Copy link

sabat commented Nov 20, 2024

I am not sure what the situation is now (Nov. 2024)—maybe @ShreyanJain9 has updated the repo and fixed bugs, haven't looked—but link facets are definitely working for me. I'm using the current git version, not the gem from rubygems (which doesn't have any code for facets).

(Facets in BlueSky are what let you make clickable links and @-sign mentions.)

Sample code that works for me:

credentials = ATProto::Credentials.new(username, password)
session = ATProto::Session.new(credentials)
bsky = Bskyrb::Client.new(session)
message = "Hello from bskyrb, link https://github.com/"
result = bsky.create_post_or_reply(message)
puts "Result: #{result['validationStatus']}"

On BlueSky, that message has a clickable link for github.com. Yay.

Minisky is cool, but I'm pretty sure it doesn't support facets at all yet. AFAIK bskyrb (git version!) is the only ruby gem that supports BlueSky's facets (therefore clickable links and mentions).

@derdennis
Copy link

This is good news, thanks for the headsup @sabat.

For my very basic need (New blogpost announcement) I fumbled together a working solution with minisky and the regex from @chipotle. I named it it_skeet.rb.

@searls
Copy link

searls commented Jan 27, 2025

I'm working on an app that uses this gem, which really helped give me a leg up on initially understanding the basic API (though I find that some of the rough edges are such that I'm considering eliminating the dependency).

For anyone looking for some tips on how to generate facets yourself, I shared a couple of file listings in a gist to look at as an example. YMMV

@ShreyanJain9
Copy link
Owner

I'm working on an app that uses this gem, which really helped give me a leg up on initially understanding the basic API (though I find that some of the rough edges are such that I'm considering eliminating the dependency).

For anyone looking for some tips on how to generate facets yourself, I shared a couple of file listings in a gist to look at as an example. YMMV

Yeah, I wrote the gem way back and I didn't understand the API that well when I did, and haven't really had time to maintain it since, so eliminating the dependency is probably not a bad idea for now :)

@searls
Copy link

searls commented Feb 7, 2025

It's working for me so far, and even if I ultimately cut it, thank you for the starting point!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants