Skip to content

Commit

Permalink
Add Bluesky bulk delivery method
Browse files Browse the repository at this point in the history
  • Loading branch information
excid3 committed Nov 12, 2024
1 parent 3b9ec9e commit efc521f
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 2 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Delivery methods we officially support:

Bulk delivery methods we support:

* [Bluesky](docs/bulk_delivery_methods/bluesky.md)
* [Discord](docs/bulk_delivery_methods/discord.md)
* [Slack](docs/bulk_delivery_methods/slack.md)
* [Webhook](docs/bulk_delivery_methods/webhook.md)
Expand Down Expand Up @@ -427,8 +428,8 @@ Recipients can also be computed inside a notifier:
class NewCommentNotifier < ApplicationNotifier
recipients ->{ params[:record].thread.all_authors }
# or
recipients do
# or
recipients do
params[:record].thread.all_authors
end
Expand Down Expand Up @@ -526,6 +527,7 @@ Individual delivery methods:

Bulk delivery methods:

* [Bluesky](docs/bulk_delivery_methods/bluesky.md)
* [Discord](docs/bulk_delivery_methods/discord.md)
* [Slack](docs/bulk_delivery_methods/slack.md)
* [Webhook](docs/bulk_delivery_methods/webhook.md)
Expand Down
21 changes: 21 additions & 0 deletions docs/bulk_delivery_methods/bluesky.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Bluesky Bulk Delivery Method

Create a Bluesky post.

## Usage

```ruby
class CommentNotification
bulk_deliver_by :bluesky do |config|
config.identifier = "username"
config.password = "password"
config.json = -> {
{
text: "Hello world!",
createdAt: Time.current.iso8601
# ...
}
}
end
end
```
1 change: 1 addition & 0 deletions lib/noticed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def self.deprecator # :nodoc:
autoload :Translation, "noticed/translation"

module BulkDeliveryMethods
autoload :Bluesky, "noticed/bulk_delivery_methods/bluesky"
autoload :Discord, "noticed/bulk_delivery_methods/discord"
autoload :Slack, "noticed/bulk_delivery_methods/slack"
autoload :Test, "noticed/bulk_delivery_methods/test"
Expand Down
49 changes: 49 additions & 0 deletions lib/noticed/bulk_delivery_methods/bluesky.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module Noticed
module BulkDeliveryMethods
class Bluesky < BulkDeliveryMethod
required_options :identifier, :password, :json

# bulk_deliver_by :bluesky do |config|
# config.identifier = ENV["BLUESKY_ID"]
# config.password = ENV["BLUESKY_PASSWORD"]
# config.json = {text: "...", createdAt: "..."}
# end

def deliver
Rails.logger.debug(evaluate_option(:json))
post_request(
"https://#{host}/xrpc/com.atproto.repo.createRecord",
headers: {"Authorization" => "Bearer #{token}"},
json: {
repo: identifier,
collection: "app.bsky.feed.post",
record: evaluate_option(:json)
},
)
end

def token
start_session.dig("accessJwt")
end

def start_session
response = post_request(
"https://#{host}/xrpc/com.atproto.server.createSession",
json: {
identifier: identifier,
password: evaluate_option(:password)
}
)
JSON.parse(response.body)
end

def host
@host ||= evaluate_option(:host) || "bsky.social"
end

def identifier
@identifier ||= evaluate_option(:identifier)
end
end
end
end

0 comments on commit efc521f

Please sign in to comment.