Skip to content

Commit

Permalink
docs: use listAvailablePlugins directly (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
G4Vi authored Aug 14, 2024
1 parent 0c8360b commit a4d88a2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
24 changes: 8 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,28 +162,17 @@ logged in guest account.
const GUEST_KEY = 'acme-corp'
const EXT_NAME = 'SlashCommand'
// create this helper function
async function listAvailableSlashCommands() {
try {
return await xtpClient.listAvailablePlugins(
EXT_NAME,
GUEST_KEY,
)
} catch (e) {
console.error(e)
return []
}
}
// change this implementation to include guest commands
export async function getCommands() {
return Object.keys(BUILTIN_COMMANDS).concat(await listAvailableSlashCommands())
return Object.keys(BUILTIN_COMMANDS).concat(await xtpClient.listAvailablePlugins(
EXT_NAME,
GUEST_KEY,
))
}
```

Next we need to add the ability to execute these custom commands. To do that we must modify `commandHandler`:


```javascript
// add this helper function
async function runSlashCommand(commandName, message) {
Expand Down Expand Up @@ -213,7 +202,10 @@ export async function commandHandler(message) {
botMessage = command(message)
} else { // add this else clause
// if we fail to find the command in the built-ins, let's check xtp
const pluginCommands = await listAvailableSlashCommands()
const pluginCommands = await xtpClient.listAvailablePlugins(
EXT_NAME,
GUEST_KEY,
)
if (pluginCommands.includes(commandName)) {
// running a plugin is no different than calling a normal function
// but it's sandboxed and language independent thanks to Wasm
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"@chatscope/chat-ui-kit-react": "^2.0.3",
"@chatscope/chat-ui-kit-styles": "^1.4.0",
"@dylibso/xtp": "^0.0.0-rc8",
"@dylibso/xtp": "^0.0.0-rc9",
"@fastify/vite": "^6.0.7",
"fastify": "^4.24.3",
"fastify-sse-v2": "^4.0.0",
Expand All @@ -34,4 +34,4 @@
"eslint-plugin-react": "^7.33.2",
"vite": "^5.3.3"
}
}
}

0 comments on commit a4d88a2

Please sign in to comment.