GithubHelp home page GithubHelp logo

trivial-slack-bot's Introduction

trivial-slack-bot

A Slack bot for tracking answers to true/false trivia questions. Designed for use with a Fact or Crap desk calendar available from calendars.com. Built with serverless technologies from AWS: Lambda, API Gateway, and DynamoDB.

Prerequistes

  1. A Slack account with permission to install apps
  2. An AWS account with permission to create resources
  3. An AWS CLI profile setup with AWS account credentials
  4. Node.js installed

Deployment

  1. Open a browser and navigate to https://api.slack.com/apps
  2. Click "Create New App".
  3. Enter the name "Trivial Bot"
  4. Slect a Slack workspace
  5. Click "Create App"
  6. In left panel, select "Bot Users"
  7. Click "Add a Bot User"
  8. Enter "trivial" for "Display name" and "Default username"
  9. Toggle on "Always Show My Bot as Online"
  10. Click "Add Bot User"
  11. In left panel, select "Install App"
  12. Click "Install App to Workspace"
  13. Review permissions and click "Allow"
  14. Record value of "Bot User OAuth Access Token"
  15. In left pannel, select "Basic Information"
  16. Under "App Credentials" click "Show" for "Signing Secret" and record value
  17. Open a shell and navigate to root of repo
  18. Run the command: npm install
  19. Run the command: npm run sls -- deploy --token <token> --signing-secret <secret> --profile <profile> --region <region> --stage <stage>
  20. Open a browser and navigate to AWS console
  21. Navgiate to API Gateway service
  22. Select API Gateway instance for bot
  23. In left panel, select "Stages" then bot's stage name
  24. Record "Invoke URL"
  25. Return to https://api.slack.com/apps and the newly created app
  26. In left panel, select "Event Subscriptions"
  27. Toggle on "Enable Events"
  28. Enter "<invoke-url>/event" for "Request URL"
  29. Expand "Subscribe to bot events"
  30. Click "Add Bot User Event"
  31. Select "app_mention" event
  32. Click "Save Changes"
  33. In left pannel, select "Slash Commands"
  34. Click "Create New Command"
  35. Enter "/trivial" for "Command"
  36. Enter "<invoke-url>/command" for "Request URL"
  37. Enter "Start or end a round of trivia" for "Short Description"
  38. Enter "[help] or [create] or [close]" for "Usage Hint"
  39. Click "Save"
  40. In left panel, select "Interactive Components"
  41. Toggle on "Interactivity"
  42. Enter "<invoke-url>/action" for "Request URL"
  43. Click "Save Changes"
  44. Test the bot by mentioning @trivial in Slack

Redployment

  1. Open a shell and navigate to root of repo
  2. Run the command: npm run sls -- deploy --token <token> --signing-secret <secret> --profile <profile> --region <region> --stage <stage>

Undeployment

  1. Open a shell and navigate to root of repo
  2. Run the command: npm run sls -- remove --token <token> --signing-secret <secret> --profile <profile> --region <region> --stage <stage>
  3. Open a broweser and nvaigate to https://api.slack.com/apps and the previously created app
  4. In left pannel, select "Basic Information"
  5. At the bottom, click "Delete App"

trivial-slack-bot's People

Contributors

jkehres avatar m6jones avatar

Watchers

 avatar  avatar

trivial-slack-bot's Issues

Handle private channels where the bot is not a member

Slack will let users invoke a slash command in a private channel where the bot is not a member. However, when the bot attempts to post a message to the channel it receives a channel_not_found error. Slash commands should perform a check that the bot is a member of the channel before executing to prevent this error.

Add CI

CI should run linter and unit tests for every PR and merge to master. Need to decide on Travis CI or CircleCI.

Catch exceptions thrown by Slack SDK

I would agree with this issue:

slackapi/node-slack-sdk#775

Error handling is not intuitive for the Slack SDK. The result object returned by an API call has an ok property, which indicates the API will never reject/throw and you need to check the result to determine the success. However, in practice the SDK will reject/throw. We are not currently handling this in the code. This is particularly bad in the stream lambda since we could stuck trying to process the same record forever when we hit a Slack API error that is permanent.

Improve usability of closing questions

Closing a trivia question is a multi-step process. You must type /trivial close. select the answer from a dropdown, and click the submit button on the dialog. Closing a question should require less typing and fewer steps.

One possible solution is to post an ephemeral message to the user that created the question. This message would only be visible to the question creator and would contain buttons that let them close/answer the question with a single click. The ephemeral message would be deleted once the question was closed.

Add unit tests

Tests should treat each lambda as a unit and minimize the amount of coupling to the implementation to make refactoring easier. We should use the following libraries for testing:

  • mocha - test framework/runner
  • chai - assertion library
  • lambda-tester - invoke lambda functions
  • sinon - mocking library for AWS SDK (i.e. DynamoDB)
  • nock - mocking library for HTTP calls to Slack

Add a slash command to show stats

The bot currently records answers for each question and displays the immediate correctness of those answers but has no way to show stats for users over time, across multiple questions. We should add a command like /trivial stats to post a leaderboard message to the channel it was invoked in. The command should take an optional argument for the desired month. If not specified, the current month is used. Stats spanning more than one month are out of scope for now. The leaderboard message should show rankings for the biggest winner (most correct) and biggest loser (most incorrect).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.