feat: Add slashcommand api
This commit is contained in:
@@ -45,6 +45,61 @@ export function activate(context) {
|
||||
|
||||
The action appears as a tile in the server side panel's View plugins menu and runs with `source: 'toolbarAction'`.
|
||||
|
||||
## Slash Command Plugin
|
||||
|
||||
`toju-plugin.json`
|
||||
|
||||
```json
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "example.slash-commands",
|
||||
"title": "Slash Commands",
|
||||
"description": "Registers / commands available from the chat composer.",
|
||||
"version": "1.0.0",
|
||||
"kind": "client",
|
||||
"scope": "client",
|
||||
"apiVersion": "1.0.0",
|
||||
"compatibility": {
|
||||
"minimumTojuVersion": "1.0.0",
|
||||
"verifiedTojuVersion": "1.0.0"
|
||||
},
|
||||
"entrypoint": "./main.js",
|
||||
"capabilities": ["messages.send", "ui.commands"]
|
||||
}
|
||||
```
|
||||
|
||||
`main.js`
|
||||
|
||||
```js
|
||||
export function activate(context) {
|
||||
const { api } = context;
|
||||
|
||||
// Global: works in chat servers and direct messages.
|
||||
context.subscriptions.push(
|
||||
api.commands.register('shrug', {
|
||||
name: 'shrug',
|
||||
description: 'Append the shrug emoticon',
|
||||
scope: 'global',
|
||||
run: () => api.messages.send('¯\\_(ツ)_/¯')
|
||||
})
|
||||
);
|
||||
|
||||
// Server-scoped: only offered while a chat server is active.
|
||||
context.subscriptions.push(
|
||||
api.commands.register('announce', {
|
||||
name: 'announce',
|
||||
description: 'Post an announcement to the current channel',
|
||||
icon: '📢',
|
||||
scope: 'server',
|
||||
options: [{ name: 'message', type: 'rest', required: true }],
|
||||
run: (slash) => api.messages.send(`📢 ${slash.args.message}`, slash.textChannel?.id)
|
||||
})
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
Typing `/` in the composer opens the autocomplete menu. `/shrug` runs immediately; `/announce <message>` fills the composer so the user can type the announcement before sending. See the [Slash Commands API](./api/commands.md) for option parsing and the command context.
|
||||
|
||||
## Settings Page Plugin
|
||||
|
||||
```json
|
||||
|
||||
Reference in New Issue
Block a user