adachsoft / workflow-step-social
Social media publishing step for AdachSoft workflows.
Requires
- php: ^8.3
- adachsoft/social-post-contracts: ^0.1
- adachsoft/social-post-pinterest: ^0.1
- adachsoft/workflow: ^7.5
- guzzlehttp/guzzle: ^7
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
Reusable adachsoft/workflow steps for publishing and managing image posts through the provider-independent adachsoft/social-post-contracts API. It includes a Pinterest provider and supports additional platforms through the same provider contract.
Requirements and installation
- PHP 8.3 or later
adachsoft/workflow^7.5adachsoft/social-post-contracts^0.1adachsoft/social-post-pinterest^0.1guzzlehttp/guzzle^7
composer require adachsoft/workflow-step-social
Registering providers and steps
Register one SocialPublisherProviderInterface implementation per platform or application-specific provider name. A provider receives validated PublisherSettings and returns a SocialPublisherInterface. SocialPublisherFactory::withDefaultProviders() registers the built-in Pinterest provider; pass additional providers as arguments when needed.
use AdachSoft\Workflow\Builder\WorkflowRunnerBuilder;
use AdachSoft\Workflow\Registry\InMemoryStepRegistry;
use AdachSoft\WorkflowStepSocial\Publisher\SocialPublisherFactory;
use AdachSoft\WorkflowStepSocial\Steps\SocialDeletePostStep;
use AdachSoft\WorkflowStepSocial\Steps\SocialListChannelsStep;
use AdachSoft\WorkflowStepSocial\Steps\SocialPostStep;
// Register the built-in Pinterest provider and any application-specific providers.
$publisherFactory = SocialPublisherFactory::withDefaultProviders($yourPublisherProvider);
$stepRegistry = new InMemoryStepRegistry();
$stepRegistry->registerInstance(SocialPostStep::class, new SocialPostStep($publisherFactory));
$stepRegistry->registerInstance(SocialDeletePostStep::class, new SocialDeletePostStep($publisherFactory));
$stepRegistry->registerInstance(SocialListChannelsStep::class, new SocialListChannelsStep($publisherFactory));
$workflowRunner = WorkflowRunnerBuilder::create()
->withStepRegistry($stepRegistry)
->build();
Each step is a StepInterface implementation with a #[StepType] definition. The registry must receive instances because each step is constructed with the configured publisher factory. Configure workflow step branches in the usual config payload.
Provider settings and secrets
The publisher input is an object. Its required provider string selects the registered provider; every remaining field is passed to that provider as an option through PublisherSettings. Provider names must be unique and stable.
Put credentials in step input, not step configuration. The workflow engine resolves ${secret:NAME} references in mapped input before execution when a SecretResolverInterface is configured. The step receives the resolved value and sanitizes input values from error messages.
Pinterest provider
The built-in pinterest provider uses adachsoft/social-post-pinterest and Guzzle. Its options are:
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
client_id | string | yes | — | Pinterest application client ID. |
client_secret | string | yes | — | Pinterest application client secret; resolve it from a workflow secret. |
token_file | string | yes | — | Path to the JSON token file created by the authorization CLI. |
sandbox | boolean | no | false | Use Pinterest's sandbox API for a Trial app. |
Example publisher input:
{
"publisher": {
"provider": "pinterest",
"client_id": "your-client-id",
"client_secret": "${secret:PINTEREST_CLIENT_SECRET}",
"token_file": "/secure/path/pinterest-tokens.json",
"sandbox": false
}
}
Authorize the Pinterest app once to create the token file before running the workflow:
export PINTEREST_CLIENT_ID='your-client-id'
export PINTEREST_CLIENT_SECRET='your-client-secret'
vendor/bin/social-post-pinterest-authorize --token-file=/secure/path/pinterest-tokens.json
For a Trial app, add --sandbox to the authorization command and set "sandbox": true in the publisher input. Standard-access apps use production (sandbox defaults to false). Keep the token file outside the web root and out of source control. See the adachsoft/social-post-pinterest README for Pinterest app setup, required OAuth scopes, and token-storage details.
The test suite uses a test-only provider named memory backed by InMemorySocialPublisher; it is not a production provider. A custom provider implements SocialPublisherProviderInterface::name() and create(PublisherSettings $settings). Its returned publisher must implement SocialPublisherInterface and advertise the features and post limits it supports. Provider-specific option validation belongs in that provider; use requireString(), optionalString(), optionalInt(), optionalBool(), and optionalStringMap() to read common option types without including option values in validation errors.
Workflow steps
Every step has on_next and on_error branches. Errors are returned as an error string with resolved input values redacted. Configuration values and branch target names are not used as sensitive input values.
social_post
Publishes an image post to a selected channel.
| Input | Type | Required | Description |
|---|---|---|---|
publisher | object | yes | Provider name and provider-specific options. |
channel_id | string | one of channel_id / channel_name | Provider channel identifier. |
channel_name | string | one of channel_id / channel_name | Exact channel name, matched across publisher pages. |
create_channel_if_missing | boolean | no | Defaults to false. With channel_name, create the channel when no exact match exists. Requires channel listing and channel creation support. |
image_url | string | one image source | Public HTTP(S) image URL. |
image_file | string | one image source | Readable local image file. |
image_base64 | string | with content_type | Base64-encoded image bytes. |
content_type | string | with image_base64 | Image MIME type. Supported contract types are JPEG, PNG, WebP, and GIF. |
description | string | yes | Post description. |
title | string | no | Optional post title. |
link | string | no | Optional HTTP(S) destination URL. |
utm | object of strings | no | Query parameters merged into link. Existing parameters are retained unless a supplied key replaces them; fragments are preserved. A non-empty UTM object requires link. |
alt_text | string | no | Optional image alternative text. |
hashtags | list of strings | no | Optional hashtags; each value may include or omit a leading #. |
truncate | boolean | no | Defaults to true. Shortens over-limit title, description, and alt text at a word boundary with …; removes trailing hashtags when the publisher's hashtag limit is exceeded. Set to false to pass text through unchanged and let the publisher reject limit violations. |
Exactly one channel selector and exactly one image source are required. A byte source consists of both image_base64 and content_type; these fields cannot be combined with image_url or image_file. Optional post fields require the corresponding publisher capabilities. The description limit includes the rendered hashtag suffix.
on_next output:
| Field | Type | Description |
|---|---|---|
post_id | string | Provider post identifier. |
post_url | string or null | Public post URL, when the provider returns one. |
channel_id | string | Resolved destination channel identifier. |
platform | string | Platform identifier returned by the publisher. |
published_at | string | Publication timestamp in ISO-8601 format. |
truncated_fields | list of strings | Input field names changed to satisfy publisher limits, such as title, description, alt_text, and hashtags. |
Rate limits use on_error unless a non-empty on_rate_limited target is configured. That branch returns retry_after_seconds as an integer or null when the publisher did not provide a delay.
social_delete_post
Deletes a provider post. The publisher must advertise DELETE_POST.
| Input | Type | Required | Description |
|---|---|---|---|
publisher | object | yes | Provider name and provider-specific options. |
post_id | string | yes | Provider post identifier to delete. |
on_next output is { "deleted": true }. Unsupported deletion, missing posts, and provider errors use on_error.
social_list_channels
Lists one page of channels. The publisher must advertise LIST_CHANNELS.
| Input | Type | Required | Description |
|---|---|---|---|
publisher | object | yes | Provider name and provider-specific options. |
cursor | string | no | Cursor returned by the previous page. |
on_next output contains channels, a list of { id, name, description, privacy } objects, and next_cursor, a string or null when there are no more pages.
Example: publish a blog pin with UTM tracking
The following is the input mapped to a social_post step. The provider name must be registered by the application, and the secret reference is resolved by the workflow engine before the step runs.
{
"publisher": {
"provider": "pinterest",
"client_id": "your-client-id",
"client_secret": "${secret:PINTEREST_CLIENT_SECRET}",
"token_file": "/secure/path/pinterest-tokens.json",
"sandbox": false
},
"channel_name": "Saurix Travel",
"create_channel_if_missing": false,
"image_url": "https://cdn.saurix.io/images/coastal-walk.png",
"title": "A Scenic Coastal Walk",
"description": "Explore a scenic coastal walk and plan your next trip.",
"link": "https://saurix.io/en/guides/coastal-walks?ref=blog",
"utm": {
"utm_source": "pinterest",
"utm_medium": "social",
"utm_campaign": "coastal_walks"
},
"alt_text": "A path beside the coast at sunset",
"hashtags": ["travel", "coastalwalk"],
"truncate": true
}
A corresponding step configuration can route rate limits to a retry or delay step:
use AdachSoft\Workflow\Engine\PayloadVo;
$step = new PayloadVo([
'type' => 'social_post',
'config' => new PayloadVo([
'on_next' => 'record_publication',
'on_error' => 'handle_publication_error',
'on_rate_limited' => 'wait_before_retry',
]),
'input_map' => new PayloadVo([
'publisher' => '$context.publisher',
'channel_name' => '$context.channel_name',
'image_url' => '$context.image_url',
'title' => '$context.title',
'description' => '$context.description',
'link' => '$context.link',
'utm' => '$context.utm',
'alt_text' => '$context.alt_text',
'hashtags' => '$context.hashtags',
]),
]);
Omit on_rate_limited to route rate-limit failures through on_error. If the provider does not return a retry delay, retry_after_seconds is null.