Giter VIP home page Giter VIP logo

stanley's Introduction

Stanley

Stanley

A secret Santa Slack bot for positive feedback.

Setting up the bot

Just click the button, duh!

Deploy

You must configure on Heroku Scheduler how often Stanley will ask for feedback. Our team is asking feedback on Mondays, Wednesdays, and Fridays. It doesn't mean that all team members will be asked three times a week. Instead, Stanley will choose a sender and a receiver each day randomly.

Setting up Slack

https://api.slack.com/ -> 'Start Building'

1. Add Bot

In the section 'Add features and functionality' select Bots and fill the form

2. Permissions

In the section 'Add features and functionality' select Permissions

In the Scope add

  • bot
  • chat:write:bot
  • team:read

3. Event Subscriptions

In the section 'Add features and functionality' select Event Subscriptions

you have to set the deployed app url into 'Requests URL' and verify

Next 'Subscribe to Bot Events' add 'message.im'

Now go to your app and have fun!

4. Install your app to your workspace

Until this moment you have a bot configure but not installed in your workspace yet. To do it and have access to Slack API credentials, click on Install your app to your workspace.

5. Set environment variables on Stanley

  • SLACK_VERIFICATION_TOKEN: Still on Slack, click on Basic Information and in the section App Credentials copy Verification Token.

  • SLACK_API_TOKEN: in the section Install App, copy it from Bot User OAuth Access Token.

The variables SLACK_API_TOKEN and SLACK_VERIFICATION_TOKEN are required. Other environment variables that are optional:

  • FEEDBACK_MEMBERS: Stanley will use all members if you don't fill it in. You can get the users and their ids using Request team members command

  • REDIS_URL: default is redis://127.0.0.1:6379/0

  • SENTRY_DSN: for Sentry integration purposes

Helpful management commands

Request team members

To be able to see team members internal usernames (used in FEEDBACK_MEMBERS variable), you can run

FLASK_APP=stanley/app.py flask team-command

It will give you the list of Slack team members with their IDs.

Request a feedback

To ask for a feedback, just run

FLASK_APP=stanley/app.py flask request-feedback-command

This will ask a random person to provide a feedback to another random person.

Example of our command (that will run on Mondays, Wednesdays, and Fridays):

if [ "$(date +%u)" = 1 ] || [ "$(date +%u)" = 3 ] || [ "$(date +%u)" = 5 ];
then FLASK_APP=stanley/app.py flask request-feedback-command;
fi

stanley's People

Contributors

amureki avatar anapaulagomes avatar codingjoe avatar dependabot-preview[bot] avatar dependabot[bot] avatar pyup-bot avatar sebastiankapunkt avatar studentofcod3 avatar syphar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

z10mx7 5udu3r

stanley's Issues

Sentry is not catching errors

ERROR:sentry.errors.uncaught:["SlackApiError: The request to the Slack API failed.\nThe server responded with: {'ok': False, 'error': 'channel_not_found'}"

Add tests

  1. Add tests
  2. Split up production/tests configuration
  3. Add Travis CI

slack.errors.SlackApiError: The request to the Slack API failed.Exception

15 Jan 2020 15:01:05.746128 <190>1 2020-01-15T14:01:04.811223+00:00 app web.1 - - Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.7/site-packages/flask/app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "/app/.heroku/python/lib/python3.7/site-packages/flask/app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/app/.heroku/python/lib/python3.7/site-packages/flask/app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/app/.heroku/python/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/app/.heroku/python/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "/app/.heroku/python/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request
return self.view_functionsrule.endpoint
File "/app/stanley/routes.py", line 44, in forward_feedback
send_slack_message('{}'.format(receiver), message=message)
File "/app/stanley/slack.py", line 22, in send_slack_message
as_user=True,
File "/app/.heroku/python/lib/python3.7/site-packages/slack/web/client.py", line 559, in chat_postMessage
return self.api_call("chat.postMessage", json=kwargs)
File "/app/.heroku/python/lib/python3.7/site-packages/slack/web/base_client.py", line 171, in api_call
return self._event_loop.run_until_complete(future)
File "/app/.heroku/python/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
return future.result()
File "/app/.heroku/python/lib/python3.7/site-packages/slack/web/base_client.py", line 226, in _send
return SlackResponse(**{**data, **res}).validate()
File "/app/.heroku/python/lib/python3.7/site-packages/slack/web/slack_response.py", line 176, in validate
raise e.SlackApiError(message=msg, response=self)
slack.errors.SlackApiError: The request to the Slack API failed.Exception

Add scheduler

The bot should ask for a feedback N times (configurable) per week. Only on weekdays.

The bot is throwing an error "The request to the Slack API failed"

04 Sep 2019 16:00:23.747128 <190>1 2019-09-04T14:00:22.768018+00:00 app web.1 - - Traceback (most recent call last):
  File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 2446, in wsgi_app
    response = self.full_dispatch_request()
  File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1951, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1820, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/app/.heroku/python/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1949, in full_dispatch_request
    rv = self.dispatch_request()
  File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1935, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/app/stanley/routes.py", line 43, in forward_feedback
    send_slack_message('{}'.format(receiver), message=message)
  File "/app/stanley/slack.py", line 19, in send_slack_message
    as_user=True,
  File "/app/.heroku/python/lib/python3.6/site-packages/slack/web/client.py", line 332, in chat_postMessage
    return self.api_call("chat.postMessage", json=kwargs)
  File "/app/.heroku/python/lib/python3.6/site-packages/slack/web/base_client.py", line 154, in api_call
    return self._event_loop.run_until_complete(future)
  File "/app/.heroku/python/lib/python3.6/asyncio/base_events.py", line 467, in run_until_complete
    return future.result()
  File "/app/.heroku/python/lib/python3.6/site-packages/slack/web/base_client.py", line 223, in _send
    return SlackResponse(**{**data, **res}).validate()
  File "/app/.heroku/python/lib/python3.6/site-packages/slack/web/slack_response.py", line 174, in validate
    raise e.SlackApiError(message=msg, response=self.data)
slack.errors.SlackApiError: The request to the Slack API failed.
04 Sep 2019 16:00:24.2161024 <190>1 2019-09-04T14:00:23.339671+00:00 app web.1 - - ERROR:sentry.errors.uncaught:["SlackApiError: The request to the Slack API failed.\nThe server responded with: {'ok': False, 'error': 'channel_not_found'}", ' File "flask/app.py", line 2446, in wsgi_app', ' File "flask/app.py", line 1951, in full_dispatch_request', ' File "flask/app.py", line 1820, in handle_user_exception', ' File "flask/_compat.py", line 39, in reraise', ' File "flask/app.py", line 1949, in full_dispatch_request', ' File "flask/app.py", line 1935, in dispatch_request', ' File "stanley/routes.py", line 43, in forward_feedback', ' File "stanley/slack.py", line 19, in send_slack_message', ' File "slack/web/client.py", line 332, in chat_postMessage', ' File "slack/web/base_client.py", line 154, in api_call', ' File "asyncio/base_events.py", line 467, in run_until_complete', ' File "slack/web/base_client.py", line 223, in _send', ' File "slack/web/slack_response.py", line 174, in validate']

Initial Update

The bot created this issue to inform you that pyup.io has been set up on this repo.
Once you have closed it, the bot will open pull requests for updates as soon as they are available.

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.