-
Notifications
You must be signed in to change notification settings - Fork 0
Caveats
Even though initialize()
also returns the express instance, you can not simply add new routes (e.g. simply do a app.get('/test', () => {...})
).
Instead you need to use the beforeRouteSetup
hook.
Example:
const options = {
beforeRouteSetup(app) {
app.get('/test', (req, res) => { ... })
}
};
const { client } = await initialize(options);
Normaly streamers can add the bot by visiting /add
and remove it on /remove
.
When the bot goes down and needs to be restarted, the list of channels is persisted in .config/channels.json
.
If you need to, for whatever reason, join or part channels programmatically,
import the joinChannel()
and leaveChannel()
functions.
Example:
import { joinChannel, leaveChannel } from 'twitch-chatbot-boilerplate';
...
await joinChannel("fosefx");
await leaveChannel("fosefx");
...
If you want to trigger any action when the bot is invited or removed to/from a chatroom you can do that using the boilerplate
EventEmitter.
import { joinChannel, leaveChannel } from 'twitch-chatbot-boilerplate';
const { client, boilerplate } = await initialize(/*...*/);
boilerplate.on("join", ({authData, basicProfile}) => {
client.say(basicProfile.login, `HeyGuys Hey, chat of @{basicProfile.login}`)
});
boilerplate.on("leave", ({authData, basicProfile}) => {
db.removeEverythingIKnowAbout(basicProfile.id);
});
More on scopes: https://dev.twitch.tv/docs/authentication#scopes
When the streamer adds your bot you can ask them for more permissions using the scopes
property in the initialize()
options object and recieve the the token using the boilerplate events mentioned above:
const { client, boilerplate } = await initialize({
scopes: ['channel:read:hype_train', 'user:read:email']
});
boilerplate.on('join', async ({ authData, basicProfile }) => {
await sendVerificationEmail(basicProfile.email);
addListenerForHypeTrain(authData.access_token);
})