PHP code example of mrezdev / laravel-talkto
1. Go to this page and download the library: Download mrezdev/laravel-talkto 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/ */
mrezdev / laravel-talkto example snippets
'outgoing' => [
'inventory-service' => [
'base_url' => env('TALKTO_INVENTORY_URL'),
'receive_endpoint' => '/api/talkto/receive',
'secret' => env('TALKTO_TO_INVENTORY_SECRET'),
'callback_endpoint' => '/api/talkto/callback',
],
],
'incoming' => [
'website-service' => [
'secret' => env('TALKTO_FROM_WEBSITE_SECRET'),
'allowed_commands' => [
'catalog.reserve-stock' => [
'driver' => 'handler',
'handler' => App\Talkto\Handlers\ReserveStockHandler::class,
'idempotency' => '
use Mrezdev\LaravelTalkto\Services\TalktoOutgoingMessageFactory;
$message = app(TalktoOutgoingMessageFactory::class)->create(
target: 'inventory-service',
command: 'catalog.reserve-stock',
payload: ['sku' => 'sku-123', 'quantity' => 2],
options: [
'business_key' => 'cart-123',
'idempotency_key' => 'website-service:catalog.reserve-stock:cart-123:v1',
],
);
use Mrezdev\LaravelTalkto\Contracts\TalktoIncomingCommandHandler;
use Mrezdev\LaravelTalkto\Models\TalktoMessage;
use Mrezdev\LaravelTalkto\Services\TalktoIncomingCommandResult;
final class ReserveStockHandler implements TalktoIncomingCommandHandler
{
public function handle(TalktoMessage $message): TalktoIncomingCommandResult
{
$payload = $message->payload ?? [];
if (! isset($payload['sku'])) {
return TalktoIncomingCommandResult::failedFinal('Missing sku.');
}
return TalktoIncomingCommandResult::succeeded([
'reserved' => true,
'sku' => $payload['sku'],
]);
}
}
use Mrezdev\LaravelTalkto\Services\TalktoIncomingCommandResult;
return TalktoIncomingCommandResult::succeeded(['reserved' => true]);
use Mrezdev\LaravelTalkto\Facades\Talkto;
use Mrezdev\LaravelTalkto\Models\TalktoMessage;
use Mrezdev\LaravelTalkto\Services\TalktoOutgoingMessageFactory;
Talkto::fake();
app(TalktoOutgoingMessageFactory::class)->create(
'inventory', 'stock.reserve', ['sku' => 'ABC', 'quantity' => 2]
);
Talkto::assertSent('inventory', 'stock.reserve');
Talkto::assertSent('inventory', 'stock.reserve', fn (TalktoMessage $message) =>
$message->payload['sku'] === 'ABC' && $message->payload['quantity'] === 2
);
Talkto::assertSentTimes('inventory', 'stock.reserve', 1);
Talkto::assertNotSent('inventory', 'stock.release');
Talkto::fake();
// Perform the application action.
Talkto::assertNothingSent();
bash
php artisan vendor:publish --tag=laravel-talkto-config
php artisan vendor:publish --tag=laravel-talkto-migrations
php artisan migrate
bash
php artisan vendor:publish --tag=talkto-config
php artisan vendor:publish --tag=talkto-migrations
bash
php artisan vendor:publish --tag=talkto-panel-views
bash
php artisan queue:work
bash
php artisan talkto:retry-failed --dry-run
bash
php artisan talkto:dlq-reprocess --dry-run
bash
php artisan talkto:report --hours=24 --direction=all --limit=20
php artisan talkto:trace <message-id>
php artisan talkto:security-audit
php artisan talkto:audit-security
bash
php artisan talkto:doctor
php artisan talkto:doctor --json