https://github.com/tacxou/nestjs_module_twurple
Twitch API/Chat/PubSub with Twurple NestJS module
https://github.com/tacxou/nestjs_module_twurple
abstract abstraction api async chat nestjs node nodejs npm promise pubsub spaces twitch twurple
Last synced: 3 months ago
JSON representation
Twitch API/Chat/PubSub with Twurple NestJS module
- Host: GitHub
- URL: https://github.com/tacxou/nestjs_module_twurple
- Owner: tacxou
- License: bsd-3-clause
- Created: 2023-03-18T13:43:01.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2026-03-11T20:36:12.000Z (3 months ago)
- Last Synced: 2026-03-11T20:43:51.043Z (3 months ago)
- Topics: abstract, abstraction, api, async, chat, nestjs, node, nodejs, npm, promise, pubsub, spaces, twitch, twurple
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@tacxou/nestjs_module_twurple
- Size: 88.9 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
Twitch API/Chat/PubSub with Twurple NestJS module
# Twurple Module
Twurple module for the NestJS framework.
## Installation
Install the package with your preferred package manager:
```bash
# bun
bun add @tacxou/nestjs_module_twurple
# npm
npm install @tacxou/nestjs_module_twurple
# yarn
yarn add @tacxou/nestjs_module_twurple
# pnpm
pnpm add @tacxou/nestjs_module_twurple
```
## Quick start examples
### 1) Configure the module
```ts
// app.module.ts
import { Module } from '@nestjs/common'
import { ConfigModule, ConfigService } from '@nestjs/config'
import { TwurpleModule, TwurpleOptions } from '@tacxou/nestjs_module_twurple'
@Module({
imports: [
ConfigModule.forRoot({ isGlobal: true }),
TwurpleModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (config: ConfigService) => ({
config: {
authProvider: config.getOrThrow('TWURPLE_AUTH_PROVIDER'),
chatChannels: config.get('TWURPLE_CHAT_CHANNELS', []),
},
}),
}),
],
})
export class AppModule {}
```
### 2) Inject and use Twurple clients
```ts
// twitch.service.ts
import { Injectable, OnModuleInit } from '@nestjs/common'
import {
InjectTwurpleApi,
InjectTwurpleChat,
InjectTwurplePubsub,
} from '@tacxou/nestjs_module_twurple'
import { ApiClient } from '@twurple/api'
import { ChatClient } from '@twurple/chat'
import { PubSubClient } from '@twurple/pubsub'
@Injectable()
export class TwitchService implements OnModuleInit {
constructor(
@InjectTwurpleApi() private readonly api: ApiClient,
@InjectTwurpleChat() private readonly chat: ChatClient,
@InjectTwurplePubsub() private readonly pubSub: PubSubClient,
) {}
async onModuleInit() {
this.chat.onMessage((channel, user, message) => {
if (message === '!ping') {
void this.chat.say(channel, `Pong @${user}`)
}
})
// Example API call
const me = await this.api.users.getMe()
console.log(`Twurple connected as: ${me?.displayName ?? 'unknown user'}`)
// Example PubSub subscription
// (adapt to your auth flow and topics)
// await this.pubSub.registerUserListener(...)
}
}
```
## Official Twurple documentation
This module wraps and exposes Twurple clients for NestJS.
For questions about Twurple classes, methods, events, and behavior, always refer to the official Twurple documentation:
- https://twurple.js.org/
- https://twurple.js.org/docs/
- https://twurple.js.org/reference/
- https://twurple.js.org/reference/chat/classes/ChatClient.html
- https://twurple.js.org/reference/api/classes/ApiClient.html
- https://twurple.js.org/reference/pubsub/classes/PubSubClient.html
## Tests
```bash
bun test tests
bun test tests --watch
bun test tests --coverage --coverage-reporter lcov
```