Compare commits
2 commits
557b7653e2
...
9ed20258e0
Author | SHA1 | Date | |
---|---|---|---|
9ed20258e0 | |||
45de3f8be4 |
2 changed files with 57 additions and 1 deletions
52
docs/api.md
Normal file
52
docs/api.md
Normal file
|
@ -0,0 +1,52 @@
|
|||
# API
|
||||
|
||||
There is a web API for getting information about things that are bridged with Out Of Your Element.
|
||||
|
||||
The base URL is the URL of the particular OOYE instance, for example, https://bridge.cadence.moe.
|
||||
|
||||
No authentication is required.
|
||||
|
||||
I'm happy to add more endpoints, just ask for them.
|
||||
|
||||
## Endpoint: GET /api/message
|
||||
|
||||
|Query parameter|Type|Description|
|
||||
|---------------|----|-----------|
|
||||
|`message_id`|regexp `/^[0-9]+$/`|Discord message ID to look up information for|
|
||||
|
||||
Response:
|
||||
|
||||
```typescript
|
||||
{
|
||||
source: "matrix" | "discord" // Which platform the message originated on
|
||||
matrix_author?: { // Only for Matrix messages; should be up-to-date rather than historical data
|
||||
displayname: string, // Matrix user's current display name
|
||||
avatar_url: string, // Absolute HTTP(S) URL to download the Matrix user's current avatar
|
||||
mxid: string // Matrix user ID, can never change
|
||||
},
|
||||
events: [ // Data about each individual event
|
||||
{
|
||||
metadata: { // Data from OOYE's database about how bridging was performed
|
||||
sender: string, // Same as matrix user ID
|
||||
event_id: string, // Unique ID of the event on Matrix, can never change
|
||||
event_type: "m.room.message" | "m.sticker" | string, // Event type
|
||||
event_subtype: "m.text" | "m.image" | "m.audio" | "m.video" | "m.file" | string | null, // For m.room.message events, this is the msgtype property
|
||||
part: 0 | 1, // 0 if this is the first "part" of the message (e.g. this would be the text of a text message with an attachment)
|
||||
reaction_part: 0 | 1, // 0 if this is the last "part" of the message (e.g. this would be the attachment of a text message with an attachment)
|
||||
room_id: string, // Room ID that the event was sent in, linked to the Discord channel
|
||||
source: number
|
||||
},
|
||||
raw: { // Raw historical event data from the Matrix API. Contains at least these properties, but highly depends on what the client sent
|
||||
content: any, // The only non-metadata property, entirely client-generated
|
||||
type: string,
|
||||
room_id: string,
|
||||
sender: string,
|
||||
origin_server_ts: number,
|
||||
unsigned?: any,
|
||||
event_id: string,
|
||||
user_id: string
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
|
@ -4,6 +4,9 @@ const {z} = require("zod")
|
|||
const {defineEventHandler, getValidatedQuery, H3Event} = require("h3")
|
||||
const {as, from, sync, select} = require("../../passthrough")
|
||||
|
||||
/** @type {import("../../m2d/converters/utils")} */
|
||||
const mUtils = sync.require("../../m2d/converters/utils")
|
||||
|
||||
/**
|
||||
* @param {H3Event} event
|
||||
* @returns {import("../../matrix/api")}
|
||||
|
@ -53,7 +56,8 @@ as.router.get("/api/message", defineEventHandler(async event => {
|
|||
}
|
||||
}
|
||||
if (!matrix_author.displayname) matrix_author.displayname = mxid
|
||||
if (!matrix_author.avatar_url) matrix_author.avatar_url = null
|
||||
if (matrix_author.avatar_url) matrix_author.avatar_url = mUtils.getPublicUrlForMxc(matrix_author.avatar_url)
|
||||
else matrix_author.avatar_url = null
|
||||
matrix_author["mxid"] = mxid
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue