PHPackages                             nanato12/phine - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. nanato12/phine

ActiveLibrary

nanato12/phine
==============

LINE Messaging API SDK for PHP Wrapper

v5.0(3mo ago)34461Apache-2.0PHPPHP &gt;=8.1CI passing

Since May 2Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/nanato12/phine)[ Packagist](https://packagist.org/packages/nanato12/phine)[ Docs](https://github.com/nanato12/phine)[ RSS](/packages/nanato12-phine/feed)WikiDiscussions develop Synced 2d ago

READMEChangelog (4)Dependencies (4)Versions (13)Used By (0)

Phine
=====

[](#phine)

A developer-friendly wrapper for the LINE Messaging API SDK for PHP.

Phine simplifies common LINE bot operations by providing intuitive message builders, event handlers, and convenient client methods.

Installation
------------

[](#installation)

```
composer require nanato12/phine
```

Requirements
------------

[](#requirements)

- PHP &gt;= 8.1
- linecorp/line-bot-sdk ^12.4

Quick Start
-----------

[](#quick-start)

```
use Phine\Client;
use Phine\MessageBuilders\TextMessageBuilder;

$client = new Client($channelSecret, $channelAccessToken);

// Parse incoming webhook request
$events = $client->parseEventRequest($requestBody, $signature);

foreach ($events as $event) {
    $client->setEvent($event);
    $client->reply([new TextMessageBuilder('Hello!')]);
}
```

Client
------

[](#client)

The `Client` class extends `MessagingApiApi` from the official LINE SDK, so all original methods are available.

```
$client = new Client($channelSecret, $channelAccessToken);
```

Message Builders
----------------

[](#message-builders)

Phine provides convenient builders for creating LINE messages.

### TextMessageBuilder

[](#textmessagebuilder)

```
use Phine\MessageBuilders\TextMessageBuilder;

// Simple text message
$message = new TextMessageBuilder('Hello!');

// With LINE emojis and quote
$message = new TextMessageBuilder(
    text: '$ Hello!',
    emojis: [$emoji],
    quoteToken: 'quote-token'
);
```

### RawFlexMessageBuilder

[](#rawflexmessagebuilder)

Build Flex Messages from a JSON array. Useful when designing messages with the [Flex Message Simulator](https://developers.line.biz/flex-simulator/).

```
use Phine\MessageBuilders\RawFlexMessageBuilder;

$json = file_get_contents('flex.json');
$contents = json_decode($json, true);
$message = new RawFlexMessageBuilder($contents, 'Alt text for notifications');
```

### ImageMessageBuilder

[](#imagemessagebuilder)

```
use Phine\MessageBuilders\ImageMessageBuilder;

$message = new ImageMessageBuilder(
    originalContentUrl: 'https://example.com/image.jpg',
    previewImageUrl: 'https://example.com/image-preview.jpg'
);
```

### VideoMessageBuilder

[](#videomessagebuilder)

```
use Phine\MessageBuilders\VideoMessageBuilder;

$message = new VideoMessageBuilder(
    originalContentUrl: 'https://example.com/video.mp4',
    previewImageUrl: 'https://example.com/video-thumbnail.jpg',
    trackingId: 'tracking-123' // optional, for tracking video views
);
```

### AudioMessageBuilder

[](#audiomessagebuilder)

```
use Phine\MessageBuilders\AudioMessageBuilder;

$message = new AudioMessageBuilder(
    originalContentUrl: 'https://example.com/audio.m4a',
    duration: 60000 // duration in milliseconds
);
```

### StickerMessageBuilder

[](#stickermessagebuilder)

```
use Phine\MessageBuilders\StickerMessageBuilder;

$message = new StickerMessageBuilder(
    packageId: '446',
    stickerId: '1988'
);
```

### LocationMessageBuilder

[](#locationmessagebuilder)

```
use Phine\MessageBuilders\LocationMessageBuilder;

$message = new LocationMessageBuilder(
    title: 'Tokyo Station',
    address: '1 Chome Marunouchi, Chiyoda City, Tokyo',
    latitude: 35.6812,
    longitude: 139.7671
);
```

Client Methods
--------------

[](#client-methods)

### parseEventRequest

[](#parseeventrequest)

Parses the incoming webhook request body and validates the signature.

```
$events = $client->parseEventRequest($requestBody, $signature);
```

### setEvent

[](#setevent)

Stores the current event in the client instance. Required before calling `reply()`.

```
$client->setEvent($event);
```

### reply

[](#reply)

Sends a reply message to the user. Must call `setEvent()` first.

```
// Simple reply
$client->reply([new TextMessageBuilder('Hello!')]);

// With sender icon and quick reply buttons
$client->reply($messages, $sender, $quickReply);
```

### push

[](#push)

Sends a push message to a specific user, group, or room.

```
$client->push($userId, [new TextMessageBuilder('Hello!')]);

// With sender and quick reply
$client->push($userId, $messages, $sender, $quickReply);
```

### sendMulticast

[](#sendmulticast)

Sends a message to multiple users at once (up to 500 users).

```
$userIds = ['U1234...', 'U5678...'];
$client->sendMulticast($userIds, [new TextMessageBuilder('Hello everyone!')]);
```

### sendBroadcast

[](#sendbroadcast)

Sends a message to all users who have added your bot as a friend.

```
$client->sendBroadcast([new TextMessageBuilder('Announcement!')]);
```

### getProfileFromUserID

[](#getprofilefromuserid)

Retrieves a user's profile. Automatically uses the appropriate API based on the event source (user, group, or room).

```
$profile = $client->getProfileFromUserID($userId);

echo $profile->displayName;
echo $profile->pictureUrl;
echo $profile->statusMessage; // Only available for 1:1 chats
```

Event Handlers
--------------

[](#event-handlers)

Phine provides an event handling system to organize your bot logic.

### BaseEventHandler

[](#baseeventhandler)

Create handlers for specific event types:

```
use LINE\Webhook\Model\Event;
use LINE\Webhook\Model\MessageEvent;
use LINE\Webhook\Model\TextMessageContent;
use Phine\Client;
use Phine\Handlers\BaseEventHandler;
use Phine\MessageBuilders\TextMessageBuilder;

class TextMessageHandler extends BaseEventHandler
{
    public const EVENT_CLASS = MessageEvent::class;
    public const MESSAGE_TYPE_CLASS = TextMessageContent::class;
    // Optional: public const MESSAGE_SOURCE_CLASS = GroupSource::class;

    public function handle(Client $client, Event $event): void
    {
        $client->reply([new TextMessageBuilder('Message received!')]);
    }
}
```

### BaseCommandHandler

[](#basecommandhandler)

Create handlers that respond to specific text commands:

```
use LINE\Webhook\Model\Event;
use Phine\Client;
use Phine\Handlers\BaseCommandHandler;
use Phine\MessageBuilders\TextMessageBuilder;

class HelloHandler extends BaseCommandHandler
{
    public static function commands(): array
    {
        return ['hello', 'hi', 'hey'];
    }

    public function handle(Client $client, Event $event): void
    {
        $client->reply([new TextMessageBuilder('Hello!')]);
    }
}
```

For commands with arguments, use prefix matching:

```
class SearchHandler extends BaseCommandHandler
{
    public static function commands(): array
    {
        return ['search '];
    }

    public static function isPrefix(): bool
    {
        return true; // Matches "search foo", "search bar", etc.
    }

    public function handle(Client $client, Event $event): void
    {
        /** @var MessageEvent $event */
        /** @var TextMessageContent $message */
        $message = $event->getMessage();
        $keyword = substr($message->getText(), 7); // Remove "search "

        // Search logic here...
    }
}
```

### EventDispatcher

[](#eventdispatcher)

Register and dispatch events to your handlers:

```
use Phine\Handlers\EventDispatcher;

class BotDispatcher extends EventDispatcher
{
    public function getHandlerClasses(): array
    {
        return [
            TextMessageHandler::class,
            HelloHandler::class,
            SearchHandler::class,
        ];
    }
}

// In your webhook endpoint
$events = $client->parseEventRequest($body, $signature);

foreach ($events as $event) {
    BotDispatcher::dispatch($client, $event);
}
```

License
-------

[](#license)

Apache-2.0

###  Health Score

48

—

FairBetter than 94% of packages

Maintenance82

Actively maintained with recent releases

Popularity17

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~264 days

Recently: every ~510 days

Total

9

Last Release

91d ago

Major Versions

v1.0.3 → v2.0.02020-07-13

v2.0.0 → v3.0.02021-01-06

v3.0.0 → v4.0.02023-12-30

v4.0.1 → v5.02026-02-11

### Community

Maintainers

![](https://www.gravatar.com/avatar/b323a83dc5db014d7b3fd3491755bab605c8b8ed5af98b4222ccafa5a5896b4d?d=identicon)[nanato12](/maintainers/nanato12)

---

Top Contributors

[![nanato12](https://avatars.githubusercontent.com/u/49806926?v=4)](https://github.com/nanato12 "nanato12 (71 commits)")

---

Tags

linebotphpphp-linebotwrapperlineline botphineline-bot-sdkline-messaging-api

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/nanato12-phine/health.svg)

```
[![Health](https://phpackages.com/badges/nanato12-phine/health.svg)](https://phpackages.com/packages/nanato12-phine)
```

###  Alternatives

[linecorp/line-bot-sdk

SDK of the LINE BOT API for PHP

7323.0M21](/packages/linecorp-line-bot-sdk)[akaunting/laravel-apexcharts

ApexCharts package for Laravel

84288.3k2](/packages/akaunting-laravel-apexcharts)[cmdotcom/text-sdk-php

PHP SDK to send messages with CM.com

23680.0k4](/packages/cmdotcom-text-sdk-php)[phalcon/cli-options-parser

Command line arguments/options parser.

181.0M7](/packages/phalcon-cli-options-parser)[revolution/laravel-line-sdk

LINE SDK for Laravel

2235.8k](/packages/revolution-laravel-line-sdk)[image-charts/image-charts

Official Image-Charts.com API client library

2762.3k](/packages/image-charts-image-charts)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
