1.6.0 β€’ Published 4 years ago

pockybot v1.6.0

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

Pockybot πŸ“πŸ‘πŸ†πŸ€–

ARCHIVED

The pockybot project has been superseded by PockyBot.Net. Please visit that project instead.

Webex bot that handles team recognition. A chatbot for pegs & pocky.

What is Pegs & Pocky?

Pegs & Pocky was created within GlobalX as a merit-based system to encourage good behaviour and to continuously improve within our complex environment, so people are motivated to reach their full potential. It started out as a physical system of pegs and cups on everyone’s desk, however as our development team expanded interstate we needed an electronic system to include everyone. Here's how it works:

  1. Participating members acknowledge good work by giving virtual "pegs" to other members within a specified time period.
    • Each member has a maximum number of pegs they can give out within that time period.
    • If they do not give at least a minimum number of pegs then they are not eligible for winning.
  2. At the end of the time period the pegs are counted (an admin calls "finish" on the bot) and the winners are announced in the chat.
  3. The top three peg recipients get physical rewards (Pocky and/or other snacks).

How it works

  • Library used to set up a Webex Teams Bot
  • Results are stored in a postgres database
  • Pegs are viewable via html uploaded to google cloud

Setup

Using npm:

npm i pockybot

Using yarn:

yarn add pockybot

Usage

Environment Variables

The following environment variables must be set so that PockyBot can run properly:

Variable NamePurposeExample Value
BUILD_NUMBERAllows PockyBot to display the build number that is running when you ping it102
VERSION_BRANCHAllows PockyBot to display the version of the app that is running when you ping it1.0.0
WEBEX_ACCESS_TOKENUsed so that the app can connect and post to Webex Teams as the BotDFsSdfsdFhgiFg
BOT_IDUsed to filter the webhooks so that the Bot only responds to messages where it has been mentionedY2lzY29zcGFyadsdfEREr
BOT_NAMEUsed to provide a human-readable name for the Bot and to name the webhooksPockyBot
POST_URLThe url that the webhook will hit when a message that mentions the bot is createdhttps://example.com/pocky/respond
PM_URLThe url that the webhook will hit when a private message is sent to the bothttps://example.com/pocky/pm
PGUSERThe username of the database user set up for the botpockybotuser
PGPASSWORDThe password used to connect to the databasepassword
PGHOSTThe url of the database for the bot informationpostgres.example.com
PGDATABASEThe name of the databasepockydatabase
PGPORTThe port of the database5432
GCLOUD_PROJECT_IDThe ID of the gcloud project where the bucket used to store results information is foundproject-123
GCLOUD_PRIVATE_KEY_IDThe ID of the gcloud private keya23c87b7127ab7d2
GCLOUD_PRIVATE_KEYThe private key required to connect to the gcloud bucket-----BEGIN PRIVATE KEY-----\nMItestingtestingtesting23423\n-----END PRIVATE KEY-----\n
GCLOUD_CLIENT_EMAILRequired to connect to the gcloud bucketpockybot@project-123.iam.gserviceaccount.com
GCLOUD_CLIENT_IDRequired to connect to the gcloud bucket382348239123
GCLOUD_CLIENT_CERT_URLRequired to connect to the gcloud buckethttps://www.googleapis.com/robot-/v1/metadata/x509/pockybot%40project-123.iam.gserviceaccount.com
GCLOUD_BUCKET_NAMEThe name of the gcloud bucket being used to store the pockybot resultspockybucket

Code

The following is example code showing usage of the bot with express in a typescript project:

import * as express from 'express';
import * as bodyParser from 'body-parser';
import { PockyBot } from 'pockybot';

// Constants
const PORT = 80;
const HOST = '0.0.0.0';

//Startup - note environment variables should already be set up when this is run
PockyBot.RegisterHooks();

// App
const app = express();
app.use(bodyParser.json()); // for parsing application/json

app.post('/respond', async (req, res) => {
    try {
        await PockyBot.Respond(req.body);
        res.status(200).end();
    } catch (e) {
        res.status(400).end();
    }
});

app.post('/pm', async (req, res) => {
    try {
        await PockyBot.PmRespond(req.body);
        res.status(200).end();
    } catch (e) {
        res.status(400).end();
    }
});

app.listen(PORT, HOST);

Database

database/initial-setup includes a number of .sql files to build the database as required by PockyBot.

Table generalconfig is initialised with default values as follows:

ValueDefaultExplanation
limit10The number of pegs each user is allowed to give out each cycle
minimum5The minimum number of pegs each user is required to give out to be eligible to win
winners3The number of winners displayed (using a dense ranking)
commentsRequired1Boolean value of whether a reason is required to give a peg
pegWithoutKeyword0Boolean value of whether the "peg" keyword is required to give a peg (if true, pegs can be given with @PockyBot @Person <reason>)
requireValues1Boolean value of whether a keyword is required in the reason for a peg to be given

Table stringconfig is used to define keywords. Name field is 'keyword' and 'value' is the value of the keyword desired. Default keywords are 'customer', 'brave', 'awesome', 'collaborative', and 'real', shorthands for the GlobalX company values.

Existing roles are 'ADMIN', 'UNMETERED', 'RESULTS', 'FINISH', 'RESET', 'UPDATE', and 'WINNERS'. Users can have more than one role. Any users with the 'ADMIN' role are considered to have all other roles except for 'UNMETERED'. 'UNMETERED' users are not restricted by the usual 'limit' value from generalconfig. All other roles relate to the commands of the same name displayed below.

Commands

All commands related to PockyBot must begin with a mention of the bot, or be sent directly to the bot. In this readme, mentions will be identified by @PockyBot.

General commands

Use any of these commands in a room PockyBot is participating in to perform commands.

  • @PockyBot status β€” get a list of pegs you have given this cycle.
  • @PockyBot welcome β€” display a welcome message.
  • @PockyBot ping β€” verify that the bot is alive.
  • @PockyBot help β€” display a list of available commands.
  • @PockyBot peg|to|at|for @OtherPerson <reason> β€” give a peg to @OtherPerson for <reason>.
    • If comments are required, a reason must be given. Otherwise, reasons are optional.
    • <reason> must include a keyword anywhere within it if keywords are required.
  • @PockyBot keywords β€” display the available keywords.
  • @PockyBot rotation β€” display the rotation of the order in which teams are responsible for buying snacks. This can be configured by adding a stringconfig with the name "rotation" and the value corresponding to a list of comma separated team names.
  • @PockyBot unpeg @OtherPerson <reason> β€” pretend to remove a peg from @OtherPerson.
    • Use @PockyBot unpeg <concept> for <reason> to unpeg abstract concepts that can't be tagged.
  • @PockyBot locationconfig get β€” get the list of available locations.
  • @PockyBot userlocation β€” configure user locations (details below). Note that normal users may not configure locations for people other than themselves, but admins can access the full functionality of this command.
    • @PockyBot userlocation get me|all|unset|@User β€” get a user's location
    • @PockyBot userlocation set {location} me β€” set your location
    • @PockyBot userlocation delete me β€” delete your location
Direct message commands

PockyBot can be messaged directly with certain commands.

  • status β€” get a list of pegs you have given this cycle.
  • welcome β€” display a welcome message.
  • ping β€” verify that the bot is alive.
  • help β€” display a list of available commands.
  • keywords β€” display the available keywords.
  • rotation β€” display the rotation (see above).

Admin-only commands

These commands can only be performed by users with the role of 'ADMIN' or users with a role corresponding to the name of the given command.

  • @PockyBot winners β€” display the current winners
  • @PockyBot results β€” display the current full results
  • @PockyBot reset β€” remove all pegs from the database
  • @PockyBot update β€” update names stored in the database with users' current display names
  • @PockyBot finish β€” complete the cycle by displaying the winners and results before wiping the database
  • @PockyBot numberconfig get|set|refresh|delete {name} {number} β€” get or change config values
  • @PockyBot stringconfig get|set|refresh|delete {name} {value} β€” get or change string config values
  • @PockyBot roleconfig get|set|refresh|delete {@User} {role} β€” get or change user roles
  • @PockyBot locationconfig get|set|delete {location} β€” get or change locations
  • @PockyBot removeuser @User|username β€” remove a user
  • @PockyBot userlocation β€” configure user locations as an admin (details below).
    • @PockyBot userlocation get me|all|unset|@User β€” get a user's location
    • @PockyBot userlocation set {location} me|@User1 @User2 β€” set one or more users' locations
    • @PockyBot userlocation delete me|@User1 @User2 β€” delete one or more users' locations
  • @PockyBot locationweight get|set|delete {location1} {location2} {number} β€” get or change location weight configs

Contributing

For notes on how to contribute, please see our Contribution Guidelines.

Testing

  1. npm install
  2. npm test
1.6.0

4 years ago

1.5.30

4 years ago

1.5.29

4 years ago

1.5.28

4 years ago

1.5.27

4 years ago

1.5.26

4 years ago

1.5.25

4 years ago

1.5.24

4 years ago

1.5.23

4 years ago

1.5.22

4 years ago

1.5.21

4 years ago

1.5.20

4 years ago

1.5.19

4 years ago

1.5.18

4 years ago

1.5.17

4 years ago

1.5.16

4 years ago

1.5.15

4 years ago

1.5.14

4 years ago

1.5.13

4 years ago

1.5.12

4 years ago

1.5.11

4 years ago

1.5.10

4 years ago

1.5.9

4 years ago

1.5.8

4 years ago

1.5.7

5 years ago

1.5.6

5 years ago

1.5.5

5 years ago

1.5.4

5 years ago

1.5.3

5 years ago

1.5.2

5 years ago

1.5.1

5 years ago

1.5.0

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.2

5 years ago

1.4.0-preview3

5 years ago

1.4.0-preview2

5 years ago

1.4.0-preview

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.4-preview

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.1.0-preview4

5 years ago

1.1.0-preview3

5 years ago

1.1.0-preview2

5 years ago

1.1.0-preview

5 years ago

1.0.1

5 years ago

1.0.0-preview2

5 years ago

1.0.0-preview

5 years ago

1.0.0

5 years ago

2.0.0-preview2

5 years ago

2.0.0-preview

5 years ago

1.7.1-preview3

5 years ago

1.7.1-preview2

5 years ago

1.7.1-preview

5 years ago