定制 ka4ivan/laravel-notification-channel-instagram 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

ka4ivan/laravel-notification-channel-instagram

Composer 安装命令:

composer require ka4ivan/laravel-notification-channel-instagram

包简介

Instagram Notifications Channel for Laravel

README 文档

README

License Build Status Latest Stable Version Total Downloads

This package makes it easy to send notifications using the Instagram Messenger with Laravel.

Contents

Installation

You can install the package via composer:

composer require ka4ivan/laravel-notification-channel-instagram

Setting up your Instagram Bot

Get Profile ID

curl -X GET "https://graph.instagram.com/me?fields=id,username&access_token=ACCESS_TOKEN"

Set config

Next we need to add tokens to our Laravel configurations. Create a new Instagram section inside config/services.php and place the page token there:

// config/services.php
'instagram' => [
    'api_version' => env('INSTAGRAM_API_VERSION', '22.0'),
    'access_token' => env('INSTAGRAM_ACCESS_TOKEN', ''),
    'profile_id' => env('INSTAGRAM_PROFILE_ID', ''),
    'start_buttons' => [
        [
            'question' => 'Start',
            'payload' => 'start',
        ],
    ],
],

Set start buttons

Run the command to set the start buttons

php artisan instagram:set-start-buttons

Possible options for the command

{--access_token= : Instagram access token}
{--profile_id= : Instagram profile ID}
{--api_version= : Instagram API version (default from config)}'

This command will add the start buttons that appear when entering the chat for the first time

image

Usage

You can now use the Instagram channel in your via() method, inside the InvoicePaid class. The to($recipientId) (IGSID) method defines the Instagram user, you want to send the notification to.

use NotificationChannels\Instagram\InstagramChannel;
use NotificationChannels\Instagram\InstagramMessage;

use Illuminate\Notifications\Notification;

class ChannelConnected extends Notification
{
    public function via($notifiable)
    {
        return [InstagramChannel::class];
    }

    public function toInstagram($notifiable)
    {

        return InstagramMessage::create()
            ->to($notifiable->instagram_id) // Optional
            ->setApiVersion('22.0') // Optional
            ->setAccessToken('ABCD') // Optional
            ->setProfileId('abcd') // Optional
            ->text('Congratulations, the communication channel is connected');
    }
}

The notification will be sent from your Instagram page, whose page token you have configured earlier. Here's a screenshot preview of the notification inside the chat window.

image

Message Examples

Basic Text Message
return InstagramMessage::create('You have just paid your monthly fee! Thanks');
Message With Attachment
return InstagramMessage::create()
    ->attach(AttachmentType::IMAGE, url('images/'.$this->product->id))
    ->to($notifiable->instagram_id);
Media types and specifications
Media Type Supported Format Supported Size Maximum
Audio aac, m4a, wav, mp4 25MB
Image png, jpeg, gif 8MB
Video mp4, ogg, avi, mov, webm 25MB
Message With Buttons
return InstagramMessage::create()
    ->to($notifiable->instagram_id)
    ->text('How can we help?')
    ->buttons([
        Button::create('View Website', $url)->isTypeWebUrl(),
        Button::create('Start Chatting', ['user' => $this->user->id])->isTypePostback() // Custom payload sent back to your server
    ]);

Routing a message

You can either send the notification by providing with the page-scoped user id of the recipient to the to($recipientId) (IGSID) method like shown in the above example or add a routeNotificationForInstagram() method in your notifiable model:

/**
 * Route notifications for the Instagram channel.
 *
 * @return int
 */
public function routeNotificationForInstagram()
{
    return $this->instagram_id;
}

Available Message methods

  • to($recipientId): (string) User (recipient) Instagram ID (IGSID).
  • text(''): (string) Notification message.
  • attach($attachmentType, $url): (AttachmentType, string) An attachment type (IMAGE, AUDIO, VIDEO) and the url of this attachment.
  • attachMany($attachmentType, $urls): (AttachmentType, array) An attachment type (IMAGE, AUDIO, VIDEO) and the urls array of this attachments.
  • buttons($buttons = []): (array) An array of "Call to Action" buttons (Created using NotificationChannels\Instagram\Components\Button::create()). You can add up to 3 buttons of one of the following types: web_url or postback. See Button methods below for more details.
  • setApiVersion($apiVersion): (string) Set Default Graph API Version.
  • setAccessToken($accessToken): (string) Set the access token used for authenticating API requests.
  • setProfileId($profileId): (string) Set the Instagram profile ID for API requests.

Available Button methods

  • title(''): (string) Button Title.
  • data(''): (string) Button Data - It can be a web url or postback data.
  • type(''): (string) Button Type - web_url or postback. Use ButtonType enumerator for guaranteeing valid values
  • isTypeWebUrl(): Helper method to create a web_url type button.
  • isTypePostback(): Helper method to create a postback type button.

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.

ka4ivan/laravel-notification-channel-instagram 适用场景与选型建议

ka4ivan/laravel-notification-channel-instagram 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 70 次下载、GitHub Stars 达 4, 最近一次更新时间为 2025 年 05 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 ka4ivan/laravel-notification-channel-instagram 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-15