Search by

adachsoft / workflow-step-social

Arkadiusz Adach

Social media publishing step for AdachSoft workflows.

Package info

gitlab.com/a.adach/workflow-step-social

Issues

pkg:composer/adachsoft/workflow-step-social

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

v0.2.0 2026-11-26 22:34 UTC

This package is auto-updated.

Last update: 2026-11-26 21:34:45 UTC


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.5
  • adachsoft/social-post-contracts ^0.1
  • adachsoft/social-post-pinterest ^0.1
  • guzzlehttp/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:

OptionTypeRequiredDefaultDescription
client_idstringyes—Pinterest application client ID.
client_secretstringyes—Pinterest application client secret; resolve it from a workflow secret.
token_filestringyes—Path to the JSON token file created by the authorization CLI.
sandboxbooleannofalseUse 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.

InputTypeRequiredDescription
publisherobjectyesProvider name and provider-specific options.
channel_idstringone of channel_id / channel_nameProvider channel identifier.
channel_namestringone of channel_id / channel_nameExact channel name, matched across publisher pages.
create_channel_if_missingbooleannoDefaults to false. With channel_name, create the channel when no exact match exists. Requires channel listing and channel creation support.
image_urlstringone image sourcePublic HTTP(S) image URL.
image_filestringone image sourceReadable local image file.
image_base64stringwith content_typeBase64-encoded image bytes.
content_typestringwith image_base64Image MIME type. Supported contract types are JPEG, PNG, WebP, and GIF.
descriptionstringyesPost description.
titlestringnoOptional post title.
linkstringnoOptional HTTP(S) destination URL.
utmobject of stringsnoQuery 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_textstringnoOptional image alternative text.
hashtagslist of stringsnoOptional hashtags; each value may include or omit a leading #.
truncatebooleannoDefaults 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:

FieldTypeDescription
post_idstringProvider post identifier.
post_urlstring or nullPublic post URL, when the provider returns one.
channel_idstringResolved destination channel identifier.
platformstringPlatform identifier returned by the publisher.
published_atstringPublication timestamp in ISO-8601 format.
truncated_fieldslist of stringsInput 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.

InputTypeRequiredDescription
publisherobjectyesProvider name and provider-specific options.
post_idstringyesProvider 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.

InputTypeRequiredDescription
publisherobjectyesProvider name and provider-specific options.
cursorstringnoCursor 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.