!! DEPRACTED !!
Carlos, a chat bot for your team.
Carlos is a chat bot with Slack and Twitch integration, it uses pluggable functions as chat commands. It is meant to quicky create chat commands which have functionality attached to it without having any knowledge of an underlying API (but really is just wrapper around wrapper).
Table Of Contents
- Installation
- Example
- Carlos
- Connectors
- Build (TODO)
Installation
npm install carlos
Example
const carlos = ;const connector = 'xoxb-[TOKEN]';const chatBot = connector 'carlos'; chatBot; const knockknock = { chatBot;}; const THISISLOUD = { chatBot;}; // Trigger response "Who is there?" to channel with "!carlos knockknock"chatBot; // Trigger response "SPEAK UP" to channel with "!carlos loud speak up"chatBot; chatBot;
How does Carlos work
Carlos responds to commands issued by !name commandName
Initialization
Require the package
const carlos = ;
Create a connector and initialize your bot
Check "Connectors" for more explanation about the connectors.
A bot-name can only be registered one time, if you try to register a name twice an error will be thrown. Your script will continue but the second one will be ignored.
!! To create your Slack-token, check Slackconnector !!
const connector = 'xoxb-[TOKEN]'; /** * @param connector * @param string name * [@param function(err) handle possible errors while initializing bot ] */const chatBot = connector 'carlos'; const chatBotCarlos = connector 'carlos' { iferr console; console; };
Properties
Carlos exposes its connector
variable, which grants you access to underlaying API's and functions.
// Slack connector exampleconsole; // Slack connectorconsole; // Slack RTM APIconsole; // Slack Web API
Carlos also exposes the name
of the instance, this may come in handy for error logging.
// Get name - set connectedchatBot;
Methods
You are able to add commands Carlos should listen to by registering functions, these functions will be given some info (commandData
) about the called action. The exposed info in connectorInfo
is dependent of the connector.
If you are ready processing the data and have a witty reponse ready you can call chatBot.reply(commandData.connectorInfo, "Response")
to respond in the channel where the command occurred.
!! The name
and postCommandText
that triggered the command will always be included. No matter which connector is used. !!
Create a function
/** * @param obj commandData { * name: string commandName, * postCommandText: string commandMessage, * obj connectorInfo { * [message: messageText - part of SlackConnector] * [,user: userID - part of SlackConnector] * [,channel: channelID - part of SlackConnector] * } */const knockknock = { chatBot;};
Register the function
You can not register a command twice on the same bot. If you do so, an error will be thrown.
/** * @param string name of command * @param function command function * [@param function(err) handle possible errors while registering function] */chatBot; chatBot;
Get commands
Get an array of the registered commands.
/** * @return array commandNames list all the commands */chatBot;
This command may come in handy to give your team a list of all the registered commands while introducing the bot.
const listCommands = { chatBot;}; chatBot; chatBot;
Individual connectors may also contain functions that can be used as a command.
See "Connectors" for more.
Unregister functions
Just as easy as you registered functions, you can also unregister a function.
/** * @param string commandName to unregister */chatBot;chatBot;
Booting Carlos
Booting Carlos is the most important, and also easiest, part. This will make sure your bot is connected and listening to possible events.
chatBot;
Events
On connected
chatBot;
On command
The command event will be triggered as soon as Carlos receives an event. By using a switch
in this event you can cut out the register middle man. The commandData
object is the same as a function gets.
chatBot;
On error
chatBot;
Error Code | Error Name | Error Description |
---|---|---|
1 | DuplicateBotError | The bot name is already registered. |
2 | ConnectorError | Something bad is happening in the connector. Orginal error can be found orginalError property. |
3 | NoCommandError | ChatBot got triggered but no command was issued. |
4 | UnknownCommandError | ChatBot got triggered but no command was found. |
5 | DuplicateCommandError | Command is already registered. |
Connectors
Out of the box Carlos comes with a SlackConnector and a TwitchConnector, you can write your own connectors if needed for other integrations. See "Creating connectors".
SlackConnector
You can create your token in your Slack Dashboard once you are signed in. The App Directory is found here. More information about Slack bots can be found here.
Initialize
/** * @param string your Slack-token */const connector = 'xoxb-[TOKEN]';
Methods
/** * @return array userNames list all users in Slack */connector; /** * @return array channelNames list all channels in Slack */connector;
TwitchConnector (first-version)
Connect your bot with Twitch chat. It might be good to consider creating a new account for your bot with an appropriate name to avoid confusion. In this case, it is also considered good to grant your bot-user mod rights.
Initialize
const identityTwitch = username: '[YOUR-USER-NAME]' password: 'oauth:[YOUR-TOKEN]'const channelsTwitch = '#[YOUR-USER-NAME]'; /** * @param obj identity Your Twitch-identity * @param array channels Twitch-channels to join */const connector = identityTwitch channelsTwitch;
Creating connectors
TODO:: (See current ones)
Build
TODO:: (Babel)
Future and TODO's
- Create more connectors.
- Tests.
- (...)