[][src]Crate misskey

Asynchronous client for Misskey.

We provide four components in this crate:

  • Clients that handles the connection between Misskey. As Misskey provides HTTP and WebSocket interfaces to interact with, we have HttpClient and WebSocketClient implementations correspondingly.
  • API bindings, including requests/responses of endpoints and messages on channels.
  • Abstraction that connects API datatypes and client implementations: Request, ConnectChannelRequest, etc.
  • High-level API for easier handling of various functionalities: ClientExt and others.

Examples

Create a note:

use misskey::prelude::*;
use misskey::HttpClient;

let client = HttpClient::builder("https://your.instance.example/api/")
    .token("API_TOKEN")
    .build()?;

client.create_note("Hello, Misskey").await?;

Automatically follow-back:

use futures::stream::TryStreamExt;
use misskey::prelude::*;
use misskey::streaming::channel::main::MainStreamEvent;
use misskey::WebSocketClient;

let client = WebSocketClient::builder("wss://your.instance.example/streaming")
    .token("YOUR_API_TOKEN")
    .connect()
    .await?;

// Connect to the main stream.
// The main stream is a channel that streams events about the connected account.
let mut stream = client.main_stream().await?;

// Wait for the next event in the main stream.
while let Some(event) = stream.try_next().await? {
    match event {
        // Check if the event is 'followed' and the user is not a bot
        MainStreamEvent::Followed(user) if !user.is_bot => {
            println!("followed from @{}", user.username);

            // Follow back `user` if you haven't already.
            if !client.is_following(&user).await? {
                client.follow(&user).await?;
            }
        }
        // other events are just ignored here
        _ => {}
   }
}

See the example directory for more examples.

Feature flags

  • http-client: Enables the HTTP client which is capable for uploading files. Enabled by default.
  • websocket-client: Enables the WebSocket client which is capable for streaming. Enabled by default.
  • tokio-runtime: Use the tokio v0.3 runtime in the WebSocket client. Enabled by default.
  • tokio02-runtime: Use the tokio v0.2 runtime in the WebSocket client.
  • async-std-runtime: Use the async-std runtime in the WebSocket client.
  • aid: Assume that the aid ID generation method is used in the targeted Misskey instance. Enabled by default.
  • meid: Assume that the meid ID generation method is used in the targeted Misskey instance.
  • ulid: Assume that the ulid ID generation method is used in the targeted Misskey instance.
  • objectid: Assume that the objectid ID generation method is used in the targeted Misskey instance.
  • and version flags, as described in version flags section.

Specifying Misskey version

We have a set of feature flags to specify the targeted Misskey version. The latest one (12-63-0) is enabled as a default. You can opt-in to compile for prior Misskey version by using default-features = false and the corresponding feature flag.

For example, to compile for Misskey v12.33.0 with WebSocket client on async-std runtime, add the following to your Cargo.toml file:

[dependencies.misskey]
version = "0.2"
default-features = false
features = ["12-31-0", "websocket-client", "async-std-runtime", "aid"]
FeatureSupported Misskey versions (inclusive)Tested Misskey version
12-63-0v12.63.0v12.63.0
12-62-2v12.62.2v12.62.2
12-62-0v12.62.0 ~ v12.62.1v12.62.0
12-61-0v12.61.0 ~ v12.61.1v12.61.0
12-60-0v12.60.0 ~ v12.60.1v12.60.0
12-58-0v12.58.0 ~ v12.59.0v12.58.0
12-57-0v12.57.0 ~ v12.57.4v12.57.1
12-55-0v12.55.0 ~ v12.56.0v12.55.0
12-51-0v12.51.0 ~ v12.54.0v12.51.0
12-49-0v12.49.0 ~ v12.50.0v12.49.0
12-48-0v12.48.0 ~ v12.48.3v12.48.0
12-47-0v12.47.0 ~ v12.47.1v12.47.1
12-42-0v12.42.0 ~ v12.46.0v12.42.0
12-39-0v12.39.0 ~ v12.41.3v12.39.0
12-37-0v12.37.0 ~ v12.38.1v12.37.0
12-31-0v12.31.0 ~ v12.36.1v12.31.0
12-29-0v12.29.0 ~ v12.30.0v12.29.0
12-28-0v12.28.0v12.28.0
12-27-0v12.27.0 ~ v12.27.1v12.27.0
12-19-0v12.19.0 ~ v12.26.0v12.20.0
12-13-0v12.13.0 ~ v12.18.1v12.13.0
12-10-0v12.10.0 ~ v12.12.0v12.10.0
12-9-0v12.9.0v12.9.0
12-8-0v12.8.0v12.8.0
12-5-0v12.5.0 ~ v12.7.1v12.5.0
(no version flag enabled)v12.0.0 ~ v12.4.1v12.0.0

Modules

builder

Builder types.

endpoint

API endpoints.

httphttp-client

Asynchronous HTTP-based client.

model

Object types used in API.

pager

Implementation of pagination.

prelude

Prelude for crates using misskey-rs.

streaming

Streaming API.

websocketwebsocket-client

Asynchronous WebSocket-based client.

Structs

HttpClienthttp-client

Asynchronous HTTP-based client for Misskey.

WebSocketClientwebsocket-client

Asynchronous WebSocket-based client for Misskey.

Enums

Error

Possible errors from the high-level API.

TimelineCursor

Point on the timeline.

TimelineRange

Range in the timeline.

Traits

Client

Abstraction over API clients.

ClientExt

An extension trait for Client that provides convenient high-level APIs.

StreamingClient

Abstraction over API clients with streaming connections.

StreamingClientExt

An extension trait for StreamingClient that provides convenient high-level APIs.

UploadFileClient

Abstraction over API clients that can upload files.

UploadFileClientExt

An extension trait for UploadFileClient that provides convenient high-level APIs.