mixer-bot

Creates a mixer bot client and runs it based on a set of options.

mixer-bot
Parameters
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/ ?fields=id
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).
Returns
Object: returns a mixerbot client.
Example
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);

assign_default_options

Assigns the default options for mixerbot.

assign_default_options(options: Object): Object
Parameters
options (Object) an options object to assign defaults.
Returns
Object: the default options.

get_connection_info

Gets connection information from Mixer's chat servers

get_connection_info(client: any, channel_id: Number)
Parameters
client (any)
channel_id (Number) the channel_id of the channel you'd like to get connection information for.

get_user_info

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.

get_user_info(client: Object)
Parameters
client (Object) the mixer client to use for requesting information.

join_chat

Creates a Mixer chat socket and authenticates

join_chat(client: any, user_id: number, channel_id: number)
Parameters
client (any)
user_id (number) The user to authenticate as
channel_id (number) The channel id of the channel you want to join