Alias

Alias

Class representing a bot alias. Aliases are used to identify the bot as a different user in Slack by setting a custom name and avatar.

Constructor

new Alias(options)

Create a bot alias.
Source:
Parameters:
Name Type Description
options Object The alias options.
Name Type Attributes Description
name String The name to give the bot when using this alias.
avatar String <optional>
Either an emoji name or URL of an image to use as a bot avatar.
Examples

Create and register an alias

bot.use(new Bot.Alias({
    name: 'DiceBot',
    avatar: 'game_die' // An emoji name or image URL
}));

Use an alias as part of a Responder

bot.use(new Bot.Listener.Command({
    name: 'dice roller',
    trigger: 'roll a die',
    handler: new Bot.Responder.RandomMessage({
        alias: 'DiceBot',
        messages: [
            '1', '2', '3', '4', '5', '6'
        ]
    })
}));

Use an alias as part of a handler function

bot.use(new Bot.Listener.Ambient({
    name: 'hunger listener',
    trigger: /i'?m hungry/i,
    handler: async message => {
        await bot
            .replyTo(message)
            .as('HungerBot')
            .with(`Hello hungry, I'm ${bot.name}`);
    }
}));

Members

(static) defaults

The default options used when constructing an alias.
Source:

Methods

(static) create() → {Alias}

Create a bot alias (see Alias for parameters).
Source:
Returns:
Type:
Alias
The new alias.

composeMessage() → {Object}

Compose a Slack message which includes the username and icon properties for this alias.
Source:
Returns:
Type:
Object
The composed Slack message.