Twitch API/Chat/PubSub with Twurple NestJS module
Twurple for NestJS Framework
yarn add @the-software-compagny/nestjs_module_twurple
// app.module.ts
import { TwurpleModule, TwurpleOptions } from '@the-software-compagny/nestjs_module_twurple'
TwurpleModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: async (config: ConfigService) => ({
config: config.get<TwurpleOptions>('twurple.options'),
}),
})
// twitch.service.ts
import { FactorydriveService } from '@the-software-compagny/nestjs_module_factorydrive'
@Injectable()
export class FileStorageService {
public constructor(
@InjectTwurpleApi() private readonly twurpleApi: ApiClient,
@InjectTwurpleChat() private readonly twurpleChat: ChatClient,
@InjectTwurplePubsub() private readonly twurplePubSub: PubSubClient,
) {
// ...
this.twurpleChat.onMessage(async (channel, user, message) => {
if (message === '!ping') {
this.twurpleChat.say(channel, 'Pong!')
}
})
// ...
}
}