plin-code/laravel-instagram-digest 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

plin-code/laravel-instagram-digest

Composer 安装命令:

composer require plin-code/laravel-instagram-digest

包简介

Laravel package that scrapes Instagram hashtags via Apify and sends a daily Telegram digest with inline action buttons.

README 文档

README

Latest Version on Packagist Total Downloads

Scrape Instagram hashtags via Apify, filter profiles by keywords and follower threshold, and send a daily Telegram digest with inline action buttons. Classify candidates with one tap.

What it does

  1. Runs the Apify apify~instagram-scraper actor against a list of hashtags.
  2. Filters results by bio/username keyword match and a minimum follower count.
  3. Upserts surviving profiles into instagram_digest_profiles.
  4. Once a day, sends the next N pending profiles as Telegram cards with inline buttons: Interesting, Reject, Show again later. Custom actions pluggable.
  5. Handles the callback when you tap a button: updates the profile status and removes the buttons from the message.

Bring your own data sources (hashtags, keywords, min-followers, chat id) via closures or plain config. Extend with custom action buttons and a custom card renderer.

Installation

composer require plin-code/laravel-instagram-digest
php artisan migrate

Add to your .env:

APIFY_TOKEN=your-apify-token
APIFY_ACTOR_ID=apify~instagram-scraper
APIFY_RESULTS_PER_HASHTAG=30

TELEGRAM_BOT_TOKEN=123:abc
TELEGRAM_CHAT_ID=-1001234567890
TELEGRAM_WEBHOOK_SECRET=a-long-random-string

Quickstart

In AppServiceProvider@boot:

use PlinCode\InstagramDigest\Facades\InstagramDigest;

public function boot(): void
{
    InstagramDigest::hashtagsUsing(fn () => ['trekking', 'hiking', 'guidealpine']);
    InstagramDigest::keywordsUsing(fn () => ['guida', 'trek', 'outdoor']);
    InstagramDigest::minFollowersUsing(fn () => 5000);
}

Register the Telegram webhook:

php artisan instagram-digest:webhook

Verify your Telegram setup end-to-end:

php artisan instagram-digest:demo

The demo uses a placehold.co URL for the placeholder image, so Telegram must be able to fetch that URL. If your network or bot configuration blocks external image fetches, pass a photo URL explicitly:

php artisan instagram-digest:demo --to=CHAT_ID

(Note: the --to option overrides the configured chat_id but currently uses the same placeholder image. For a full dry-run with your own image, register a custom CardRenderer — see below.)

Data sources: resolvers vs config

Every data source has two equivalent ways to supply it.

Via config (config/instagram-digest.php or env):

'hashtags' => ['trekking', 'hiking'],
'keywords' => ['guida', 'outdoor'],
'min_followers' => 5000,

Via resolver closure (takes precedence when registered):

InstagramDigest::hashtagsUsing(fn () => Hashtag::active()->pluck('name')->all());
InstagramDigest::keywordsUsing(fn () => Keyword::all()->pluck('term')->all());
InstagramDigest::minFollowersUsing(fn () => Setting::get('min_followers', 5000));
InstagramDigest::chatIdUsing(fn () => auth()->user()->telegram_chat_id);
InstagramDigest::dailyCountUsing(fn () => 10);

If no resolver is registered, the package falls back to config.

Custom actions

Register your own inline button:

use PlinCode\InstagramDigest\Facades\InstagramDigest;
use PlinCode\InstagramDigest\Models\Profile;

InstagramDigest::registerAction(
    key: 'archive',
    label: 'Archive',
    handler: fn (Profile $p) => $p->update(['status' => 'archived']),
);

Replace the default action set entirely:

InstagramDigest::defaultActions([
    new MyYesAction,
    new MyNoAction,
]);

Any class implementing PlinCode\InstagramDigest\Contracts\DigestAction is accepted.

Custom card rendering

Option A: publish the Blade view and edit it

php artisan vendor:publish --tag=instagram-digest-views

Then edit resources/views/vendor/instagram-digest/card.blade.php.

Option B: register your own renderer

use PlinCode\InstagramDigest\Contracts\CardRenderer;
use PlinCode\InstagramDigest\Facades\InstagramDigest;

InstagramDigest::renderCardUsing(MyCardRenderer::class);

Your renderer must return a PlinCode\InstagramDigest\Support\CardPayload.

Customizing the webhook route

The webhook is registered by the package at POST /instagram-digest/webhook/{secret?} with the api middleware group. Both the URL prefix and the middleware stack are config-driven — edit config/instagram-digest.php after publishing:

php artisan vendor:publish --tag=instagram-digest-config

Then adjust:

'route' => [
    'prefix' => 'instagram-digest',           // appears in the URL: /{prefix}/webhook/{secret?}
    'middleware' => ['api'],                  // any middleware array — e.g. ['api', 'throttle:60,1']
],

If you need full control (different HTTP verb, route model binding, custom controller), you can bypass the auto-registered route by setting 'middleware' => ['api', 'should-never-match'] (breaks the route) and defining your own pointing at PlinCode\InstagramDigest\Http\Controllers\WebhookController.

Scheduling

The package does NOT register any scheduled tasks. Wire the commands yourself in routes/console.php:

use Illuminate\Support\Facades\Schedule;

Schedule::command('instagram-digest:scrape')->weekdays()->at('09:30');
Schedule::command('instagram-digest:send')->weekdays()->at('10:00');

Events

Listen to the following events to integrate with your own domain:

Event Payload Use case
ProfileDiscovered Profile $profile, bool $isNew Sync to your CRM / lead model — $isNew distinguishes first-time discovery from refresh
ProfileStatusChanged Profile $profile, string $from, string $to React to user classification
DigestSent array $profileIds Metrics, auditing
ScrapingRunCompleted Run $run Notifications

Example listener:

public function handle(ProfileDiscovered $event): void
{
    if (! $event->isNew) {
        return;
    }

    Prospect::firstOrCreate(
        ['instagram_handle' => $event->profile->instagram_username],
        ['status' => 'new'],
    );
}

Testing your integration

The package plays nicely with Laravel's HTTP fakes and event fakes. In your own tests:

use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Event;
use PlinCode\InstagramDigest\Events\ProfileDiscovered;
use PlinCode\InstagramDigest\Jobs\RunHashtagScrapingJob;

it('my app reacts to ProfileDiscovered', function () {
    Event::fake([ProfileDiscovered::class]);
    Http::fake([
        'api.apify.com/*' => Http::response([/* ... */], 200),
    ]);

    dispatch_sync(new RunHashtagScrapingJob);

    Event::assertDispatched(ProfileDiscovered::class);
});

For the Telegram side, fake api.telegram.org/* and assert via Http::assertSent(...).

Commands

Command Description
instagram-digest:scrape [--sync] Dispatch the Apify scraping job.
instagram-digest:send [--count=N] Dispatch the Telegram digest job.
instagram-digest:webhook [url?] Register the Telegram webhook with Telegram.
instagram-digest:demo [--to=id] Send one fake card to verify Telegram config.

Testing

composer test
composer analyse
composer format

License

MIT. See LICENSE.md.

plin-code/laravel-instagram-digest 适用场景与选型建议

plin-code/laravel-instagram-digest 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 04 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「digest」 「laravel」 「instagram」 「scraping」 「telegram」 「apify」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 plin-code/laravel-instagram-digest 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 plin-code/laravel-instagram-digest 我们能提供哪些服务?
定制开发 / 二次开发

基于 plin-code/laravel-instagram-digest 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 42
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-20