bluesky_text 0.4.2 copy "bluesky_text: ^0.4.2" to clipboard
bluesky_text: ^0.4.2 copied to clipboard

Provides the easiest and most powerful way to analyze the text on Bluesky Social.

example/example.dart

// Copyright 2023 Shinya Kato. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided the conditions.

// ignore_for_file: lines_longer_than_80_chars

import 'package:bluesky/bluesky.dart' as bsky;
import 'package:bluesky_text/bluesky_text.dart';

Future<void> main() async {
  //! You just need to pass text to parse.
  final text = BlueskyText(
    'I speak 日本語 and English 🚀 @shinyakato.dev and @shinyakato.bsky.social. '
    'Visit 🚀 https://shinyakato.dev.',
  );

  //! The character limit for Bluesky Social posts is 300 characters.
  //! You need to split it before call some properties.
  if (text.isLengthLimitExceeded) {
    //! Let's split.
    final texts = text.split();

    for (final text in texts) {
      print(text.handles);
      print(text.links);
      print(text.entities);
    }
  } else {
    //! If it is less than 300 characters, it can simply be parsed.

    // [{type: handle, value: @shinyakato.dev, indices: {start: 35, end: 50}},
    // {type: handle, value: @shinyakato.bsky.social, indices: {start: 55, end: 78}}]
    print(text.handles);

    // [{type: link, value: https://shinyakato.dev, indices: {start: 91, end: 113}}]
    print(text.links);

    // [{type: handle, value: @shinyakato.dev, indices: {start: 35, end: 50}},
    // {type: handle, value: @shinyakato.bsky.social, indices: {start: 55, end: 78}},
    // {type: link, value: https://shinyakato.dev, indices: {start: 91, end: 113}}]
    print(text.entities);

    //! And you can easily integrate with bluesky package!
    final bluesky = bsky.Bluesky.fromSession(await _session);
    final facets = await text.entities.toFacets();

    await bluesky.feeds.createPost(
      text: text.value,
      facets: facets.map(bsky.Facet.fromJson).toList(),
    );
  }
}

Future<bsky.Session> get _session async {
  final session = await bsky.createSession(
    service: 'SERVICE_NAME', //! The default is `bsky.social`
    identifier: 'YOUR_HANDLE_OR_EMAIL', //! Like `shinyakato.bsky.social`
    password: 'YOUR_PASSWORD',
  );

  return session.data;
}
10
likes
0
pub points
82%
popularity

Publisher

verified publisheratprotodart.com

Provides the easiest and most powerful way to analyze the text on Bluesky Social.

Homepage
Repository (GitHub)
View/report issues

Topics

#atproto #bluesky #util

Funding

Consider supporting this project:

github.com

License

unknown (license)

Dependencies

characters, freezed_annotation, icann_tlds, json_annotation, xrpc

More

Packages that depend on bluesky_text