Skip to content
This repository has been archived by the owner on Dec 29, 2020. It is now read-only.

Caveats

Max Baumann edited this page Jul 14, 2020 · 3 revisions

Caveats

New Routes

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);

Join and part chats

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");
...

On join and part

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);
});

Request permissions (Scopes)

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);
})
Clone this wiki locally