PHPackages                             voniersa/twitch-live-chat - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. voniersa/twitch-live-chat

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

voniersa/twitch-live-chat
=========================

A simple and easy to use library for reading from and writing to the twitch irc live chats by partially using the observer design pattern

1.0.2(3mo ago)134MITPHPPHP ^8.2CI passing

Since Oct 24Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/voniersa/twitch-live-chat-library)[ Packagist](https://packagist.org/packages/voniersa/twitch-live-chat)[ RSS](/packages/voniersa-twitch-live-chat/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (5)Used By (0)

Twitch Live Chat Library
========================

[](#twitch-live-chat-library)

[![Unit tests](https://github.com/voniersa/twitch-live-chat-library/actions/workflows/unit-tests.yml/badge.svg?event=push)](https://github.com/voniersa/twitch-live-chat-library/actions/workflows/unit-tests.yml)

A simple and easy to use library for reading from and writing to the twitch irc live chats by partially using the observer design pattern.

With this library you can easily build your own twitch chatbot with PHP.

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

[](#requirements)

PHP Version 8.2 or higher

How to use
----------

[](#how-to-use)

You can install the library with composer:

```
composer require voniersa/twitch-live-chat
```

Functionalities
---------------

[](#functionalities)

Firstly you have to create a new [TwitchChatAdapter](src/TwitchChatAdapter.php):

```
use voniersa\twitch\livechat\TwitchChatAdapter;
use voniersa\twitch\livechat\IrcConnector;
use voniersa\twitch\livechat\ConnectionVerifier;

$adapter = new TwitchChatAdapter(new IrcConnector(), new ConnectionVerifier());
```

With this Adapter you can open a connection to twitch live chats by executing the [openConnection()](src/TwitchChatAdapter.php#L27) function. This function needs the parameters

- [**UserName**](src/valueObjects/UserName.php) - the username of your account which you want to use as your chatbot
- [**Password**](src/valueObjects/Password.php) - the authentication code of your chatbot account. You can get your oauth code at
- [**ChannelCollection**](src/ChannelCollection.php) - a collection of all channels where your chatbot should be active. A channel always needs a **\#** in front of the channel name

You can open multiple connections with different users and channels.

```
$connection = $adapter->openConnection(
    UserName::fromString("xxxxxx"),
    Password::fromString("oauth:xxxxxx"),
    ChannelCollection::fromArray([
        ChannelName::fromString("#xxxxxx"),
        ChannelName::fromString("#xxxxxx")
    ])
);
```

To this connection you can add as many observers as you want by executing the [attach()](src/SocketConnection.php#L43) function and later also the [detach()](src/SocketConnection.php#L51) function to remove an observer.

```
$exampleObserver = new ExampleObserver();
$connection->attach($exampleObserver);

$connection->detach($exampleObserver);
```

You have to write the Observers by yourself. For that simply create a new class which implements the [**MessageObserver**](src/MessageObserver.php) interface. You need to add the Method update() with the parameter of type [**Message**](src/valueObjects/Message.php).

```
use voniersa\twitch\livechat\MessageObserver;

class ExampleObserver implements MessageObserver
{
    public function update(Message $message): void
    {
        // do here what ever you want ...
    }
}
```

This update() method gets called everytime when a message is written to the live chats. Here you can define what should happen if a message appears.

To actually start reading the chat simply call the function [readLiveChat()](src/TwitchChatAdapter.php#L83) of the Adapter. You need to provide the connection and a time after how many seconds the reading process should stop. The function returns a [**MessageCollection**](src/MessageCollection.php) which contains all messages that are written to the chat in that time period:

```
$adapter->readLiveChat($connection, 30);
```

With this library you cannot only read from specific live chats. You can also write something to the chat by simply call the [writeMessage()](src/TwitchChatAdapter.php#L69) function.

```
$adapter->writeMessage($connection, ChannelName::fromString("#xxxxxx"), "This message is send to the live chat!");
```

Example
-------

[](#example)

In the [demo.php](example/demo.php) you can find a simple code snippet, how you can use this library.

To run this example script, execute the following command:

```
make demo username="xxxxxx" password="oauth:xxxxxx" channel="#xxxxxx"

```

License
-------

[](#license)

This library is released under the MIT Licence. See the bundled [LICENSE file](LICENSE) for details.

Author
------

[](#author)

Sascha Vonier ([@voniersa](https://github.com/voniersa))

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance80

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 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 ~413 days

Total

3

Last Release

105d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/99a1cb45e14288dc0467937d169279ca3996effc906828f48955730b4ef7e11c?d=identicon)[voniersa](/maintainers/voniersa)

---

Top Contributors

[![voniersa](https://avatars.githubusercontent.com/u/53305317?v=4)](https://github.com/voniersa "voniersa (9 commits)")

---

Tags

chatchatbotlibraryphptwitch

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/voniersa-twitch-live-chat/health.svg)

```
[![Health](https://phpackages.com/badges/voniersa-twitch-live-chat/health.svg)](https://phpackages.com/packages/voniersa-twitch-live-chat)
```

PHPackages © 2026

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