Fork of misskey.js for Foundkey (Moved to main FoundKey repository) https://akkoma.dev/FoundKeyGang/FoundKey
This repository has been archived on 2022-10-04. You can view files and clone it, but cannot push or open issues or pull requests.
Go to file
syuilo b6df8cc1f5 Add tests 2021-06-27 21:17:42 +09:00
.github/workflows codecov integration 2021-06-25 09:46:40 +09:00
src Improve type 2021-06-27 21:17:38 +09:00
test Add tests 2021-06-27 21:17:42 +09:00
test-d Add tests 2021-06-27 21:17:42 +09:00
.editorconfig tab 2021-05-16 18:22:19 +09:00
.gitignore Add ignore config 2021-05-15 01:53:41 +09:00
LICENSE Initial commit 2021-05-11 14:14:30 +09:00
README.md codecov integration 2021-06-25 09:46:40 +09:00
codecov.yml codecov integration 2021-06-25 09:46:40 +09:00
i-want-you.png i want you 2021-05-14 12:00:10 +09:00
jest.config.ts wip 2021-05-14 13:49:40 +09:00
package-lock.json Update deps 2021-06-25 09:12:18 +09:00
package.json 0.0.5 2021-06-26 02:04:46 +09:00
tsconfig.json fix typescript config 2021-06-08 11:31:53 +09:00

README.md

misskey.js

Strongly-typed official Misskey SDK for browsers/Node.js.

Test codecov

NPM

JavaScript(TypeScript)用の公式MisskeySDKです。ブラウザ/Node.js上で動作します。

以下が提供されています:

  • ユーザー認証
  • APIリクエスト
  • ストリーミング
  • ユーティリティ関数
  • Misskeyの各種モデル(ノート、ユーザー等)の型定義

Install

npm i misskey-js

Usage

Authenticate

todo

API request

import * as Misskey from 'misskey-js';

const cli = new Misskey.api.APIClient({
	origin: 'https://misskey.test',
	credential: 'TOKEN',
});

const meta = await cli.request('meta', { detail: true });

Streaming

import * as Misskey from 'misskey-js';

const stream = new Misskey.Stream('https://misskey.test', { token: 'TOKEN' });
const mainChannel = stream.useChannel('main');
mainChannel.on('notification', notification => {
	console.log('notification received', notification);
});

チャンネルへの接続

チャンネルへの接続はuseChannelメソッドを使用します。

パラメータなし

const stream = new Misskey.Stream('https://misskey.test', { token: 'TOKEN' });

const mainChannel = stream.useChannel('main');

パラメータあり

const stream = new Misskey.Stream('https://misskey.test', { token: 'TOKEN' });

const messagingChannel = stream.useChannel('messaging', {
	otherparty: 'xxxxxxxxxx',
});

チャンネルから切断

disposeメソッドを呼び出します。

const stream = new Misskey.Stream('https://misskey.test', { token: 'TOKEN' });

const mainChannel = stream.useChannel('main');

mainChannel.dispose();

メッセージの受信

チャンネル接続インスタンスはEventEmitterを継承しており、メッセージがサーバーから受信されると受け取ったイベント名でペイロードをemitします。

import * as Misskey from 'misskey-js';

const stream = new Misskey.Stream('https://misskey.test', { token: 'TOKEN' });
const mainChannel = stream.useChannel('main');
mainChannel.on('notification', notification => {
	console.log('notification received', notification);
});

メッセージの送信

チャンネル接続インスタンスのsendメソッドを使用してメッセージをサーバーに送信することができます。

import * as Misskey from 'misskey-js';

const stream = new Misskey.Stream('https://misskey.test', { token: 'TOKEN' });
const messagingChannel = stream.useChannel('messaging', {
	otherparty: 'xxxxxxxxxx',
});

messagingChannel.send('read', {
	id: 'xxxxxxxxxx'
});