在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):gpressutto5/laravel-slack开源软件地址(OpenSource Url):https://github.com/gpressutto5/laravel-slack开源编程语言(OpenSource Language):PHP 100.0%开源软件介绍(OpenSource Introduction):
About Laravel SlackSlack notification for Laravel as it should be. Easy, fast, simple and highly testable. Since it uses On-Demand Notifications, it requires Laravel 5.5 or higher. InstallationRequire this package in your composer.json and update your dependencies: composer require gpressutto5/laravel-slack Since this package supports Laravel's Package Auto-Discovery you don't need to manually register the ServiceProvider. After that, publish the configuration file: php artisan vendor:publish --provider="Pressutto\LaravelSlack\ServiceProvider" You're gonna need to configure an "Incoming Webhook" integration for your Slack team. ConfigurationOn the published configuration file For security reasons you shouldn't commit your Webhook URL,
so this package will, by default, use the environment variable
UsageYou can send simple Slack messages like this:
\Slack::to('#finance')->send('Hey, finance channel! A new order was created just now!');
\Slack::to('@joe')->send("Hey Joe! It looks like you've forgotten your password! Use this token to recover it: as34bhdfh");
\Slack::to(['@zoe', '@amy', '@mia'])->send('I swear, honey, you are the only one... :heart:');
// ↑ look at this array ↑
\Slack::to('#universe', '@god', '#scientists')->send(':thinking_face:');
// ↑ what? I don't need that array? ↑
\Slack::send('Default message to the default channel, set on config/laravel-slack.php.');
class HelloMessage extends SlackMessage
{
public $content = "Hey bob, I'm a sending a custom SlackMessage";
public $channel = '@bob';
}
\Slack::send(new SlackMessage());
class User extends Model
{
public function getSlackChannelAttribute(): string
{
return $this->attributes['my_custom_slack_channel_column'];
}
}
\Slack::to(User::where('verified', true))->send('Sending message to all verified users!');
\Slack::to('#finance')->webhook('https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX')->send('Hey, finance channel! A new order was created just now!'); TestingWhen testing you can easily mock the Slack service by calling
This class also has some helper methods for you to use when testing:
Slack::assertSent(function (SlackMessage $message) {
return $message->content === 'fake';
});
Slack::assertSent(function (SlackMessage $message) {
return strlen($message->content) >= 100;
}, 2);
Slack::assertSent(function (SlackMessage $message) {
return strpos($message->content, 'test') !== false;
}, 5, true);
Slack::assertSentCount(3); Since this package uses |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论