Class: BlueFactory::Interaction
- Inherits:
-
Object
- Object
- BlueFactory::Interaction
- Defined in:
- lib/blue_factory/interaction.rb
Overview
Represents a single feed interaction event.
Interactions are various kinds of events registered while a user is browsing the feed,
either automatically in response to their browsing (e.g. "post seen", "post liked") or as
explicit actions taken consciously by the user, with the intention of passing information back
to the feed operator (clicking "show more like this" / "show less like this" in the post context
menu). Interactions are submitted through the app.bsky.feed.sendInteractions endpoint and may
be batched.
When that endpoint is called, BlueFactory wraps the submitted interaction objects in instances of Interaction and passes them to the configured handler block, which is set up through BlueFactory::Interactions#on_interactions or BlueFactory::Interactions#interactions_handler= on BlueFactory.
Note: the Interaction objects include info about what interaction has been triggered and
on which specific post (post AT URI), but they don't include info in which feed it has been
triggered. If you have multiple feeds configured and need to know which feed an interaction
is from, you need to include either a context field (assigned to a specific post) or a
req_id field (assigned to the whole request) in the data response returned from
FeedHandler#get_posts.
Constant Summary collapse
- EVENTS =
Mapping of interaction identifiers in the protocol to short code symbols.
{ # user has liked a post in the feed 'app.bsky.feed.defs#interactionLike' => :like, # user has quoted a post in the feed 'app.bsky.feed.defs#interactionQuote' => :quote, # user has replied to a post in the feed 'app.bsky.feed.defs#interactionReply' => :reply, # user has reposted a post in the feed 'app.bsky.feed.defs#interactionRepost' => :repost, # user has scrolled down to the given post 'app.bsky.feed.defs#interactionSeen' => :seen, # user has clicked "show less like this" on a post 'app.bsky.feed.defs#requestLess' => :request_less, # user has clicked "show more like this" on a post 'app.bsky.feed.defs#requestMore' => :request_more }
Instance Attribute Summary collapse
-
#context ⇒ String?
readonly
Optional post context from the original response.
-
#event ⇒ String
readonly
The protocol identifier of the interaction type.
-
#item ⇒ String
readonly
The URI of the post.
-
#req_id ⇒ String?
readonly
Optional request identifier from the original response.
-
#type ⇒ Symbol?
readonly
Short code symbol of the interaction type.
Instance Method Summary collapse
-
#initialize(data) ⇒ Interaction
constructor
A new instance of Interaction.
Constructor Details
#initialize(data) ⇒ Interaction
Returns a new instance of Interaction.
72 73 74 75 76 77 78 |
# File 'lib/blue_factory/interaction.rb', line 72 def initialize(data) @item = data['item'] @event = data['event'] @context = data['feedContext'] @req_id = data['reqId'] @type = EVENTS[@event] end |
Instance Attribute Details
#context ⇒ String? (readonly)
Returns optional post context from the original response.
64 65 66 |
# File 'lib/blue_factory/interaction.rb', line 64 def context @context end |
#event ⇒ String (readonly)
Returns the protocol identifier of the interaction type.
58 59 60 |
# File 'lib/blue_factory/interaction.rb', line 58 def event @event end |
#item ⇒ String (readonly)
Returns the URI of the post.
55 56 57 |
# File 'lib/blue_factory/interaction.rb', line 55 def item @item end |
#req_id ⇒ String? (readonly)
Returns optional request identifier from the original response.
67 68 69 |
# File 'lib/blue_factory/interaction.rb', line 67 def req_id @req_id end |
#type ⇒ Symbol? (readonly)
Returns short code symbol of the interaction type.
61 62 63 |
# File 'lib/blue_factory/interaction.rb', line 61 def type @type end |