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

πŸ§‘β€πŸ’» Request for Channel Webhook Integration #52

Closed
marky291 opened this issue Apr 4, 2024 · 5 comments Β· Fixed by #73
Closed

πŸ§‘β€πŸ’» Request for Channel Webhook Integration #52

marky291 opened this issue Apr 4, 2024 · 5 comments Β· Fixed by #73
Labels
enhancement New feature or request

Comments

@marky291
Copy link
Contributor

marky291 commented Apr 4, 2024

We would like to request the implementation of a webhook integration feature that leverages the existing channel->webhooks() functionality provided by DiscordPHP. This integration is sought to enhance our application's connectivity and streamline our notification processes.

@marky291 marky291 changed the title Request for ChannelWebhook Integration Request for Channel Webhook Integration Apr 4, 2024
@marky291
Copy link
Contributor Author

marky291 commented Apr 4, 2024

Code snippet of how I am using it with DiscordPHP, cannot find a simple solution to this. :(

`if ($messageCache->count()) {

            $messageItem = $messageCache->pop();

            $this->discord()->getChannel($messageItem->getChannelId())->webhooks->freshen()->done(function (WebhookRepository $webhooks) use ($messageItem) {

                $message = MessageBuilder::new()->setUsername($messageItem->getUsername())->setContent($messageItem->getMessage());

                $webhook = $webhooks->find(function (Webhook $webhook) {
                    return $webhook->name === config('services.discord.bot_name');
                });

                // async function.
                if (!$webhook) {
                    $webhooks->save(new Webhook($this->discord(), [
                        'name' => config('services.discord.bot_name'),
                    ]))->then(function (Webhook $webhook) use ($message, $messageItem) {
                        $webhook->execute($message)->done(function (Message $message) use ($messageItem) {
                            Log::info('Message sent: ' . $message->content . ' to channel ' . $messageItem->getChannelId());
                        });
                    });
                }

                // this if a webhook already exists, since not async.
                $webhook->execute($message)->done(function (Message $message) use ($messageItem) {
                    Log::info('Message sent: ' . $message->content . ' to channel ' . $messageItem->getChannelId());
                });
            });`

@marky291 marky291 closed this as completed Apr 4, 2024
@marky291 marky291 reopened this Apr 4, 2024
@Log1x Log1x transferred this issue from laracord/laracord Apr 5, 2024
@Log1x
Copy link
Member

Log1x commented Apr 5, 2024

Hi! I moved this to the framework repo.

Can you give me a better example of how this would be used? I'm struggling to understand the purpose or how I could provide better DX for it.

@marky291
Copy link
Contributor Author

marky291 commented Apr 6, 2024

Hey! Sorry, it looks like it is the only way to dynamically set the bot name when sending messages. This is really useful for when you want the bot to change name (Dynamic AI Characters) or for when you want to create chat between applications by using the logged in users name.

@Log1x Log1x changed the title Request for Channel Webhook Integration πŸ§‘β€πŸ’» Request for Channel Webhook Integration Apr 11, 2024
@Log1x
Copy link
Member

Log1x commented May 30, 2024

Ideally we'd implement something like ->toWebhook($url) in https://github.com/laracord/framework/blob/main/src/Discord/Message.php to start.

I'd like to explore Webhook creation itself at a later date/in a separate issue.

Log1x added a commit that referenced this issue May 30, 2024
πŸ§‘β€πŸ’» Add a `clearAuthor()` method to clear the default Message embed author/icon
πŸ§‘β€πŸ’» Add an `avatar()` method that aliases `avatarUrl()` for improved DX
@Log1x
Copy link
Member

Log1x commented May 30, 2024

#73 proposes a solution to this. I ended up adding the webhook creation as it made sense in this case.

With the PR, your code would be reduced to something like:

if ($messageCache->isEmpty()) {
    return;
}

$messageItem = $messageCache->pop();

$this
    ->message()
    ->username($messageItem->getUsername())
    ->body($messageItem->getMessage())
    ->webhook()
    ->send($messageItem->getChannelId());

@Log1x Log1x added the enhancement New feature or request label May 30, 2024
@Log1x Log1x closed this as completed in #73 Jun 5, 2024
Log1x added a commit that referenced this issue Jun 5, 2024
* πŸ§‘β€πŸ’» Add a `Message::clearAuthor()` method to clear the default Message embed author/icon
* πŸ§‘β€πŸ’» Add a `Message::avatar()` method that aliases `avatarUrl()` for improved DX
* πŸ§‘β€πŸ’» Add `Message::thumbnail()` and `Message::image()` aliases for their URL equivalent
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 a pull request may close this issue.

2 participants