2021-05-13 19:54:41 -07:00
|
|
|
# misskey.js
|
2021-05-16 08:07:01 -07:00
|
|
|
**Strongly-typed official Misskey SDK for browsers/Node.js.**
|
|
|
|
|
2021-06-12 06:50:45 -07:00
|
|
|
[![Test](https://github.com/misskey-dev/misskey.js/actions/workflows/test.yml/badge.svg)](https://github.com/misskey-dev/misskey.js/actions/workflows/test.yml)
|
2021-06-24 17:46:40 -07:00
|
|
|
[![codecov](https://codecov.io/gh/misskey-dev/misskey.js/branch/develop/graph/badge.svg?token=PbrTtk3nVD)](https://codecov.io/gh/misskey-dev/misskey.js)
|
2021-06-12 06:50:45 -07:00
|
|
|
|
2021-05-23 01:17:14 -07:00
|
|
|
[![NPM](https://nodei.co/npm/misskey-js.png?downloads=true&downloadRank=true&stars=true)](https://www.npmjs.com/package/misskey-js)
|
|
|
|
|
2021-05-16 08:07:01 -07:00
|
|
|
JavaScript(TypeScript)用の公式MisskeySDKです。ブラウザ/Node.js上で動作します。
|
|
|
|
|
|
|
|
以下が提供されています:
|
|
|
|
- ユーザー認証
|
|
|
|
- APIリクエスト
|
|
|
|
- ストリーミング
|
|
|
|
- ユーティリティ関数
|
2021-07-07 07:23:34 -07:00
|
|
|
- Misskeyの各種型定義
|
2021-05-13 19:54:41 -07:00
|
|
|
|
2021-05-13 20:00:58 -07:00
|
|
|
## Install
|
2021-05-23 01:16:14 -07:00
|
|
|
```
|
|
|
|
npm i misskey-js
|
|
|
|
```
|
2021-05-13 20:00:58 -07:00
|
|
|
|
2021-05-13 19:54:41 -07:00
|
|
|
# Usage
|
2021-05-16 02:30:42 -07:00
|
|
|
## Authenticate
|
|
|
|
todo
|
|
|
|
|
2021-05-13 19:54:41 -07:00
|
|
|
## API request
|
2021-05-16 02:27:21 -07:00
|
|
|
``` ts
|
|
|
|
import * as Misskey from 'misskey-js';
|
|
|
|
|
|
|
|
const cli = new Misskey.api.APIClient({
|
2021-05-22 20:15:28 -07:00
|
|
|
origin: 'https://misskey.test',
|
|
|
|
credential: 'TOKEN',
|
2021-05-16 02:27:21 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
const meta = await cli.request('meta', { detail: true });
|
|
|
|
```
|
2021-05-13 19:54:41 -07:00
|
|
|
|
|
|
|
## Streaming
|
2021-05-16 02:33:08 -07:00
|
|
|
``` ts
|
|
|
|
import * as Misskey from 'misskey-js';
|
|
|
|
|
|
|
|
const stream = new Misskey.Stream('https://misskey.test', { token: 'TOKEN' });
|
2021-05-22 21:34:36 -07:00
|
|
|
const mainChannel = stream.useChannel('main');
|
2021-05-16 02:33:08 -07:00
|
|
|
mainChannel.on('notification', notification => {
|
|
|
|
console.log('notification received', notification);
|
|
|
|
});
|
|
|
|
```
|
2021-05-13 20:00:10 -07:00
|
|
|
|
2021-05-22 21:34:36 -07:00
|
|
|
### チャンネルへの接続
|
|
|
|
チャンネルへの接続は`useChannel`メソッドを使用します。
|
2021-05-16 06:23:23 -07:00
|
|
|
|
2021-05-22 21:34:36 -07:00
|
|
|
パラメータなし
|
2021-05-17 08:07:17 -07:00
|
|
|
``` ts
|
|
|
|
const stream = new Misskey.Stream('https://misskey.test', { token: 'TOKEN' });
|
|
|
|
|
2021-05-22 21:34:36 -07:00
|
|
|
const mainChannel = stream.useChannel('main');
|
2021-05-17 08:07:17 -07:00
|
|
|
```
|
|
|
|
|
2021-05-22 21:34:36 -07:00
|
|
|
パラメータあり
|
2021-05-17 08:07:17 -07:00
|
|
|
``` ts
|
|
|
|
const stream = new Misskey.Stream('https://misskey.test', { token: 'TOKEN' });
|
|
|
|
|
2021-05-22 21:34:36 -07:00
|
|
|
const messagingChannel = stream.useChannel('messaging', {
|
2021-05-17 08:07:17 -07:00
|
|
|
otherparty: 'xxxxxxxxxx',
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
### チャンネルから切断
|
|
|
|
`dispose`メソッドを呼び出します。
|
|
|
|
|
|
|
|
``` ts
|
|
|
|
const stream = new Misskey.Stream('https://misskey.test', { token: 'TOKEN' });
|
|
|
|
|
2021-05-22 21:34:36 -07:00
|
|
|
const mainChannel = stream.useChannel('main');
|
2021-05-17 08:07:17 -07:00
|
|
|
|
|
|
|
mainChannel.dispose();
|
|
|
|
```
|
2021-05-16 06:23:23 -07:00
|
|
|
|
|
|
|
### メッセージの受信
|
|
|
|
チャンネル接続インスタンスはEventEmitterを継承しており、メッセージがサーバーから受信されると受け取ったイベント名でペイロードをemitします。
|
|
|
|
|
2021-05-17 08:07:17 -07:00
|
|
|
``` ts
|
|
|
|
import * as Misskey from 'misskey-js';
|
|
|
|
|
|
|
|
const stream = new Misskey.Stream('https://misskey.test', { token: 'TOKEN' });
|
2021-05-22 21:34:36 -07:00
|
|
|
const mainChannel = stream.useChannel('main');
|
2021-05-17 08:07:17 -07:00
|
|
|
mainChannel.on('notification', notification => {
|
|
|
|
console.log('notification received', notification);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2021-05-16 06:23:23 -07:00
|
|
|
### メッセージの送信
|
|
|
|
チャンネル接続インスタンスの`send`メソッドを使用してメッセージをサーバーに送信することができます。
|
|
|
|
|
2021-05-17 08:07:17 -07:00
|
|
|
``` ts
|
|
|
|
import * as Misskey from 'misskey-js';
|
|
|
|
|
|
|
|
const stream = new Misskey.Stream('https://misskey.test', { token: 'TOKEN' });
|
2021-05-22 21:34:36 -07:00
|
|
|
const messagingChannel = stream.useChannel('messaging', {
|
2021-05-17 08:07:17 -07:00
|
|
|
otherparty: 'xxxxxxxxxx',
|
|
|
|
});
|
|
|
|
|
|
|
|
messagingChannel.send('read', {
|
|
|
|
id: 'xxxxxxxxxx'
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2021-05-13 20:00:58 -07:00
|
|
|
---
|
|
|
|
|
2021-05-13 20:00:10 -07:00
|
|
|
<div align="center">
|
|
|
|
<a href="https://github.com/misskey-dev/misskey/blob/develop/CONTRIBUTING.md"><img src="./i-want-you.png" width="300"></a>
|
|
|
|
</div>
|