API クライアント
Client は RPC メソッドを提供する gRPC API クライアントです。
セットアップ
Section titled “セットアップ”// ESMimport { OAuth2Authenticator, Client, MediaUploadType, LanguageCode } from 'mixi2-js';// CJSconst { OAuth2Authenticator, Client, MediaUploadType, LanguageCode } = require('mixi2-js');import { OAuth2Authenticator, Client, MediaUploadType, LanguageCode } from '@otoneko1102/mixi2-js';const authenticator = new OAuth2Authenticator({ clientId: process.env.CLIENT_ID!, clientSecret: process.env.CLIENT_SECRET!, tokenUrl: process.env.TOKEN_URL!,});
const client = new Client({ apiAddress: process.env.API_ADDRESS!, authenticator,});| プロパティ | 型 | 必須 | 説明 |
|---|---|---|---|
apiAddress |
string |
○ | API サーバーアドレス |
authenticator |
Authenticator |
○ | 認証インスタンス |
authKey |
string |
- | x-auth-key メタデータに付与する認証キー |
RPC メソッド一覧
Section titled “RPC メソッド一覧”Bot・Plugin 共通
Section titled “Bot・Plugin 共通”| メソッド | 引数 | 戻り値 | 説明 |
|---|---|---|---|
getUsers(userIdList) |
string[] |
Promise<User[]> |
ユーザー情報を一括取得 |
getPosts(postIdList) |
string[] |
Promise<Post[]> |
ポスト情報を一括取得 |
createPost(request) |
CreatePostRequest |
Promise<Post> |
ポストを作成(返信/引用/コミュニティ/メディア添付対応) |
deletePost(postId) |
string |
Promise<boolean> |
ポストを削除 |
initiatePostMediaUpload(request) |
InitiatePostMediaUploadRequest |
Promise<InitiatePostMediaUploadResponse> |
メディアアップロードを開始 |
getPostMediaStatus(mediaId) |
string |
Promise<GetPostMediaStatusResponse> |
メディアの処理状況を取得 |
sendChatMessage(request) |
SendChatMessageRequest |
Promise<ChatMessage> |
チャットメッセージを送信 |
getStamps(request?) |
GetStampsRequest? |
Promise<GetStampsResponse> |
スタンプ一覧を取得 |
addStampToPost(postId, stampId) |
string, string |
Promise<Post> |
ポストにスタンプを付与 |
getAccessToken() |
- | Promise<string> |
認証インスタンスからアクセストークンを取得 |
close() |
- | void |
gRPC 接続を閉じる |
Plugin 専用
Section titled “Plugin 専用”| メソッド | 引数 | 戻り値 | 説明 |
|---|---|---|---|
getCommunities(communityIdList) |
string[] |
Promise<Community[]> |
コミュニティ情報を一括取得 |
getCommunityTimeline(request) |
GetCommunityTimelineRequest |
Promise<Post[]> |
コミュニティのタイムラインを取得 |
getCommunityMemberList(request) |
GetCommunityMemberListRequest |
Promise<GetCommunityMemberListResponse> |
コミュニティのメンバー一覧を取得 |
restrictCommunityPost(request) |
RestrictCommunityPostRequest |
Promise<void> |
コミュニティのポストを非表示にする |
getCommunitiesUsingApplication(request?) |
GetCommunitiesUsingApplicationRequest? |
Promise<GetCommunitiesUsingApplicationResponse> |
Plugin がインストールされているコミュニティ一覧を取得 |
sendDirectMessageToCommunityMember(request) |
SendDirectMessageToCommunityMemberRequest |
Promise<ChatMessage> |
コミュニティメンバーに DM を送信 |
ユーザー情報取得
Section titled “ユーザー情報取得”const users = await client.getUsers(["user-id-1", "user-id-2"]);const post = await client.createPost({ text: "Hello mixi2!" });CreatePostRequest
Section titled “CreatePostRequest”| フィールド | 型 | 必須 | 説明 |
|---|---|---|---|
text |
string |
○ | ポスト本文(最大 149 文字) |
inReplyToPostId |
string |
- | 返信先ポスト ID |
quotedPostId |
string |
- | 引用対象ポスト ID |
communityId |
string |
- | 投稿先コミュニティ ID(Plugin のみ) |
mediaIdList |
string[] |
- | 添付メディア ID(最大 4 件) |
postMask |
PostMask |
- | マスク設定(センシティブ/ネタバレ) |
publishingType |
PostPublishingType |
- | 配信設定 |
const deleted = await client.deletePost("post-id");// deleted === true なら削除成功メディアアップロード → ポスト添付
Section titled “メディアアップロード → ポスト添付”const upload = await client.initiatePostMediaUpload({ contentType: "image/png", dataSize: 1024, mediaType: MediaUploadType.IMAGE,});// upload.uploadUrl に POST でメディアデータを送信const status = await client.getPostMediaStatus(upload.mediaId);// status.status === MediaUploadStatus.COMPLETED になったら添付可能await client.createPost({ text: "画像付き!", mediaIdList: [upload.mediaId] });InitiatePostMediaUploadRequest
Section titled “InitiatePostMediaUploadRequest”| フィールド | 型 | 必須 | 説明 |
|---|---|---|---|
contentType |
string |
○ | Content-Type(例: image/jpeg) |
dataSize |
number |
○ | データサイズ(バイト) |
mediaType |
MediaUploadType |
○ | メディア種別(IMAGE / VIDEO) |
description |
string |
- | メディアの説明 |
チャットメッセージ送信
Section titled “チャットメッセージ送信”const message = await client.sendChatMessage({ roomId: "room-id", text: "Hello!",});SendChatMessageRequest
Section titled “SendChatMessageRequest”| フィールド | 型 | 必須 | 説明 |
|---|---|---|---|
roomId |
string |
○ | 送信先ルーム ID |
text |
string |
△ | テキスト(text または mediaId のいずれか必須) |
mediaId |
string |
△ | 添付メディア ID |
// 公式スタンプ一覧取得const result = await client.getStamps({ officialStampLanguage: LanguageCode.JP });const officialSets = result.officialStampSets;
// コミュニティスタンプ取得(Plugin のみ)const result2 = await client.getStamps({ communityIds: ["community-id"] });const communityStamps = result2.communityStampSets;
// ポストにスタンプを付与await client.addStampToPost("post-id", "stamp-id");GetStampsRequest
Section titled “GetStampsRequest”| フィールド | 型 | 必須 | 説明 |
|---|---|---|---|
officialStampLanguage |
LanguageCode |
- | 公式スタンプの言語(未指定の場合は空のリストが返る) |
communityIds |
string[] |
- | コミュニティスタンプを取得するコミュニティ ID(Plugin のみ) |
GetStampsResponse
Section titled “GetStampsResponse”| フィールド | 型 | 説明 |
|---|---|---|
officialStampSets |
OfficialStampSet[] |
公式スタンプセットの一覧 |
communityStampSets |
CommunityStampSet[] |
コミュニティスタンプセットの一覧 |
client.close();各 RPC メソッドの詳細は 公式 API 仕様 を参照してください。