Developing a Telegram Bot for Supplier Price Change Notifications
The bot monitors supplier prices (via API, scraping, or price list uploads) and immediately notifies those responsible of changes requiring action: price increase, deficit items appearing, condition changes.
Monitoring Logic
class SupplierPriceMonitor
{
public function checkChanges(Supplier $supplier): void
{
$newPrices = $this->fetchPrices($supplier);
foreach ($newPrices as $sku => $newPrice) {
$oldPrice = SupplierPrice::where([
'supplier_id' => $supplier->id,
'sku' => $sku,
])->value('price');
if ($oldPrice === null) continue; // new position — don't notify
$changePercent = abs($newPrice - $oldPrice) / $oldPrice * 100;
if ($changePercent >= config('suppliers.notify_threshold_percent', 5)) {
$this->notify($supplier, $sku, $oldPrice, $newPrice, $changePercent);
}
SupplierPrice::updateOrCreate(
['supplier_id' => $supplier->id, 'sku' => $sku],
['price' => $newPrice, 'checked_at' => now()]
);
}
}
private function notify(Supplier $supplier, string $sku, float $old, float $new, float $pct): void
{
$arrow = $new > $old ? '📈' : '📉';
$direction = $new > $old ? 'increased' : 'decreased';
$message = "{$arrow} <b>Price {$direction}</b>\n\n" .
"Supplier: {$supplier->name}\n" .
"SKU: <code>{$sku}</code>\n" .
"Was: " . number_format($old, 2) . " ₽\n" .
"Now: " . number_format($new, 2) . " ₽\n" .
"Change: <b>" . round($pct, 1) . "%</b>";
$this->telegram->sendToChannel(config('telegram.pricing_channel'), $message);
}
}
Notification threshold (5% by default) is configured. Check runs by schedule via Cron/Celery Beat.
Timeline: 2–3 business days.







