Skip to content

Commit efc521f

Browse files
committed
Add Bluesky bulk delivery method
1 parent 3b9ec9e commit efc521f

File tree

4 files changed

+75
-2
lines changed

4 files changed

+75
-2
lines changed

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Delivery methods we officially support:
4141

4242
Bulk delivery methods we support:
4343

44+
* [Bluesky](docs/bulk_delivery_methods/bluesky.md)
4445
* [Discord](docs/bulk_delivery_methods/discord.md)
4546
* [Slack](docs/bulk_delivery_methods/slack.md)
4647
* [Webhook](docs/bulk_delivery_methods/webhook.md)
@@ -427,8 +428,8 @@ Recipients can also be computed inside a notifier:
427428
class NewCommentNotifier < ApplicationNotifier
428429
recipients ->{ params[:record].thread.all_authors }
429430
430-
# or
431-
recipients do
431+
# or
432+
recipients do
432433
params[:record].thread.all_authors
433434
end
434435
@@ -526,6 +527,7 @@ Individual delivery methods:
526527

527528
Bulk delivery methods:
528529

530+
* [Bluesky](docs/bulk_delivery_methods/bluesky.md)
529531
* [Discord](docs/bulk_delivery_methods/discord.md)
530532
* [Slack](docs/bulk_delivery_methods/slack.md)
531533
* [Webhook](docs/bulk_delivery_methods/webhook.md)

docs/bulk_delivery_methods/bluesky.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Bluesky Bulk Delivery Method
2+
3+
Create a Bluesky post.
4+
5+
## Usage
6+
7+
```ruby
8+
class CommentNotification
9+
bulk_deliver_by :bluesky do |config|
10+
config.identifier = "username"
11+
config.password = "password"
12+
config.json = -> {
13+
{
14+
text: "Hello world!",
15+
createdAt: Time.current.iso8601
16+
# ...
17+
}
18+
}
19+
end
20+
end
21+
```

lib/noticed.rb

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def self.deprecator # :nodoc:
2020
autoload :Translation, "noticed/translation"
2121

2222
module BulkDeliveryMethods
23+
autoload :Bluesky, "noticed/bulk_delivery_methods/bluesky"
2324
autoload :Discord, "noticed/bulk_delivery_methods/discord"
2425
autoload :Slack, "noticed/bulk_delivery_methods/slack"
2526
autoload :Test, "noticed/bulk_delivery_methods/test"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
module Noticed
2+
module BulkDeliveryMethods
3+
class Bluesky < BulkDeliveryMethod
4+
required_options :identifier, :password, :json
5+
6+
# bulk_deliver_by :bluesky do |config|
7+
# config.identifier = ENV["BLUESKY_ID"]
8+
# config.password = ENV["BLUESKY_PASSWORD"]
9+
# config.json = {text: "...", createdAt: "..."}
10+
# end
11+
12+
def deliver
13+
Rails.logger.debug(evaluate_option(:json))
14+
post_request(
15+
"https://#{host}/xrpc/com.atproto.repo.createRecord",
16+
headers: {"Authorization" => "Bearer #{token}"},
17+
json: {
18+
repo: identifier,
19+
collection: "app.bsky.feed.post",
20+
record: evaluate_option(:json)
21+
},
22+
)
23+
end
24+
25+
def token
26+
start_session.dig("accessJwt")
27+
end
28+
29+
def start_session
30+
response = post_request(
31+
"https://#{host}/xrpc/com.atproto.server.createSession",
32+
json: {
33+
identifier: identifier,
34+
password: evaluate_option(:password)
35+
}
36+
)
37+
JSON.parse(response.body)
38+
end
39+
40+
def host
41+
@host ||= evaluate_option(:host) || "bsky.social"
42+
end
43+
44+
def identifier
45+
@identifier ||= evaluate_option(:identifier)
46+
end
47+
end
48+
end
49+
end

0 commit comments

Comments
 (0)