Social Media Pipeline Example
This example demonstrates how to build a workflow that processes sports events, generates AI commentary, and posts to Mastodon.
Overview
A social media pipeline workflow follows this pattern:
Event (NFL Touchdown) → Prompt (Generate Commentary) → Action (Post to Mastodon)
Use Case
When an NFL touchdown event is received from SportRadar, the workflow:
- Filters for touchdown events
- Generates engaging social media commentary using AI
- Posts the commentary to Mastodon
Step 1: Create the Event Entity
Entity Configuration:
- Name: "NFL Touchdown Event"
- Type: Event
- Condition Mode: Single Path
Condition Configuration:
{
"type": "group",
"operator": "AND",
"conditions": [
{
"type": "rule",
"field": "message.sport",
"comparison": "equals",
"value": "nfl"
},
{
"type": "rule",
"field": "message.eventType",
"comparison": "equals",
"value": "touchdown"
}
]
}
This AND condition ensures only NFL touchdown events trigger the workflow.
Step 2: Create the Prompt Entity
Entity Configuration:
- Name: "Generate Touchdown Commentary"
- Type: Prompt
- Model: GPT-4 or Claude
Prompt Template:
Step 3: Create the Action Entity
Entity Configuration:
- Name: "Post to Mastodon"
- Type: Action
Script (Option 1 - Using helper function):
// Post the latest AI response directly to Mastodon
// Uses environment variables: MASTODON_URL, MASTODON_ACCESS_TOKEN
await postLatestPromptToMastodon();
print('Posted touchdown update to Mastodon');
Script (Option 2 - Manual control with error handling):
// Get the generated commentary
const commentary = await latestPromptResponse();
if (commentary) {
try {
// Post to Mastodon with custom handling
const result = await postToMastodon(
MASTODON_URL,
MASTODON_ACCESS_TOKEN,
commentary
);
print('Posted to Mastodon, status ID:', result.id);
// Store the post ID for potential future reference
output = {
mastodonPostId: result.id,
commentary: commentary,
success: true
};
} catch (error) {
print('Failed to post to Mastodon:', error.message);
output = { success: false, error: error.message };
}
} else {
print('No commentary generated, skipping post');
}
Complete Workflow Data Structure
{
"nodes": {
"n1": {
"entityId": "event-entity-uuid",
"name": "NFL Touchdown Event",
"entityType": "event",
"tfCondition": "Single Path",
"presentation": {
"type": "circle",
"position": { "x": 100, "y": 200 }
}
},
"n2": {
"entityId": "prompt-entity-uuid",
"name": "Generate Touchdown Commentary",
"entityType": "prompt",
"presentation": {
"type": "brain",
"position": { "x": 350, "y": 200 }
}
},
"n3": {
"entityId": "action-entity-uuid",
"name": "Post to Mastodon",
"entityType": "action",
"presentation": {
"type": "star",
"position": { "x": 600, "y": 200 }
}
}
},
"connectors": {
"c1": {
"source": "n1",
"target": "n2",
"sourcePort": "out",
"targetPort": "in"
},
"c2": {
"source": "n2",
"target": "n3",
"sourcePort": "out",
"targetPort": "in"
}
},
"workflow": {
"ref": "n1",
"children": [
{
"ref": "n2",
"children": [
{
"ref": "n3",
"children": []
}
]
}
]
},
"presentation": {
"viewport": { "x": 0, "y": 0, "zoom": 100 }
}
}
Workflow Outcomes
| Outcome | When it occurs |
|---|---|
| Success | All entities execute without errors |
| Error | A script throws an error or times out |
| Ignore | Event condition doesn't match |
Required Environment Variables
Set these in the Admin Console under Settings → Variables:
| Variable | Description | Example |
|---|---|---|
MASTODON_URL | Your Mastodon instance URL | https://mastodon.social |
MASTODON_ACCESS_TOKEN | OAuth access token | your-access-token |
Sample Input Message
{
"sport": "nfl",
"eventType": "touchdown",
"team": "Kansas City Chiefs",
"player": "Patrick Mahomes",
"yards": 15,
"quarter": 3,
"homeTeam": "Chiefs",
"homeScore": 28,
"awayTeam": "Raiders",
"awayScore": 14,
"timestamp": "2025-01-08T15:30:00Z"
}
Extending the Pipeline
Add Error Handling Branch
Use True/False branching on the Event to handle different scenarios:
{
"n1": {
"entityId": "event-uuid",
"name": "NFL Touchdown Event",
"entityType": "event",
"tfCondition": "True/False",
"presentation": { "type": "circle", "position": { "x": 100, "y": 200 } }
},
"n2": {
"name": "true",
"entityType": "logic-branch",
"branchValue": "true",
"presentation": { "type": "logic-branch", "position": { "x": 300, "y": 100 } }
},
"n3": {
"name": "false",
"entityType": "logic-branch",
"branchValue": "false",
"presentation": { "type": "logic-branch", "position": { "x": 300, "y": 300 } }
}
}
Store for Analytics
Add an action to store data for analytics:
// Store touchdown event in S3 for later analysis
await stmStore(
['nfl', 'touchdowns', message.team],
{
player: message.player,
yards: message.yards,
quarter: message.quarter,
timestamp: message.timestamp
},
'touchdown-' + Date.now() + '.json'
);
print('Stored touchdown data for analytics');
Related Topics
- Mastodon Script Functions - Mastodon API functions
- Prompt Script Functions - AI prompt functions
- STM Script Functions - Short-term memory storage
- Conditions - Condition configuration