serverless/serverless-slackbot

Name: serverless-slackbot

Owner: Serverless

Description: [Deprecated] A Serverless Module to create your own SlackBot without servers/websockets via Slash Commands

Created: 2015-12-17 20:13:07.0

Updated: 2018-05-14 05:44:44.0

Pushed: 2016-01-29 17:01:04.0

Homepage:

Size: 41

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Serverless Slack Bot AWS Lambda API Gateway

serverless-slackbot

Under Construction

This does not work with the most recent version of the Serverless Framework. We will be refactoring this as an open Serverless Project within the next week.

Description

A Serverless Module for the Serverless Framework featuring a SlackBot you can easily add skills to and package as a Slack Application, ready for distribution. All without servers!

We love Slack and their RTM (websockets) API is cool but we want to build dirt-cheap bots that don't require maintaining and paying for servers (we're Serverless!). So, we built a powerful SlackBot that runs exclusively on AWS Lambda, API Gateway & DynamoDB. Plus, you can easily add skills to it and it's ready to be distributed as a Slack Application, used by multiple Slack teams :)

Features Downsides
How It Works

After you register a Slack Application, register a single Slack SlashCommand for it, and name the SlashCommand after your bot's name. This SlashCommand and the words included after it are what instruct the bot.

For example, if you type this in Slack: /charlie help. Slack will send the text to your Serverless-SlackBot, which is trained to listen for the words immediately after the SlashCommand, in this case: help.

A Skill is function that your Serverless-SlackBot performs based on the word(s) entered in the SlashCommand. A Skill can listen to only the first word, or the first two words, allowing you to include a verb. For example, /charlie send email can do one thing, while /charlie read email can do another thing.

Set-Up
Building Your Bot
Adding Skills

Every file in the module's skills folder is automatically loaded, so just add files in there to add skills. Reference the existing skills in the skills folder for examples, or simply copy them. After you add your new skills, deploy your changes with serverless function deploy and choose the incoming function. Your new skill should be available right away and you can try it out on Slack.

Adding Events

Your Serverless-SlackBot also features a neat event handler system. We're not entirely sure how this will grow. Currently, it only handles one event: what happens when authorization is completed.

Slack Teams Are Pre-Loaded

Every time a SlashCommand sends a request to your Serverless-SlackBot, the Slack Team sending the request is loaded from DynamoDB. Their access token is then used to instantiate a Slack SDK (read more on this below) and their team data is submitted as a parameter in every Skills function. It's pretty convenient :)

Slack API Operations

The Serverless-SlackBot comes with slack-node npm module. Check out its README for information on how to use it. But it is pre-configured with the current Slack Team's access token and ready for use here:

kBot.Slack

You can use it like this:

kBot.Slack.api('users.list', function(error, response) {});

Here is the documentation on the Slack API methods. Make sure you have the right Slack Scope to use these!

Good luck, Serverless Team


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.