PHP code example of voniersa / twitch-live-chat

1. Go to this page and download the library: Download voniersa/twitch-live-chat library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

voniersa / twitch-live-chat example snippets


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

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

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

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

$connection->detach($exampleObserver);

use voniersa\twitch\livechat\MessageObserver;

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

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

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