huginn_bluesky_authorfeed_agent 0.1.O
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7e1d05533b1d91a4a55a7c7664e4d682481ced1cdfbb2ca1778c2a50d0a01081
|
4
|
+
data.tar.gz: 68412b0cfc4db10204f7dd1a1ff02a53dcdc30180c00e119327072684d51c8c4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: db0eb9bec22d9b6ce225b0a80284076f597f60451058edac18579e37eccdf4953d4d0586e7323f542631585f78eca35e9d47dc43ad3e1e51268370e0a37dec9e
|
7
|
+
data.tar.gz: 0b4dd9d1117b48891b69d962b7cdccaf1feb26f7134053e87e43baa44fe3bd3a4fa9b027d173154db4e7fa093343576aac9b5da659721d833e3cbb718390935e
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2023 Nicolas Germain
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,182 @@
|
|
1
|
+
module Agents
|
2
|
+
class BlueskyAuthorfeedAgent < Agent
|
3
|
+
include FormConfigurable
|
4
|
+
can_dry_run!
|
5
|
+
no_bulk_receive!
|
6
|
+
default_schedule 'every_1h'
|
7
|
+
|
8
|
+
description do
|
9
|
+
<<-MD
|
10
|
+
The Bluesky Publish Agent publishes posts from the events it receives.
|
11
|
+
|
12
|
+
To be able to use this Agent you need to authenticate with Twitter with [twurl](https://github.com/twitter/twurl).
|
13
|
+
|
14
|
+
You must also specify a `message` parameter, you can use [Liquid](https://github.com/huginn/huginn/wiki/Formatting-Events-using-Liquid) to format the message.
|
15
|
+
Additional parameters can be passed via `parameters`.
|
16
|
+
|
17
|
+
`debug` is used for verbose mode.
|
18
|
+
|
19
|
+
`handle` is mandatory for authentication.
|
20
|
+
|
21
|
+
`user` is the wanted user you want to check.
|
22
|
+
|
23
|
+
`app_password` is mandatory for authentication.
|
24
|
+
|
25
|
+
`expected_receive_period_in_days` is used to determine if the Agent is working. Set it to the maximum number of days
|
26
|
+
that you anticipate passing without this Agent receiving an incoming Event.
|
27
|
+
MD
|
28
|
+
end
|
29
|
+
|
30
|
+
event_description <<-MD
|
31
|
+
Events look like this:
|
32
|
+
|
33
|
+
{
|
34
|
+
}
|
35
|
+
MD
|
36
|
+
|
37
|
+
def default_options
|
38
|
+
{
|
39
|
+
'user' => '',
|
40
|
+
'debug' => 'false',
|
41
|
+
'handle' => '',
|
42
|
+
'app_password' => '',
|
43
|
+
'expected_receive_period_in_days' => '2',
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
form_configurable :user, type: :string
|
48
|
+
form_configurable :debug, type: :boolean
|
49
|
+
form_configurable :app_password, type: :string
|
50
|
+
form_configurable :handle, type: :string
|
51
|
+
form_configurable :expected_receive_period_in_days, type: :string
|
52
|
+
def validate_options
|
53
|
+
unless options['user'].present?
|
54
|
+
errors.add(:base, "user is a required field")
|
55
|
+
end
|
56
|
+
|
57
|
+
unless options['app_password'].present?
|
58
|
+
errors.add(:base, "app_password is a required field")
|
59
|
+
end
|
60
|
+
|
61
|
+
unless options['handle'].present?
|
62
|
+
errors.add(:base, "handle is a required field")
|
63
|
+
end
|
64
|
+
|
65
|
+
if options.has_key?('debug') && boolify(options['debug']).nil?
|
66
|
+
errors.add(:base, "if provided, debug must be true or false")
|
67
|
+
end
|
68
|
+
|
69
|
+
unless options['expected_receive_period_in_days'].present? && options['expected_receive_period_in_days'].to_i > 0
|
70
|
+
errors.add(:base, "Please provide 'expected_receive_period_in_days' to indicate how many days can pass before this Agent is considered to be not working")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def working?
|
75
|
+
event_created_within?(options['expected_receive_period_in_days']) && !recent_error_logs?
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
def check
|
80
|
+
get_feed()
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def log_curl_output(code,body)
|
86
|
+
|
87
|
+
log "request status : #{code}"
|
88
|
+
|
89
|
+
if interpolated['debug'] == 'true'
|
90
|
+
log "body"
|
91
|
+
log body
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
def generate_did(user)
|
97
|
+
uri = URI.parse("https://bsky.social/xrpc/com.atproto.identity.resolveHandle")
|
98
|
+
params = { :handle => user }
|
99
|
+
uri.query = URI.encode_www_form(params)
|
100
|
+
response = Net::HTTP.get_response(uri)
|
101
|
+
|
102
|
+
log_curl_output(response.code,response.body)
|
103
|
+
|
104
|
+
return JSON.parse(response.body)['did']
|
105
|
+
end
|
106
|
+
|
107
|
+
def generate_api_key(did)
|
108
|
+
uri = URI.parse("https://bsky.social/xrpc/com.atproto.server.createSession")
|
109
|
+
request = Net::HTTP::Post.new(uri)
|
110
|
+
request.content_type = "application/json"
|
111
|
+
request.body = JSON.dump({
|
112
|
+
"identifier" => did,
|
113
|
+
"password" => interpolated['app_password']
|
114
|
+
})
|
115
|
+
|
116
|
+
req_options = {
|
117
|
+
use_ssl: uri.scheme == "https",
|
118
|
+
}
|
119
|
+
|
120
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
121
|
+
http.request(request)
|
122
|
+
end
|
123
|
+
|
124
|
+
log_curl_output(response.code,response.body)
|
125
|
+
|
126
|
+
return JSON.parse(response.body)['accessJwt']
|
127
|
+
end
|
128
|
+
|
129
|
+
def get_feed()
|
130
|
+
|
131
|
+
did = generate_did(interpolated['handle'])
|
132
|
+
uri = URI.parse("https://bsky.social/xrpc/app.bsky.feed.getAuthorFeed?actor=#{generate_did(interpolated['user'])}&limit=30")
|
133
|
+
request = Net::HTTP::Get.new(uri)
|
134
|
+
request["Authorization"] = "Bearer #{generate_api_key(did)}"
|
135
|
+
|
136
|
+
req_options = {
|
137
|
+
use_ssl: uri.scheme == "https",
|
138
|
+
}
|
139
|
+
|
140
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
141
|
+
http.request(request)
|
142
|
+
end
|
143
|
+
|
144
|
+
log_curl_output(response.code,response.body)
|
145
|
+
|
146
|
+
payload = JSON.parse(response.body)
|
147
|
+
|
148
|
+
if payload != memory['last_status']
|
149
|
+
payload['feed'].each do |feed|
|
150
|
+
found = false
|
151
|
+
if !memory['last_status'].nil? and memory['last_status']['feed'].present?
|
152
|
+
last_status = memory['last_status']
|
153
|
+
if interpolated['debug'] == 'true'
|
154
|
+
log "last_status"
|
155
|
+
log last_status
|
156
|
+
end
|
157
|
+
last_status["feed"].each do |feedbis|
|
158
|
+
if feed == feedbis
|
159
|
+
found = true
|
160
|
+
if interpolated['debug'] == 'true'
|
161
|
+
log "found is #{found}"
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
if found == false
|
167
|
+
create_event payload: feed
|
168
|
+
else
|
169
|
+
if interpolated['debug'] == 'true'
|
170
|
+
log "found is #{found}"
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
memory['last_status'] = payload
|
175
|
+
else
|
176
|
+
if interpolated['debug'] == 'true'
|
177
|
+
log "no diff"
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
require 'huginn_agent/spec_helper'
|
3
|
+
|
4
|
+
describe Agents::BlueskyAuthorfeedAgent do
|
5
|
+
before(:each) do
|
6
|
+
@valid_options = Agents::BlueskyAuthorfeedAgent.new.default_options
|
7
|
+
@checker = Agents::BlueskyAuthorfeedAgent.new(:name => "BlueskyAuthorfeedAgent", :options => @valid_options)
|
8
|
+
@checker.user = users(:bob)
|
9
|
+
@checker.save!
|
10
|
+
end
|
11
|
+
|
12
|
+
pending "add specs here"
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: huginn_bluesky_authorfeed_agent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.O
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nicolas Germain
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-12-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.1.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 12.3.3
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 12.3.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: huginn_agent
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Write a longer description or delete this line.
|
56
|
+
email:
|
57
|
+
- ngermain@hihouhou.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- LICENSE.txt
|
63
|
+
- lib/huginn_bluesky_authorfeed_agent.rb
|
64
|
+
- lib/huginn_bluesky_authorfeed_agent/bluesky_authorfeed_agent.rb
|
65
|
+
- spec/bluesky_authorfeed_agent_spec.rb
|
66
|
+
homepage: https://github.com/hihouhou/huginn_bluesky_authorfeed_agent
|
67
|
+
licenses:
|
68
|
+
- MIT
|
69
|
+
metadata: {}
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 1.3.1
|
84
|
+
requirements: []
|
85
|
+
rubygems_version: 3.3.3
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: Write a short summary, because Rubygems requires one.
|
89
|
+
test_files:
|
90
|
+
- spec/bluesky_authorfeed_agent_spec.rb
|