laravel-notification-channels / discord Goto Github PK
View Code? Open in Web Editor NEWDiscord notification channel for Laravel
Home Page: http://laravel-notification-channels.com
License: MIT License
Discord notification channel for Laravel
Home Page: http://laravel-notification-channels.com
License: MIT License
Hi,
I need some help. I did not find example in readme file.
I would like to send embed message which includes images. please, could anybody post correct syntax of adding image to message.
Thank you!
At current state of the documentation, it appears that one model is tied to one specific channel.
Is there a possible workaround to allow a model to dispatch to two different channels?
Hi, when can we expect support for Laravel 6?
I guess this will work #28
I tried updating to Laravel 9 but having conflicts with
illuminate/queue and laravel/framework packages.
Only one of these can be installed: illuminate/queue[v5.8.0, ..., 5.8.x-dev, v6.0.0, ..., 6.x-dev, v7.0.0, ..., 7.x-dev, v8.0.0, ..., 8.x-dev, v9.0.0-beta.1, ..., 9.x-dev], laravel/framework[v9.0.0-beta.1, ..., 9.x-dev]. laravel/framework replaces illuminate/queue and thus cannot coexist with it.
I followed the installation procedure but with my first try sending a notification i get the following error:
InvalidArgumentException in Manager.php line 90: Driver [App\Notifications\DiscordChannel] not supported.
I want to send notification to discord channel from laravel project:
use Notifiable
to my model
public function routeNotificationForDiscord() { return '123123123123123123123'; //real channel id }
as well
'discord' => [ 'token' => env('DISCORD_BOT_TOKEN'), ],
to services.php and added DISCORD_BOT_TOKEN=gjadkgja1361.djga163.kjg13613djg to my .env fileAnd when i try to do Favorite::find(1)->notify(new AddedToFavoritesDiscordMessage());
i receive Discord responded with an HTTP error: 403: Missing Access
/vendor/laravel-notification-channels/discord/src/Discord.php", line: 93, function: "serviceRespondedWithAnHttpError", โฆ }
here is my problem:
$ php artisan discord:setup
You must paste your Discord token (App Bot User token) into your services.php
config file.
View the README for more info: https://github.com/laravel-notification-channels/discord#installation
but in my config/services.php i have
'discord' => [
'token' => env('DISCORD_BOT_TOKEN')
],
and in my .env file a have a DISCORD_BOT_TOKEN value
Hi, all,
First of all great package, thank you!
I'm trying to channel all notifications in my application to our staff discord's channel. Sometimes we send many notifications at once to various text channels we end up being rate limited.
I saw a pull request that returns the underlying GuzzleHttp exception inCouldNotSendNotification
. Our notifications are queued and sent "asynchronously", so I was thinking of releasing the job again after the seconds spcified in the response by Discord.
This is my code in theory, because I don't know how to test it without making real requests to Discord (test it in ci/cd pipelines):
public function failed(Exception $exception)
{
if ($exception instanceof CouldNotSendNotification) {
if ($exception->getCode() === 429) {
$json = json_decode($exception->getPrevious()->getResponse());
$this->release($json->retry_after);
}
}
}
Could you please advise on how to proceed?
Thank you,
Ivanka
Add support for laravel 11
I just rolled out a new Laravel app and wanted to add discord notifications support, went to install the package and simply running composer require laravel-notification-channels/discord
results in the package failing to install due to the illuminate/queue requirements.
As 5.8 support was recently added in 397a25b could you publish a new release to support this officially?
In the meanwhile as a workaround for anyone else experiencing this, you can use composer require laravel-notification-channels/discord:dev-master
to install it.
title is self-explanatory but i'm gonna ask it again. can i use this package with discord webhooks? (seems like i can't) i want to able it for my users to write down a discord url and receive messages.
This is a silly thing, but the description in github says Discord notification channel for Laravel 5.3
while the readme says Discord notification channel for Laravel 5.6
.
This may be turning away people who don't scroll down and confuse people who don't read the readme closely.
Not works
Attempting to identify the bot with Discord's websocket gateway...
Connecting to 'wss://gateway.discord.gg'...
Discord responded with an error while trying to identify the bot: {"t":null,"s":null,"op":10,"d":{"heartbeat_interval":41250,"_trace":["gateway-prd-main-3q62"]}}
NotificationChannels\Discord\Exceptions\CouldNotSendNotification with message 'Discord responded with an HTTP error: 400'
Hi
i am trying your package and i cant proceed in setting up the discord bot cause i keep receiving this error in my php artisan...
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'NotificationChannels\Discord\DiscordServiceProvider' not found
i have put this in app.php
NotificationChannels\Discord\DiscordServiceProvider::class
thanks in advance :D
we need a support for laravel 11 ASAP
I've spent a while trying to get this installed, have not been able to find any problems related to this, and have reviewed my server configuration and reviewed PHP versions(PHP 7.0.20)
My Laravel Version is 5.4.33.
[root] # php artisan --version Laravel Framework 5.4.33 [root] #
The Composer Error Output
Using version ^1.0 for laravel-notification-channels/discord
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for laravel-notification-channels/discord ^1.0 -> satisfiable by laravel-notification-channels/discord[v1.0.0].
- Conclusion: remove laravel/framework v5.4.33
- Conclusion: don't install laravel/framework v5.4.33
- laravel-notification-channels/discord v1.0.0 requires illuminate/queue 5.1.*|5.2.*|5.3.* -> satisfiable by illuminate/queue[v5.1.1, v5.1.13, v5.1.16, v5.1.2, v5.1.20, v5.1.22, v5.1.25, v5.1.28, v5.1.30, v5.1.31, v5.1.41, v5.1.6, v5.1.8, v5.2.0, v5.2.19, v5.2.21, v5.2.24, v5.2.25, v5.2.26, v5.2.27, v5.2.28, v5.2.31, v5.2.32, v5.2.37, v5.2.43, v5.2.45, v5.2.6, v5.2.7, v5.3.0, v5.3.16, v5.3.23, v5.3.4].
- don't install illuminate/queue v5.1.1|don't install laravel/framework v5.4.33
- don't install illuminate/queue v5.1.13|don't install laravel/framework v5.4.33
- don't install illuminate/queue v5.1.16|don't install laravel/framework v5.4.33
- don't install illuminate/queue v5.1.2|don't install laravel/framework v5.4.33
- don't install illuminate/queue v5.1.20|don't install laravel/framework v5.4.33
- don't install illuminate/queue v5.1.22|don't install laravel/framework v5.4.33
- don't install illuminate/queue v5.1.25|don't install laravel/framework v5.4.33
- don't install illuminate/queue v5.1.28|don't install laravel/framework v5.4.33
- don't install illuminate/queue v5.1.30|don't install laravel/framework v5.4.33
- don't install illuminate/queue v5.1.31|don't install laravel/framework v5.4.33
- don't install illuminate/queue v5.1.41|don't install laravel/framework v5.4.33
- don't install illuminate/queue v5.1.6|don't install laravel/framework v5.4.33
- don't install illuminate/queue v5.1.8|don't install laravel/framework v5.4.33
- don't install illuminate/queue v5.2.0|don't install laravel/framework v5.4.33
- don't install illuminate/queue v5.2.19|don't install laravel/framework v5.4.33
- don't install illuminate/queue v5.2.21|don't install laravel/framework v5.4.33
- don't install illuminate/queue v5.2.24|don't install laravel/framework v5.4.33
- don't install illuminate/queue v5.2.25|don't install laravel/framework v5.4.33
- don't install illuminate/queue v5.2.26|don't install laravel/framework v5.4.33
- don't install illuminate/queue v5.2.27|don't install laravel/framework v5.4.33
- don't install illuminate/queue v5.2.28|don't install laravel/framework v5.4.33
- don't install illuminate/queue v5.2.31|don't install laravel/framework v5.4.33
- don't install illuminate/queue v5.2.32|don't install laravel/framework v5.4.33
- don't install illuminate/queue v5.2.37|don't install laravel/framework v5.4.33
- don't install illuminate/queue v5.2.43|don't install laravel/framework v5.4.33
- don't install illuminate/queue v5.2.45|don't install laravel/framework v5.4.33
- don't install illuminate/queue v5.2.6|don't install laravel/framework v5.4.33
- don't install illuminate/queue v5.2.7|don't install laravel/framework v5.4.33
- don't install illuminate/queue v5.3.0|don't install laravel/framework v5.4.33
- don't install illuminate/queue v5.3.16|don't install laravel/framework v5.4.33
- don't install illuminate/queue v5.3.23|don't install laravel/framework v5.4.33
- don't install illuminate/queue v5.3.4|don't install laravel/framework v5.4.33
- Installation request for laravel/framework (locked at v5.4.33, required as 5.4.*) -> satisfiable by laravel/framework[v5.4.33].
Installation failed, reverting ./composer.json to its original content.
Thanks, sorry if this is something obvious.
As of this morning our site is only getting 400 responses to posting to discord
We done actually use embeds, all are notifications are just markdown.
I wanted to test the bot using your code. In your example you simply have $ composer test. I have no clue how to start this although I got it unto my discord server it doesn't stay.
The Discord Bot always online, but still can send the notification. Any idea how to make the bot online?
The Usage of the package in the read is missing many of the basic. A simple way of just sending a notification to a channel will go a long way if you add it. Thank you
Package doesn't support PHP 8.0
Does anybody have an updated version of this that supports embed objects as seen in the docs here: https://discordapp.com/developers/docs/resources/channel#embed-object
Supports message formats that look like so: https://i.gyazo.com/6033ee0a7432f806218931babb418f1b.png
If not I will create a pull request.
Discord sends back data in the response body when there is a rate limit error.
See: https://discord.com/developers/docs/topics/rate-limits
They say that you should not hard code the retry timeout:
Because we may change rate limits at any time and rate limits can be different per application, rate limits should not be hard coded into your bot/application. In order to properly support our dynamic rate limits, your bot/application should parse for our rate limits in response headers and locally prevent exceeding the limits as they change.
Right now the RequestException
is caught and a CouldNotSendNotification
exception is thrown. The latter only includes the message
keyword from the response sent by Discord API. The other keywords like retry_after
and global
are being discarded.
One fix for this could be to include the original RequestException
exception as the previous exception to the thrown CouldNotSendNotification
. Exceptions have 3 constructor arguments, the message, code and previous exception. Only the message part is currently used. Setting the previous exception should make it possible for the Laravel app to get the body of the original Discord response from the original exception and parse out the retry_after
or other data.
Ping me when you're done with the code, tests and readme. I'll do a little code review and publish your package on Packagist.
I've seen a few webhook questions on here before, but I'm sure the assumption here is a one app, one system approach. What I have is a notifications systems, whereby every customer on my platform needs to integrate Discord, so, the webhook will be different per user, and they'll set it on their profile.
How can I send a notification then to their webhook's url channel?
This is my current routing on my User
model to obtain their webhook:
/**
* Route notifications for the Discord channel.
*/
public function routeNotificationForDiscord($notification)
{
try {
$availableIntegration = AvailableIntegration::where('slug', 'discord')
->first();
$userIntegration = UserIntegration::where('user_id', $this->id)
->where('available_integration_id', $availableIntegration->id)
->first();
if (!$userIntegration) {
return null;
}
return $userIntegration->schema->discord_webhook;
} catch (\Exception $e) { }
return null;
}
I'm having some issues getting this package to be supported in my project. I'm working inside a Laravel 8 application and am using PHP 7.4, I'm using version 1.3.0 of this package and have just set it up, my notification class (the important bits) looks like this...
<?php
namespace App\Notifications\Monitor;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\SlackMessage;
use Illuminate\Notifications\Messages\NexmoMessage;
use NotificationChannels\Discord\DiscordChannel;
use NotificationChannels\Discord\DiscordMessage;
use NotificationChannels\Twitter\TwitterChannel;
use NotificationChannels\Twitter\TwitterDirectMessage;
use App\Models\NotificationHistory;
use App\Traits\Plans;
class MonitorDown extends Notification implements ShouldQueue
{
use Queueable, Plans;
public $monitor;
public $emailData;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($monitor, $emailData)
{
$this->monitor = $monitor;
$this->emailData = $emailData;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
$preferences = json_decode($notifiable->notification_preferences);
if (!$notifiable->is_subscribed) {
$preferences->monitors->down = array_merge(array_diff($preferences->monitors->down, [
'nexmo', 'discord', 'twitter'
]));
}
// not working
return ['twitter', 'discord'];
// not working
return [DiscordChannel::class, 'discord'];
// not working
return [DiscordChannel::class];
// return $preferences->monitors->down;
}
/**
* Determine which queues should be used for each notification channel.
*
* @return array
*/
public function viaQueues()
{
return [
'mail' => 'notifications',
'database' => 'notifications',
'slack' => 'notifications',
'nexmo' => 'notifications',
'discord' => 'notifications',
'twitter' => 'notifications'
];
}
/**
* Get the Discord representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toDiscord($notifiable)
{
$data = [
'type' => 'monitor-down',
'name' => $this->emailData['monitor_name'],
'url' => $this->emailData['monitor_url'],
'value' => 'down'
];
try {
$this->createHistoryEntry('discord', 'Monitor Down', $data, $notifiable);
} catch (\Exception $e) { }
$monitorName = $this->emailData['monitor_name'];
$monitorURL = $this->emailData['monitor_url'];
return DiscordMessage::create("Your monitor $monitorName -- ($monitorURL) -- has just gone DOWN");
}
/**
* Create a history entry
*
* @param mixed $notifiable
* @return array
*/
public function createHistoryEntry($method = 'database', $type = '', $data, $notifiable)
{
try {
$history = new NotificationHistory();
$history->method = $method;
$history->type = $type;
$history->data = json_encode($data);
$history->notification_id = isset($this->id) ? $this->id : '';
$history->user_id = $notifiable['id'];
$history->save();
} catch (\Exception $e) { }
}
}
You'll see that I've tried several ways to get the notifications to work:
// not working
return ['twitter', 'discord'];
// not working
return [DiscordChannel::class, 'discord'];
// not working
return [DiscordChannel::class];
But still, the error returned is:
InvalidArgumentException: Driver [discord] not supported.
I add step by step notification and after enter to page (page test notification) i see that error. Command in CLI i run
php artisan discord:setup
Is the bot already added to your server? (yes/no) [no]:
>
What is your Discord app client ID?:
> *********************
Add the bot to your server by visiting this link: https://discord.com/oauth2/authorize?&client_id=******************&scope=bot&permissions=0
Continue? (yes/no) [yes]:
> yes
Attempting to identify the bot with Discord's websocket gateway...
Connecting to 'wss://gateway.discord.gg'...
Your bot has been identified by Discord and can now send API requests!
Crush on line
app(Discord::class)->getPrivateChannel($discordId); //$discordId = discord_user_id
Laravel 8 has been released today and we need to update this repo to support it.
See https://laravel.com/docs/8.x/upgrade & laravel-notification-channels/channels#107
When i deployed on hosting i got an error
On PC all works
NotificationChannels \ Discord \ Exceptions \ CouldNotSendNotification
Discord responded with an HTTP error: 401: 401: Unauthorized
I tried running php artisan discord:setup
and got this output:
Is the bot already added to your server? (yes/no) [no]:
>
What is your Discord app client ID?:
> <client_id>
Add the bot to your server by visiting this link: https://discordapp.com/oauth2/authorize?&client_id=<client_id>&scope=bot&permissions=0
Continue? (yes/no) [yes]:
>
Attempting to identify the bot with Discord's websocket gateway...
Could not get a websocket gateway address, defaulting to 'wss://gateway.discord.gg'.
Connecting to 'wss://gateway.discord.gg'...
WebSocket\ConnectionException : Could not open socket to "gateway.discord.gg:443": (0).
at S:\repos\totoro\vendor\textalk\websocket\lib\Client.php:60
56| // Open the socket. @ is there to supress warning that we will catch in check below instead.
57| $this->socket = @fsockopen($host_uri, $port, $errno, $errstr, $this->options['timeout']);
58|
59| if ($this->socket === false) {
> 60| throw new ConnectionException(
61| "Could not open socket to \"$host:$port\": $errstr ($errno)."
62| );
63| }
64|
Exception trace:
1 WebSocket\Client::connect()
S:\repos\totoro\vendor\textalk\websocket\lib\Base.php:30
2 WebSocket\Base::send("{"op":2,"d":{"token":"<bot api token>","v":3,"compress":false,"properties":{"$os":"WINNT","$browser":"laravel-notification-channels-discord","$device":"laravel-notification-channels-discord","$
referrer":"","$referring_domain":""}}}")
S:\repos\totoro\vendor\laravel-notification-channels\discord\src\Commands\SetupCommand.php:96
Please use the argument -v to see more details.
Could this happen because the gateway version is too old? I had a quick look at the discord dev portal and saw the latest version is 6, not 3 as used in the request.
Code: https://ptero.co/wexewiwuqo.xml
Ran by: https://ptero.co/uzikulasak.php
Output data in horizon: https://ptero.co/aqupemahim.makefile
Stacktrace: https://ptero.co/azahiqozux.shell
Hi, when will you release support for laravel 5.6?
I'm getting the following message,
Line 24 in [...]/vendor/laravel-notification-channels/discord/src/Exceptions/CouldNotSendNotification.php- Discord responded with an HTTP error: 403: Cannot send messages to this user
But I am unable to figure out how to catch this exception and handle it accordingly. The issue here is that the Discord bot no longer has any channels in common with that particular user, so its unable to send that PM - which makes sense.
How can I catch these exceptions from inside the Notification itself? It's sent to a few different users, not individually, so catching the Notification::send()
method is not an option.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.