• Stars
    star
    135
  • Rank 269,297 (Top 6 %)
  • Language
    JavaScript
  • Created almost 9 years ago
  • Updated almost 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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

  • Quick set-up
  • Easily add skills
  • No monthly server costs
  • Infinitely scalable (thanks to AWS Lambda and DynamoDB)
  • Pay only when your bot is called (thanks to AWS Lambda, again)
  • Do most of what you can do with Slack's RTM (websockets) API
  • Packaged as a Slack App ready for distribution
  • Saves Slack Teams separately in DynamoDB. Ready to be used by millions of Slack Teams
  • Multi-stage support (development, production) (thanks to the Serverless Framework)
  • Slack API is pre-configured. Your bot can do all types of neat Slack functions out-of-the-box (e.g., search messages, list users, etc.).

Downsides

  • Some features that come with websockets/Slack's RTM API aren't available on this architecture (AWS has no websockets service), like listening to events and not having to use SlashCommands exclusively. However, we've done a lot to recreate these features. If you're clever with the Slack API, you will be able to recreate more of these ;)

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

  • Open a Serverless Project, or create a new one with:
$ serverless project create
  • Inside your project, run
$ serverless module install https://github.com/serverless/serverless-slackbot
  • Deploy the module's required resources on AWS with:
$ serverless resources deploy
  • Deploy the functions and endpoints with:
$ serverless dash deploy
  • Make note of the endpoints that was returned to you. You'll use them to set up the Slack app in the next step

  • Register a Slack Application

  • Add the GET endpoint that was returned to you in the previous step to the "Redirect URI" field

  • Register one SlashCommand for your application. We recommend it being the name of your bot (e.g., Charles). For the SlashCommand endpoint, add the POST endpoint that was returned to you in the previous step. Make note of the "Verification Token" that Slack generated for your Slash Command. We use this token to validate that the POST request really is coming from Slack.

  • Copy the "Client ID", "Client Secret" and "Verification Token" you created with your application and Set the following environment variables in your Serverless Project. Use $ serverless env set and $ serverless env list

    • SLACK_OAUTH_CLIENT_ID
    • SLACK_OAUTH_CLIENT_SECRET
    • SLACK_TOKEN
    • SERVERLESS_PROJECT_NAME
  • deploy the functions again with serverless function deploy to update the env vars.

  • Make an Add to Slack button and also make sure you add the correct Slack Scopes that your bot will require. Here is a good starter template with some popular scopes:

https://slack.com/oauth/authorize?scope=incoming-webhook+commands+bot+team%3Aread+users%3Aread+chat%3Awrite%3Abot+emoji%3Aread+reactions%3Awrite&client_id=YOURSLACKCLIENTIDGOESHERE
  • Authorize and test your new Slack application by visiting the previous authorization url. After you authorize, you should be notified of the success of the authorization in your Slack team. try /<your-slash-command> help and make sure everything is working great.

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:

SlackBot.Slack

You can use it like this:

SlackBot.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

More Repositories

1

serverless

⚡ Serverless Framework – Use AWS Lambda and other managed cloud services to build apps that auto-scale, cost nothing when idle, and boast radically low maintenance.
JavaScript
46,101
star
2

examples

Serverless Examples – A collection of boilerplates and examples of serverless architectures built with the Serverless Framework on AWS Lambda, Microsoft Azure, Google Cloud Functions, and more.
JavaScript
11,353
star
3

serverless-graphql

Serverless GraphQL Examples for AWS AppSync and Apollo
JavaScript
2,720
star
4

components

The Serverless Framework's new infrastructure provisioning technology — Build, compose, & deploy serverless apps in seconds...
JavaScript
2,306
star
5

event-gateway

React to any event with serverless functions across clouds
Go
1,647
star
6

serverless-python-requirements

⚡️🐍📦 Serverless plugin to bundle Python packages
JavaScript
1,108
star
7

plugins

Serverless Plugins – Extend the Serverless Framework with these community driven plugins –
JavaScript
970
star
8

aws-ai-stack

AWS AI Stack – A ready-to-use, full-stack boilerplate project for building serverless AI applications on AWS
JavaScript
911
star
9

serverless-graphql-blog

A Serverless Blog leveraging GraphQL to offer a REST API with only 1 endpoint using Serverless v0.5
JavaScript
793
star
10

serverless-plugin-typescript

Serverless plugin for zero-config Typescript support
TypeScript
776
star
11

github-action

⚡:octocat: A Github Action for deploying with the Serverless Framework
Dockerfile
642
star
12

scope

🔭 Scope - Create a birdeye's view of your Github project and embed on your site
JavaScript
456
star
13

guide

Serverless Guide - An open-source definitive guide to serverless architectures.
Shell
439
star
14

serverless-kubeless

This plugin enables support for Kubeless within the Serverless Framework.
JavaScript
302
star
15

serverless-google-cloudfunctions

Serverless Google Cloud Functions Plugin – Adds Google Cloud Functions support to the Serverless Framework
JavaScript
272
star
16

serverless-azure-functions

Serverless Azure Functions Plugin – Add Azure Functions support to the Serverless Framework
TypeScript
266
star
17

post-scheduler

Schedule posts & content updates for static websites (Jekyll, Hugo, Gatsby, Phenomic etc)
JavaScript
191
star
18

serverless-starter

A boilerplate for new Serverless Projects
JavaScript
190
star
19

blog

serverless.com/blog – Posts from the Serverless community & core team. Contributions welcome!
JavaScript
183
star
20

serverless-client-s3

A plugin to deploy front-end assets to S3 via the Serverless Framework
JavaScript
171
star
21

serverless-websockets-plugin

Websocket support for Serverless Framework on AWS
JavaScript
149
star
22

serverless-openwhisk

Adds Apache OpenWhisk support to the Serverless Framework!
JavaScript
143
star
23

typescript

TypeScript definitions for Serverless Framework service configuration
TypeScript
140
star
24

cloud

Serverless Cloud makes building, deploying, and managing serverless applications easier and more accessible to everyone.
HTML
112
star
25

compose

Orchestrate Serverless Framework in monorepos
JavaScript
109
star
26

event-gateway-example

JavaScript
104
star
27

serverless-optimizer-plugin

Serverless Optimizer Plugin: Optimizers for reducing Lambda file sizes and improving their performance -
JavaScript
102
star
28

enterprise

Documentation for the Serverless Framework Enterprise Edition –
95
star
29

multicloud

The serverless @multicloud library provides an easy way to write your serverless handlers 1 time and deploy them to multiple cloud providers include Azure & AWS.
TypeScript
90
star
30

aws-event-mocks

JavaScript
83
star
31

emulator

Serverless Emulator which lets you run serverless functions locally
JavaScript
78
star
32

serverless-local-schedule

⚡️🗺️⏰ Schedule AWS CloudWatch Event based invocations in local time(with DST support!)
JavaScript
72
star
33

event-mocks

TypeScript
72
star
34

fdk

This library is deprecated. Please use https://github.com/serverless/event-gateway-sdk instead.
JavaScript
69
star
35

serverless-open-runtime

WIP - An extensible, community-driven, open-runtime for serverless compute
Go
68
star
36

serverless-runtime-babel

Babel runtime for v.0.5 of the Serverless Framework
JavaScript
68
star
37

forms-service

Serverless Forms Service to collect form data with Admin UI
JavaScript
66
star
38

serverless-secrets-plugin

JavaScript
66
star
39

serverless-golang

Serverless Template for Golang
Go
64
star
40

serverless-tencent

⚡️ 🐧 Serverless Tencent CLI 及中文讨论社区
JavaScript
63
star
41

serverless-slack

A Serverless Module featuring pre-written Slack functions from authorization to slash commands!
JavaScript
49
star
42

dashboard-plugin

The Serverless Framework Dashboard plugin
JavaScript
49
star
43

event-gateway-getting-started

Walkthrough application for using the Event Gateway. -- https://www.serverless.com
JavaScript
48
star
44

workshop

A complete full-stack application and walkthrough for learning the features of the Serverless Framework.
CSS
45
star
45

desktop

A native GUI application that makes it easy to explore and test Serverless Framework applications built on AWS Lambda.
45
star
46

serverless-swagger-plugin

JavaScript
44
star
47

serverless-meta-sync

Secure syncing of serverless project meta data across teams
JavaScript
44
star
48

event-gateway-sdk

Event Gateway JavaScript SDK
JavaScript
43
star
49

safeguards-plugin

Serverless Framework Plugin to enforce safeguard policies
JavaScript
33
star
50

serverless-graphql-relay

Serverless GraphQL Boilerplate using Relay – Ready to be deployed to production within minutes …
JavaScript
32
star
51

utils

General serverless utilities
JavaScript
29
star
52

serverless-event-gateway-plugin

Event Gateway plugin for Serverless Framework
JavaScript
28
star
53

eslint-config

Common ESLint & Prettier config for Serverless projects
JavaScript
27
star
54

serverless-knative

Serverless Knative Provider Plugin – Adds Knative to the Serverless Framework
JavaScript
25
star
55

serverless-plugin-boilerplate

A Starter Project to help you build Plugins for the Serverless Framework -
JavaScript
24
star
56

dashboard

JavaScript
24
star
57

fullstack-course

The entire fullstack application course as seen on serverless.com/learn
JavaScript
24
star
58

serverless-babel-plugin

A Serverless plugin to compile your JavaScript code with Babel before deployment
JavaScript
23
star
59

serverless-plugin-log-retention

Control the retention of your serverless function's cloudwatch logs.
JavaScript
20
star
60

cloud-computing-conferences

A curated list of all the best cloud computing conferences happening in 2019! Check here to find a serverless or cloud event happening near you.
18
star
61

event-gateway-workshop

Learn what the Event Gateway is, how it works and build your first event-driven multi-cloud application!
JavaScript
18
star
62

fdk-tmp

The Serverless Function Development Kit (FDK)
JavaScript
18
star
63

aws-sdk-extra

The AWS SDK + a handful of extra convenience methods.
JavaScript
18
star
64

platform-sdk

Serverless Platform SDK
JavaScript
17
star
65

meetups

Want to start a Serverless usergroup? We can help you get started and be an official Serverless Usergroup. Join us to be part of the family of many Serverless Usergroups across the world.
17
star
66

boilerplate-googlecloudfunctions-nodejs

A Serverless Framework Boilerplate for Google Cloud Functions support in Node.js
JavaScript
15
star
67

cli

Serverless Components CLI
JavaScript
14
star
68

serverless-helpers-py

Python
12
star
69

tutorial

A tutorial repo with multiple projects designed to help teach users
JavaScript
11
star
70

serverless-helpers-js

Serverless Helpers Node.Js: An NPM module that provides helper functions for Serverless Modules written in Node.js -
JavaScript
11
star
71

template

Compose & provision a collection of Serverless Components
JavaScript
10
star
72

template-package

Repository template for serverless packages
JavaScript
9
star
73

serverlessconf-workshop

JavaScript
9
star
74

serverless-search-engine

Part of the Serverless Live series where we build a very simplistic search engine and spider
JavaScript
9
star
75

artwork

Official design elements of Serverless Inc. and its projects
8
star
76

extensions

Use / make / monetize developer experiences.
JavaScript
8
star
77

event-gateway-connector

Serverless Event Gateway Connector Framework
Go
7
star
78

raffleapp

A serverless raffle app
JavaScript
7
star
79

netlify-landing-page

Components Landing page demo
CSS
7
star
80

compose-example

JavaScript
6
star
81

demo-todo

An example serverless-todo app
JavaScript
5
star
82

serverless-raffle

JavaScript
5
star
83

enterprise-template

JavaScript
5
star
84

workshops

Companion repo for workshops with instructions and code examples
JavaScript
5
star
85

sls-action

GitHub action for Serverless CLI
TypeScript
5
star
86

test

Test setup and utilities for serverless projects
JavaScript
4
star
87

compose-website-example

JavaScript
4
star
88

console

4
star
89

cli-design

Repository to discuss Serverless Framework v3 redesign
HTML
4
star
90

event-gateway-tracer

JavaScript
3
star
91

core

Serverless Components Core
JavaScript
3
star
92

status

The Serverless Status Page
JavaScript
3
star
93

partner-examples

JavaScript
2
star
94

components-core

WIP
TypeScript
2
star
95

azure-build-task

A Serverless build task for Azure Dev Ops
TypeScript
1
star
96

sfe-nodejs-service

JavaScript
1
star
97

inquirer

inquirer with enforced serverless theme
JavaScript
1
star
98

template-getting-started-node-js

Application templates used by the Serverless Platform
1
star
99

serverless-cloud-gitpod

Starter repository for running Serverless Cloud on GitPod
1
star
100

user-testing

Tests of product concepts
JavaScript
1
star