Strongly-typed official Misskey SDK for browsers/Node.js.
JavaScript(TypeScript)用の公式MisskeySDKです。ブラウザ/Node.js上で動作します。
以下が提供されています:
- ユーザー認証
- APIリクエスト
- ストリーミング
- ユーティリティ関数
- Misskeyの各種モデル(ノート、ユーザー等)の型定義
npm i misskey-js
todo
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 });
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' });