Skip to content

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
@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.

2 participants