Implementing Automatic Posting of New Products to Social Media
When manager publishes product in catalog, system automatically distributes announcement to required channels: VKontakte, Telegram channel, Facebook Page, Odnoklassniki. Without manual copying, without delays, with correct formatting for each platform.
Architecture
Core — event-driven pipeline. Product publication generates ProductPublished event, which is picked up by separate listeners for each social network. Each listener queues task, worker processes independently.
ProductPublished event
├── VkPostListener → queue: vk-posts
├── TelegramPostListener → queue: telegram-posts
├── FacebookPostListener → queue: facebook-posts
└── OdnoklassnikiPostListener → queue: ok-posts
Such scheme guarantees that failure in one network doesn't block posting to others.
VKontakte
Uses VK API v5.199. For publishing from community need community token with wall right. Photo upload — two-step: first get upload URL, then upload file and save.
// Step 1: get upload server
$uploadServer = $vk->photos->getWallUploadServer(['group_id' => $groupId]);
// Step 2: upload image
$uploaded = Http::attach('photo', file_get_contents($imageUrl), 'photo.jpg')
->post($uploadServer['upload_url']);
// Step 3: save photo
$saved = $vk->photos->saveWallPhoto([
'group_id' => $groupId,
'photo' => $uploaded['photo'],
'server' => $uploaded['server'],
'hash' => $uploaded['hash'],
]);
// Step 4: publish post
$vk->wall->post([
'owner_id' => -$groupId,
'message' => $caption,
'attachments' => "photo{$saved[0]['owner_id']}_{$saved[0]['id']}",
]);
Telegram
Telegram Bot API — simplest for integration. Method sendPhoto or sendMediaGroup for multiple photos. Caption supports HTML and MarkdownV2.
import httpx
async def post_to_telegram(bot_token: str, channel_id: str, photo_url: str, caption: str):
async with httpx.AsyncClient() as client:
resp = await client.post(
f"https://api.telegram.org/bot{bot_token}/sendPhoto",
json={
"chat_id": channel_id,
"photo": photo_url,
"caption": caption,
"parse_mode": "HTML",
},
timeout=15,
)
resp.raise_for_status()
return resp.json()
Caption limit — 1024 characters. If description longer, sent as additional message via sendMessage with reply_to_message_id.
Facebook Page
Graph API v19.0, method /{page-id}/photos. Requires Page Access Token with pages_manage_posts right.
POST /v19.0/{page-id}/photos
?url=https://cdn.example.com/img.jpg
&message=New product in catalog...
&published=true
Text Templates
Different platforms require different formatting. Templates stored in database and editable via CMS:
| Platform | Features |
|---|---|
| VKontakte | Up to 16k characters, emoji, clickable links |
| Telegram | HTML tags <b>, <i>, <a>, limit 1024 |
| Links in text — preview generated automatically |
Template variables: {name}, {price}, {url}, {description}, {tags}.
Retry Logic and Monitoring
Each queue task has 3 attempts with exponential backoff (1 min → 5 min → 15 min). After exhausting attempts — entry in failed_social_posts table with error body and admin notification. Post metrics (success/fail per platform) displayed in dashboard.
Implementation Timeline
Integration of two platforms (VK + Telegram) — 4–6 business days. Each additional platform — 1–2 days. Admin panel with post history and templates — additional 2–3 days.







