Download the PHP package vzgcoders/twitchphp without Composer
On this page you can find all versions of the php package vzgcoders/twitchphp. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package twitchphp
TwitchPHP
An async ReactPHP framework for the Twitch Helix API, EventSub over WebSocket, and chat (IRC over WebSocket) — designed and built like DiscordPHP.
Requirements
- PHP 8.4+
- Composer
- A registered application at https://dev.twitch.tv/console/apps for the
client_id/client_secret
Installation
The HTTP transport lives in its own package, twitchphp/http,
and is pulled in automatically.
Windows and SSL
PHP on Windows has no access to the system certificate store. Download a
CA bundle and point openssl.cafile in your php.ini at it,
otherwise every TLS connection fails silently.
Authentication
Twitch has several OAuth flows; TwitchPHP supports the ones a bot or service needs.
| You have… | Pass | Behaviour |
|---|---|---|
| A client id + secret only | client_id, client_secret |
Requests an app access token (client-credentials). Good for public data and EventSub. |
| A user access token | token (+ optional refresh_token) |
Validated on startup. With a refresh_token, an invalid/expired token is refreshed transparently, and any Helix 401 triggers one recover-and-retry. |
Twitch\Http\OAuth also exposes authorizationUrl(), exchangeCode(), deviceCode(), validate()
and revoke() for building the authorization-code / device-code flows in your own app.
Keeping a token alive
Twitch invalidates the previous refresh token every time it issues a new one, so
a long-running client that refreshes without saving the result locks itself out
of its own account as soon as the process restarts. Pass a token_store and the
rotation is persisted for you; pass a reauthorize strategy and a grant that
can no longer be refreshed is rebuilt from scratch:
A 401 is then refreshed, or re-authorized, and the request retried once. The
exception is a missing scope: MissingScopeException surfaces immediately,
naming the scopes that would have satisfied the call, because no amount of
re-issuing widens a grant that was never asked for. See
examples/self-healing-auth.php.
The Helix client
Resources hang off the client as repositories, mirroring DiscordPHP. 29 of them:
Every call returns a React\Promise\PromiseInterface. Collections are
Discord\Helpers\Collection instances of
hydrated Twitch\Parts\* models.
Repositories share a common surface from Twitch\Repository\AbstractRepository:
freshen(), all() (auto-follows pagination.cursor), fetch($id), save($part),
delete($part), plus get(), first(), filter() and iteration.
EventSub
Enable the WebSocket transport with 'eventsub' => true, then subscribe once the session is ready:
SubscriptionTypes has a constant for every EventSub type and knows the version
Twitch currently wants for it. Session reconnects (session_reconnect),
keepalives and revocation are handled for you, and the desired subscription set
(deduplicated) is replayed automatically onto a fresh session after a drop.
Chat (IRC)
Pass a nick and channels to connect the chat client. It speaks IRCv3 over
wss://irc-ws.chat.twitch.tv and parses tags into Twitch\Parts\ChatMessage parts.
Richer commands
Twitch\Chat\CommandClient layers aliases, per-user cooldowns, permission
levels and an auto !help on top of the plain command event:
Moderators and the broadcaster bypass cooldowns; permission also accepts a
fn (ChatMessage $m): bool predicate.
Events
| Event | Payload | Notes |
|---|---|---|
init / ready |
Twitch |
Authenticated and connected. |
error |
\Throwable, Twitch |
|
token_refreshed |
string $token, Twitch |
|
closed |
Twitch |
After close(). |
eventsub |
string $type, array $event, array $meta, Twitch |
Every notification. |
eventsub.<type> |
array $event, array $meta, Twitch |
e.g. eventsub.channel.chat.message. |
eventsub.ready / eventsub.keepalive / eventsub.revoked / eventsub.disconnected |
||
chat |
ChatMessage |
Any chat line. |
command |
string $name, array $args, ChatMessage |
Prefix commands. |
Configuration
| Option | Default | |
|---|---|---|
client_id |
— | Required. |
client_secret |
'' |
Enables the app-token flow. |
token / refresh_token |
null |
A user token and its refresh token. |
scopes |
[] |
Informational. |
loop |
Loop::get() |
A React\EventLoop\LoopInterface. |
logger |
NullLogger |
Any PSR-3 logger. |
socket_options |
[] |
Passed to React\Socket\Connector. |
nick |
null |
Set to connect the IRC client. |
channels |
[] |
Normalised to #lowercase. |
command_prefix |
'!' |
|
eventsub |
false |
Set to connect the EventSub client. |
token_store |
null |
A Twitch\Auth\TokenStoreInterface. Read at startup, written through on every token change. |
reauthorize |
null |
A Twitch\Auth\ReauthorizerInterface, used when refreshing can no longer recover a grant. |
Development
License
MIT — see LICENSE.
All versions of twitchphp with dependencies
twitchphp/http Version ^1.1
discord-php-helpers/collection Version dev-main
evenement/evenement Version ^3.0
nesbot/carbon Version ^3.8 || ^2.72
psr/log Version ^1.1 || ^2.0 || ^3.0
ratchet/pawl Version ^0.4.1
react/event-loop Version ^1.5
react/promise Version ^3.2 || ^2.11
react/socket Version ^1.16
symfony/options-resolver Version ^6.4 || ^7.0