This module send notification to Microsoft Teams using a webhook.
You can see the request hitting the webhook through the tests. You can clone this repo and change
the config('notifier.hooks.orders.updated')
to test with your hook without running docker.
You can install the package via composer:
composer require peteleco/notifier
You can publish the config file with:
php artisan vendor:publish --tag="notifier-config"
This is the contents of the published config file:
return [
'hooks'=> [
'orders' => [
'updated' => env('NOTIFIER_HOOKS_ORDERS_UPDATED', 'https://webhook.site/bb7586cd-24cb-4336-b648-ceb4fd9c6609'),
'queue' => env('NOTIFIER_HOOKS_ORDERS_queue', 'default'),
]
]
];
$notifier = new Peteleco\Notifier();
echo $notifier->sendMessage('Hello, Peteleco!');
// Or you can send using order message updated object
$message = OrderUpdatedMessage::from([
'uuid' => \Illuminate\Support\Str::uuid(),
'status' => 'my custom status',
'updated_at' => \Carbon\Carbon::yesterday()->setHour(18)->setMinutes(30)->setSecond(0),
]);
$request = app(
Notifier::class,
['webhookUrl' => config('notifier.hooks.orders.updated')]
)->send($message->toMessageCard());
# The toMessageCard method will format in a teams MessageCard
# https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-using?tabs=cURL
protected static function boot(): void
{
parent::boot();
// Dispatch events
static::created(function (Order $order) {
OrderUpdated::dispatch(OrderUpdatedMessage::from([
'uuid' => $order->getAttribute('uuid'),
'status' => $order->load('orderStatus')->orderStatus->getAttribute('title'),
'updated_at' => $order->getAttribute('created_at'),
]));
});
static::updated(function (Order $order) {
if($order->wasChanged('order_status_id')) {
OrderUpdated::dispatch(OrderUpdatedMessage::from([
'uuid' => $order->getAttribute('uuid'),
'status' => $order->load('orderStatus')->orderStatus->getAttribute('title'),
'updated_at' => $order->getAttribute('created_at'),
]));
}
});
}
composer test
# run the command below to init docker
./docker/init.sh -g ${GID} -u ${UID}
# if have problem with permissions
chmod 755 ./docker/init.sh
chmod 755 ./docker/pest.sh
chmod 755 ./docker/interact.sh
./docker/init.sh -g ${GID} -u ${UID}
./pest
./interact
# running commands inside the container
composer test
If you want to debug, change the config mode in the docker/xdebug.ini to develop,debug
;xdebug.mode=coverage
xdebug.mode=develop,debug
Then configure your cli to use your docker machine
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.