Creates a mixer bot client and runs it based on a set of options.
(Object
= {}
)
options for the mixer-bot.
Name | Description |
---|---|
options.env String
|
path to the .env file. |
options.channel_id String
|
channel id to join for the bot, which can be found here for a user:
https://mixer.com/api/v1/channels/
|
options.greeting String
|
the greeting message to display when the bot joins a channel (If you use "@me" here it will be replaced with your username) |
options.on Function
|
a list of functions that define the mixer bot's response on channel actions (ChatMessage, UserJoin). Data is passed with reference to the mixer client (data.client), ws socket (data.socket), API user information (data.user_info), and these options (data.options). |
Object
:
returns a mixerbot client.
const mixerbot = require('mixer-bot');
// Create a .env file in the same location and set
// MIXER_ACCESS_TOKEN=***
// MIXER_CHANNEL_ID=***
// Setup options
var options = {};
options.on = {};
options.greeting = 'Hello!';
// Setup channel ID
// If left unset, this will be the id to your channel
// Get your channel id here: https://mixer.com/api/v1/channels/<username>?fields=id
// options.channel_id = '<CHANNEL_ID>';
// Assign bot to greet user when they enter
options.on.UserJoin = data => {
socket = data.socket;
return response => {
socket.call('msg',[
`Hi ${response.username}! I'm pingbot! Write !ping and I will pong back!`,
]);
}
};
// Assign bot to pong user if they message !ping
options.on.ChatMessage = data => {
socket = data.socket;
return response => {
if (response.message.message[0].data.toLowerCase().startsWith('!ping')) {
socket.call('msg', [`@${response.user_name} PONG!`]);
console.log(`Ponged ${response.user_name}`);
}
}
};
// Handle errors
options.on.error = data => {
return error => {
console.error('Socket error');
console.error(error);
}
};
// Run mixer bot
mixerbot(options);
Assigns the default options for mixerbot.
(Object)
an options object to assign defaults.
Object
:
the default options.
Gets connection information from Mixer's chat servers
(any)
(Number)
the channel_id of the channel you'd like to get connection information for.
Gets our Currently Authenticated Mixer user's information. This returns an object full of useful information about the user whose OAuth Token we provided above.
(Object)
the mixer client to use for requesting information.
Creates a Mixer chat socket and authenticates