Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add persistent interaction routing support to commands (Fixes #79) #80

Merged
merged 3 commits into from
Jun 5, 2024

Conversation

Log1x
Copy link
Member

@Log1x Log1x commented Jun 5, 2024

This PR adds persistent interaction routing allowing for easy persistence and handling of interactions such as button clicks.

It is based on Laravel routing and allows for passing parameters such as {id} and making them optional using a ? like {id?}. All parameters should be passed using : instead of /.

All routes are prefixed with the command name behind the scenes to remain unique.

It is hopefully pretty straight forward to use, see the following example:

/**
 * Handle the command.
 */
public function handle($message, $args)
{
    return $this
        ->message()
        ->title('Hello')
        ->content('Hello world!')
        ->button('👋', route: 'wave')
        ->button('Test', route: 'wave:12345')
        ->send($message);
}

/**
 * The command interaction routes.
 */
public function interactions(): array
{
    return [
        'wave' => fn (Interaction $interaction) => $this->message('👋')->reply($interaction, true),
        'wave:{id?}' => fn (Interaction $interaction, string $id = 'default') => $this->message("Hello from {$id}")->reply($interaction, true),
    ];
}

@Log1x Log1x merged commit 47b83ae into main Jun 5, 2024
1 check passed
@Log1x Log1x deleted the feat/interaction-routing branch June 5, 2024 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant