{"id":37010287,"url":"https://github.com/voniersa/twitch-live-chat-library","last_synced_at":"2026-01-14T00:59:17.505Z","repository":{"id":203357285,"uuid":"709370047","full_name":"voniersa/twitch-live-chat-library","owner":"voniersa","description":"A simple and easy to use PHP library for reading from and writing to the twitch irc live chats by partially using the observer design pattern","archived":false,"fork":false,"pushed_at":"2025-01-31T19:29:08.000Z","size":703,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-12T20:33:14.803Z","etag":null,"topics":["chat","chatbot","library","php","twitch"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/voniersa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-24T15:22:58.000Z","updated_at":"2025-04-30T12:30:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"63c10982-0389-4510-a7a5-6d2c3f71258a","html_url":"https://github.com/voniersa/twitch-live-chat-library","commit_stats":null,"previous_names":["voniersa/twitch-live-chat-library"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/voniersa/twitch-live-chat-library","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voniersa%2Ftwitch-live-chat-library","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voniersa%2Ftwitch-live-chat-library/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voniersa%2Ftwitch-live-chat-library/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voniersa%2Ftwitch-live-chat-library/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/voniersa","download_url":"https://codeload.github.com/voniersa/twitch-live-chat-library/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voniersa%2Ftwitch-live-chat-library/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28407632,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T00:40:43.272Z","status":"ssl_error","status_checked_at":"2026-01-14T00:40:42.636Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chat","chatbot","library","php","twitch"],"created_at":"2026-01-14T00:59:16.806Z","updated_at":"2026-01-14T00:59:17.487Z","avatar_url":"https://github.com/voniersa.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Twitch Live Chat Library\n[![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)\n\nA simple and easy to use library for reading from and writing to the twitch irc live chats by partially using the observer design pattern.\n\nWith this library you can easily build your own twitch chatbot with PHP.\n\n## Requirements\nPHP Version 8.2 or higher\n\n## How to use\nYou can install the library with composer:\n\n```bash\ncomposer require voniersa/twitch-live-chat\n```\n\n## Functionalities\nFirstly you have to create a new [TwitchChatAdapter](src/TwitchChatAdapter.php):\n```php\nuse voniersa\\twitch\\livechat\\TwitchChatAdapter;\nuse voniersa\\twitch\\livechat\\IrcConnector;\nuse voniersa\\twitch\\livechat\\ConnectionVerifier;\n\n$adapter = new TwitchChatAdapter(new IrcConnector(), new ConnectionVerifier());\n```\nWith 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\n* [__UserName__](src/valueObjects/UserName.php) - the username of your account which you want to use as your chatbot\n* [__Password__](src/valueObjects/Password.php) - the authentication code of your chatbot account. You can get your oauth code at https://twitchtokengenerator.com/\n* [__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\n\nYou can open multiple connections with different users and channels.\n```php\n$connection = $adapter-\u003eopenConnection(\n    UserName::fromString(\"xxxxxx\"),\n    Password::fromString(\"oauth:xxxxxx\"),\n    ChannelCollection::fromArray([\n        ChannelName::fromString(\"#xxxxxx\"),\n        ChannelName::fromString(\"#xxxxxx\")\n    ])\n);\n```\nTo 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.\n```php\n$exampleObserver = new ExampleObserver();\n$connection-\u003eattach($exampleObserver);\n\n$connection-\u003edetach($exampleObserver);\n```\nYou 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).\n```php\nuse voniersa\\twitch\\livechat\\MessageObserver;\n\nclass ExampleObserver implements MessageObserver\n{\n    public function update(Message $message): void\n    {\n        // do here what ever you want ...\n    }\n}\n```\nThis 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.\n\nTo 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:\n```php\n$adapter-\u003ereadLiveChat($connection, 30);\n```\nWith 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.\n```php\n$adapter-\u003ewriteMessage($connection, ChannelName::fromString(\"#xxxxxx\"), \"This message is send to the live chat!\");\n```\n\n## Example\nIn the [demo.php](example/demo.php) you can find a simple code snippet, how you can use this library.\n\nTo run this example script, execute the following command:\n```\nmake demo username=\"xxxxxx\" password=\"oauth:xxxxxx\" channel=\"#xxxxxx\"\n```\n\n## License\nThis library is released under the MIT Licence. See the bundled [LICENSE file](LICENSE) for details.\n\n## Author\nSascha Vonier ([@voniersa](https://github.com/voniersa))\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvoniersa%2Ftwitch-live-chat-library","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvoniersa%2Ftwitch-live-chat-library","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvoniersa%2Ftwitch-live-chat-library/lists"}