Package Exports
- @commandkit/workflow
- @commandkit/workflow/handler
Readme
@commandkit/workflow
CommandKit plugin for useworkflow.dev.
Installation
npm install @commandkit/workflow workflowUsage
import { defineConfig } from 'commandkit/config';
import { workflow } from '@commandkit/workflow';
export default defineConfig({
plugins: [workflow()],
});Then, add workflow functions inside src/workflows directory.
import { sleep } from 'workflow';
import { useClient } from 'commandkit/hooks';
export async function greetUserWorkflow(userId: string) {
'use workflow';
await greetUser(userId);
await sleep('5 seconds');
await greetUser(userId, true);
return { success: true };
}
async function greetUser(userId: string, again = false) {
'use step';
const client = useClient<true>();
const user = await client.users.fetch(userId);
const message = again ? 'Hello again!' : 'Hello!';
await user.send(message);
}Now, you can run the workflow using the start function in your commands (or other places).
import { start } from 'workflow/api';
import {greetUserWorkflow} from '@/workflows/greet';
export const command: CommandData = {
name: 'greet',
description: 'Greet command',
};
export const chatInput: ChatInputCommand = async (ctx) => {
await ctx.interaction.reply("I'm gonna greet you 😉");
await start(greetUserWorkflow, [ctx.interaction.user.id]);
}Using custom Worlds
You can use any world providers from useworkflow.dev/worlds or create your own custom world. Refer to the Building a World documentation for more details.