1. Go to this page and download the library: Download conduit-ui/mattermost library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
conduit-ui / mattermost example snippets
return [
'default' => env('MATTERMOST_CONNECTION', 'default'),
'connections' => [
'default' => [
'url' => env('MATTERMOST_URL', 'http://localhost:8065'),
'token' => env('MATTERMOST_BOT_TOKEN'),
'bot_user_id' => env('MATTERMOST_BOT_USER_ID'),
'team' => env('MATTERMOST_TEAM'),
],
],
'bot' => [
// Global middleware applied to every handler. Per-handler
// middleware stacks on top via the #[Middleware(...)] attribute.
'middleware' => [
ConduitUI\Mattermost\Bot\Middleware\IgnoreBots::class,
ConduitUI\Mattermost\Bot\Middleware\Dedup::class,
],
'dedup_ttl' => 60,
'rate_limit_seconds' => 30,
'allowed_channels' => [],
],
];
use ConduitUI\Mattermost\Facades\Mattermost;
// One-liner post
Mattermost::posts()->createPost([
'channel_id' => $channelId,
'message' => 'Hello from Laravel!',
]);
// Or the fluent builder
use ConduitUI\Mattermost\Messages\Message;
Mattermost::posts()->createPost(
Message::make('Deploy started')
->to($channelId)
->thread($rootPostId)
->toArray()
);
use App\Mattermost\HandleNewPost;
use ConduitUI\Mattermost\Bot\Events\PostCreated;
use ConduitUI\Mattermost\Facades\Mattermost;
// Class-based handler
Mattermost::on(PostCreated::class, HandleNewPost::class);
// By Mattermost event name
Mattermost::on('posted', HandleNewPost::class);
// Wildcard — every event
Mattermost::on('*', LogAllEvents::class);
use ConduitUI\Mattermost\Bot\Attributes\Middleware;
use ConduitUI\Mattermost\Bot\Events\PostCreated;
use ConduitUI\Mattermost\Bot\Handler;
use ConduitUI\Mattermost\Bot\Middleware\IgnoreBots;
use ConduitUI\Mattermost\Bot\Middleware\RateLimit;
#[Middleware(IgnoreBots::class, RateLimit::class)]
class HandleMentions extends Handler
{
public function handle(PostCreated $event): void
{
$this->reply($event, 'on it');
$this->react($event, 'eyes');
$this->typing($event);
}
}
use ConduitUI\Mattermost\Bot\Events\Event;
use ConduitUI\Mattermost\Bot\Middleware\Middleware;
class StripPrefix implements Middleware
{
public function handle(Event $event, \Closure $next): mixed
{
if ($event instanceof PostCreated) {
$event->message = ltrim($event->message, '!');
}
return $next($event);
}
}
use ConduitUI\Mattermost\Bot\Attributes\Middleware;
use ConduitUI\Mattermost\Bot\Middleware\Guards\ChannelMember;
use ConduitUI\Mattermost\Bot\Middleware\Guards\RequiresPermission;
use ConduitUI\Mattermost\Bot\Middleware\Guards\RequiresRole;
#[Middleware(RequiresRole::class)]
class DeployHandler extends Handler
{
public static array $roles = ['system_admin'];
public function handle(PostCreated $event): void { /* ... */ }
}
class HandleHeavyJob extends Handler implements \Illuminate\Contracts\Queue\ShouldQueue
{
public function handle(PostCreated $event): void { /* ... */ }
}
use App\Mattermost\DeployHandler;
use ConduitUI\Mattermost\Facades\Mattermost;
use ConduitUI\Mattermost\SlashCommands\SlashCommand;
use ConduitUI\Mattermost\SlashCommands\SlashCommandResponse;
Mattermost::slash('deploy', DeployHandler::class);
Mattermost::slash('status', fn (SlashCommand $cmd) =>
SlashCommandResponse::make()->inChannel('All systems go')
);
class DeployHandler
{
public function __invoke(SlashCommand $cmd): SlashCommandResponse
{
return SlashCommandResponse::make()
->ephemeral("Deploying {$cmd->arg(0)}...");
}
}
use ConduitUI\Mattermost\Facades\Mattermost;
use ConduitUI\Mattermost\Interactive\InteractiveAction;
use ConduitUI\Mattermost\Interactive\InteractiveActionResponse;
Mattermost::interactive('approve', fn (InteractiveAction $a) =>
InteractiveActionResponse::make()->update('Approved!')
);
use ConduitUI\Mattermost\Streaming\MattermostStreamingReply;
$reply = MattermostStreamingReply::create($channelId, rootId: $event->postId);
foreach ($llm->stream($prompt) as $chunk) {
$reply->append($chunk);
}
$reply->finalize();
use ConduitUI\Mattermost\Notifications\MattermostMessage;
class DeployFinished extends Notification
{
public function via(mixed $notifiable): array
{
return ['mattermost'];
}
public function toMattermost(mixed $notifiable): MattermostMessage
{
return MattermostMessage::make("Deploy of `{$this->ref}` finished")
->color('#36a64f')
->field('Duration', '2m31s', short: true);
}
}
// In your PanelProvider
use ConduitUI\Mattermost\Filament\MattermostPlugin;
return $panel->plugin(MattermostPlugin::make());
use ConduitUI\Mattermost\Facades\Mattermost;
beforeEach(fn () => Mattermost::fake());
it('posts an announcement when deploy finishes', function () {
DeployFinished::dispatch($build);
Mattermost::assertPosted(fn ($payload) =>
$payload['channel_id'] === 'town-square'
&& str_contains($payload['message'], 'Deploy of')
);
Mattermost::assertPostCount(1);
});