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 webhook support to Messages (Fixes #52) #73

Merged
merged 5 commits into from
Jun 5, 2024
Merged

✨ Add webhook support to Messages (Fixes #52) #73

merged 5 commits into from
Jun 5, 2024

Conversation

Log1x
Copy link
Member

@Log1x Log1x commented May 30, 2024

This adds a ->webhook() method that will send messages in a channel through a webhook to allow for further customization such as username & avatar.

It can be used in two ways:

When passing no argument, Laracord will attempt to create a webhook in the destination channel with the same name as the bot. It will then re-use that webhook when sending webhook messages in that channel in the future:

$this
    ->message()
    ->username('Example')
    ->avatar('https://example.com/avatar.png')
    ->content('Hello world!')
    ->webhook()
    ->send($channel);

The second way would be to pass a webhook URL of which already exists for the destination channel:

$this
    ->message()
    ->username('Example')
    ->avatar('https://example.com/avatar.png')
    ->content('Hello world!')
    ->webhook('https://discord.com/api/webhooks/...')
    ->send($channel);

This will attempt to retrieve the Webhook part from DiscordPHP's WebhookRepository using the URL and then send the message using the webhook.

A future improvement might be to allow sending directly to any webhook URL instead of using DiscordPHP (or the bot).

Change log

Enhancements

🧑‍💻 Add a `clearAuthor()` method to clear the default Message embed author/icon
🧑‍💻 Add an `avatar()` method that aliases `avatarUrl()` for improved DX
@Log1x Log1x added the enhancement New feature or request label May 30, 2024
@marky291
Copy link
Contributor

marky291 commented May 30, 2024

Is there a way to retrieve the created webhook ID so that it can be saved and reused from a data storage or will this guarantee to persist its created webhook even if restarted?

@Log1x
Copy link
Member Author

Log1x commented May 30, 2024

at the moment, it names the created webhook the same name as the bot its self to easily identify/re-use it in the future.

@Log1x
Copy link
Member Author

Log1x commented May 30, 2024

could also have it add the bot's user ID or something to ensure the identifier is unique, but it'd get a little awkward if it were to be used without specifying a username (despite Laracord doing that for you by default).

@Log1x Log1x merged commit 160483e into main Jun 5, 2024
1 check passed
@Log1x Log1x deleted the feat/52 branch June 5, 2024 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🧑‍💻 Request for Channel Webhook Integration
2 participants