adachsoft / action-webhook
Webhook action integration for AdachSoft automation applications.
Requires
- php: ^8.3
- adachsoft/action-contracts: ^0.1.4
- adachsoft/webhook-engine: ^0.1.1
- symfony/http-client: ^8.1
- symfony/http-foundation: ^8.1
Requires (Dev)
- adachsoft/php-code-style: ^0.7.4
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^13
- rector/rector: ^2.9
- symplify/phpstan-rules: ^14.19
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
adachsoft/action-webhook adds the framework-independent webhook.call action to applications built on adachsoft/action and adachsoft/automation. It implements the action-contracts provider, semantic validator, and handler interfaces, and sends requests through Symfony HttpClient.
Requirements
- PHP 8.3 or later
adachsoft/action-contractsadachsoft/webhook-engine- Symfony HttpClient and HttpFoundation
Installation
composer require adachsoft/action-webhook
Usage
Registering the action
Create a shared configuration and register the provider, validator, and handler with the host action system:
use AdachSoft\ActionWebhook\ActionWebhookFactory;
use AdachSoft\ActionWebhook\WebhookActionConfigDto;
use AdachSoft\ActionWebhook\Transport\WebhookTargetPolicyDto;
$factory = new ActionWebhookFactory();
$config = new WebhookActionConfigDto(
timeoutSeconds: 10,
signingSecret: null,
userAgent: 'adachsoft-action-webhook',
targetPolicy: new WebhookTargetPolicyDto(),
);
$actionTypeProvider = $factory->createActionType();
$validator = $factory->createValidator($config);
$handler = $factory->createHandler($config);
Register $actionTypeProvider with the action type registry, $validator with semantic validation, and $handler with action execution. The same contracts can be consumed by any action or automation host; this package does not depend on a particular application framework.
Configuration
WebhookActionConfigDto accepts:
timeoutSeconds: request timeout in seconds, from 1 to 60 (default10).signingSecret: optional shared secret. When set, the handler signs the exact request body with HMAC SHA-256 and addsX-Webhook-Signature: sha256=<hex-digest>. The webhook engine requires a secret of at least 16 characters.userAgent: value of theUser-Agentheader (defaultadachsoft-action-webhook).targetPolicy: aWebhookTargetPolicyDtofor private-network access.
Verifying a signature
Verify the signature against the raw request body before decoding or transforming it. The receiver should use the same secret and compare the complete header with a constant-time comparison:
$providedSignature = $request->headers->get('X-Webhook-Signature', '');
$expectedSignature = 'sha256=' . hash_hmac('sha256', $request->getContent(), $signingSecret);
if (!hash_equals($expectedSignature, $providedSignature)) {
throw new \RuntimeException('Invalid webhook signature.');
}
Private-network policy and SSRF protection
Private and local network targets are blocked by default. The factory applies Symfony's NoPrivateNetworkHttpClient to the sender, disables redirects, and limits the response body. This protects against server-side request forgery (SSRF), including host names that resolve to private addresses at send time. The validator deliberately does not resolve DNS; it provides fast feedback for literal private IPs and localhost names, while the sender performs the network check when the request is made.
Use allowedNetworks to permit specific trusted IP addresses or CIDR ranges without opening access to other private targets:
$targetPolicy = new WebhookTargetPolicyDto(
allowedNetworks: ['192.168.2.20/32', '2001:db8:1234::/48'],
);
allowPrivateNetworks: true disables the sender's private-network protection entirely. Enable it only when the host application deliberately trusts all configured webhook destinations. An allow-listed name such as localhost can still be blocked at send time if it resolves to an address outside the configured networks.
Action parameters
The webhook.call action has schema version 1:
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
url | string | Yes | — | HTTP or HTTPS URL with a host. URL credentials are not allowed. |
method | enum | No | POST | One of POST, GET, PUT, PATCH, or DELETE. |
body | JSON | No | Trigger payload | A custom JSON body. An array is JSON-encoded; a string is sent unchanged. An empty or omitted value uses the default payload. GET requests always have an empty body. |
A request with a body includes Content-Type: application/json. All requests include User-Agent and X-Webhook-Run-Id headers. When signing is configured, X-Webhook-Signature is added as well.
Default payload
When body is empty or omitted, non-GET requests send the following JSON shape:
{
"action": "webhook.call",
"trigger": {
"type": "automation.schedule",
"id": "schedule-123",
"occurrenceKey": "2026-06-25T10:00:00+00:00"
},
"runId": "run-456",
"requestedAt": "2026-06-25T10:00:01+00:00",
"actor": {
"type": "user",
"id": "user-789"
}
}
The trigger and actor values come from the action execution context. requestedAt uses the ATOM date-time format. GET requests do not send this payload.
Result and run history
A 2xx response returns SUCCEEDED with a message such as HTTP 204; any other HTTP status returns FAILED with HTTP <status>. Transport failures, including targets blocked by the network policy, return FAILED with the exception message truncated to 500 characters.
The result output contains status_code when an HTTP response exists and always includes duration_ms. The response body is never included in the action output. The handler returns this result to the host action runner; persistence of action run history remains the host system's responsibility.
Symfony services
automation-symfony-bundle autoconfigures services implementing the action-contracts provider, validator, and handler interfaces. Register factory-created services so their target policy and shared configuration are consistent:
# config/services.yaml
services:
AdachSoft\ActionWebhook\ActionWebhookFactory: ~
app.webhook_target_policy:
class: AdachSoft\ActionWebhook\Transport\WebhookTargetPolicyDto
arguments:
$allowedNetworks: ['192.168.2.20/32']
$allowPrivateNetworks: false
app.webhook_action_config:
class: AdachSoft\ActionWebhook\WebhookActionConfigDto
arguments:
$timeoutSeconds: 10
$signingSecret: '%env(WEBHOOK_SIGNING_SECRET)%'
$userAgent: 'adachsoft-action-webhook'
$targetPolicy: '@app.webhook_target_policy'
app.webhook_call_action_type:
class: AdachSoft\ActionWebhook\WebhookCallActionType
factory: ['@AdachSoft\ActionWebhook\ActionWebhookFactory', 'createActionType']
app.webhook_call_action_validator:
class: AdachSoft\ActionWebhook\WebhookCallActionValidator
factory: ['@AdachSoft\ActionWebhook\ActionWebhookFactory', 'createValidator']
arguments: ['@app.webhook_action_config']
app.webhook_call_action_handler:
class: AdachSoft\ActionWebhook\WebhookCallActionHandler
factory: ['@AdachSoft\ActionWebhook\ActionWebhookFactory', 'createHandler']
arguments: ['@app.webhook_action_config']
Configure WEBHOOK_SIGNING_SECRET in the application's secret store. Omit the signing secret or configure it as null to send unsigned requests. The bundle's autoconfiguration discovers the returned services by their implemented interfaces.