Sign inSign up

liatrio/lab-partner

By liatrio

•Updated almost 6 years ago

Slack bot for interactive automated workshop support

Image
0

1.1K

liatrio/lab-partner repository overview

⁠Lab-Partner

Slack bot for interactive automated workshop support

⁠Configuration

Environment Variables

  • CLIENT_SIGNING_SECRET: Slack app signing secret

    This value is generated when you create a Slack app. api.slack.com/app⁠ Basic Information -> App Credentials -> Signing Secret.

  • BOT_TOKEN: Slack app bot user OAuth token

    This value is generated when you create a Slack app. api.slack.com/app⁠ OAuth & Permissions -> Tokens for Your Workspace -> Bot User OAuth Access Token.

  • TEAM: Slack workspace ID

  • MONGO_URI: URL of Mongo DB server.

  • SCRIPT: Relative path to Script folder.

⁠Kubernetes Secret Configuration
If you're deploying to kubernetes this application has a helm chart which includes a secret named `lab-partner`. You'll need to set the three following strings in the values.yaml for this secret to be populated.
secrets:
  slackSigningSecret: ""
  slackBotUserOauthAccessToken: ""
  teamId: ""

⁠Scripts

Scripts represent the customized functionality for a specific workshop or lab. They tell the bot how to respond to user input or other events, how to track participant progress, etc. A Script is simply a folder with BotKit features. Each feature is a JavaScript modules which return a function which takes the BotKit controller as an argument.

module.exports = function (controller) {
  // Code to extend bot functionality goes here :)
}

There is a sample Script in the sample-script⁠ folder.

To use a Script the SCRIPT environment variable must be set to a relative path to the Script folder.

⁠Plugins

⁠Help

Provides access to the build in help message.

help.addCommand(command, name, description)

Adds a command to the built in help message. Should be used by Script features to document additional commands available to the participant.

  • command: sample message that will trigger the feature
  • name: name of the feature
  • description: description of what the feature does
module.exports = async (controller) => {

  controller.plugins.help.addCommand("@lab-partner awesome feature", "Awesome Feature", "This feature is so awesome!");

  controller.hears("awesome feature", "mention", (bot, message) => {
    bot.reply(message, "This feature is awesome!");
  }
}

help.getMessage()

Returns a Slack message to display a help message with available commands. The message is returned as an object with a list of Slack block kit⁠ blocks.

module.exports = async (controller) => {

  controller.hears("foo", "mention", (bot, message) => {
    const helpMessage = controller.plugins.help.getMessage();

    bot.reply(message, {
      blocks: [
        {
          type: "section",
          text: {
            type: "mrkdwn",
            test: "I don't know what you mean by \"foo\". Try one of these commands..."
          },
        },
        ...helpMessage.blocks,
      ],
    });
  }
}
⁠Slack helper

slack.whoAmI()

Fetches Slack user info⁠ for the bot.

module.exports = async (controller) => {

  let botUser;
  try {
    botUser = await controller.slack.whoAmi();
  } catch (error) {
    console.error(`Failed to fetch bot user info: ${error}`);
    return;
  }
  console.log(`Bot user name is ${botUser.real_name}.`);
}

slack.getUserInfo(id)

Fetches Slack user info⁠ for a user.

  • id: Slack user id
module.exports = async (controller) => {

  controller.hears("what is my status", "message", (bot, message) => {
    
    const userInfo = controller.plugins.slack.getUserInfo(message.user);

    bot.reply(message, {
      blocks: [
        {
          type: "section",
          text: {
            type: "mrkdwn",
            test: `Your status is ${userInfo.profile.status_emoji}: ${userInfo.profile.status_text}`,
          },
        },
        ...helpMessage.blocks,
      ],
    });
  }
}

Tag summary

Content type

Image

Digest

Size

89.6 MB

Last updated

almost 6 years ago

docker pull liatrio/lab-partner