Developers

Sending messages via Slife is easy.

1. Using the Facade:

<?php
use Slife\Support\Facade\Slife;

Slife::send('This is a test message!');
Slife::send('Using a webhook handle', ['default']);



2. Using a custom payload:

<?php
use Concrete\Core\Support\Facade\Application;
use Slife\Payload;

// Get the Application container
$app = Application::getFacadeApplication();

// Get a Slife instance
$slife = $app->make('slife');

// Create a custom Slack message
$payload = $app->make(Payload::class, [
    'channel' => '#random',
    'username' => 'Concrete5',
    'text' => 'Hello?',
]);

// Send the message to Slack
$slife->send($payload);


If you want to build a Slife extension, the following code may help you:

<?php
$em = $this->app->make('Doctrine\ORM\EntityManager');

// Create an event
$event = new\Slife\Entity\Event;
$event->setPackage('slife');
$event->setEvent('on_page_type_publish');

// Save the event
$em->persist($event);
$em->flush();

// Create a placeholder
$placeholder = new\Slife\Entity\Placeholder;
$placeholder->setPlaceholder('name');
$placeholder->setEvent($event);

// Save the placeholder
$em->persist($placeholder);
$em->flush();

// Create message
$message = new\Slife\Entity\Message;
$message->setEvent($event);
$message->setWebhook($webhook);
$message->setMessage('This is a test');

// Save message
$em->persist($message);
$em->flush();


Please send a support ticket if you need further help.