Git Product home page Git Product logo

musicalchair's Introduction

MusicalChair Slack bot ๐ŸŽต๐Ÿช‘

Selects a random user in a channel and asks them for their song of the day

MusicalChair avatar, created with MidJourney

OAuth Scopes

Scope Purpose
chat:write To post the message
channels:read To get a list of all members

Environment Variables

Name Necessity Default Description
SLACK_BOT_TOKEN Required Token provided on bot creation, begins with xoxb-
SLACK_CHANNEL_ID Required Channel ID that the bot asks the question in and gets list of users from.
SLACK_SIGNING_SECRET Required Slack bot signing secret used to authenticate requests from Slack.

Local Dev

Prerequisites

  • A slack workspace to which you can add a bot and edit its permissions, create one if needed, adding the OAuth scopes listed above.
  • Docker - the app is containerised and the development environment uses docker compose
  • ngrok, used to forward an https URL to your local machine, needed to test slack events and actions *. Use ngrok to forward traffic to your local machine, copy the URL. ngrok http 8000
  • Set up your slack app by going to the app home under Slack Apps
    • Under Features > Interactivity & Shortcuts, enable and configure the URL to {ngrok_url}/slack/actions
    • Under Features > Event Subscriptions, enable and configure the URL to {ngrok_url}/slack/events
      • Subscribe to the following events: app_home_opened, app_mention and message.channels
  • Additional to the required standard environment variables, add these to your .env file:
Name Description
DEPLOYMENT_ENV Set to Local to enable local development mocking
LOCAL_URL Set to the https URL obtained from ngrok

Local dev loop

  1. Start the docker compose application (in older docker versions, docker-compose needed to be downloaded separately)
docker compose up -d --build && docker compose logs -f
  1. Make changes to the code to auto-restart the process inside the contianer.

musicalchair's People

Contributors

mjmammoth avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

musicalchair's Issues

Store answers to daily questions

Create a daily question playlist

  • The first response with music from the user for that day will be added
  • Limited to same day answers only

Welcome DM on channel join

When a user joins a channel where MusicalChair daily question is active, the should be DM'd with the option to do whatever the opposite of the default setting is.

Opt-in or opt-out

OAuth on non-slack endpoints

Endpoints that aren't authenticated by Slack's signing secret methodology need to be authenticated by OAuth.

These endpoints (/ask-for-song, /backfill--playlists) are currently available publicly and could be abused with the lack of authentication currently on them.

Should figure out what the interaction with Slack's OAuth is like as well as that is required to distribute the app eventually.

Admin configure section

Need a way to configure which channels are included

  • CHANNEL_ID should not be an environment variable

  • firestore state document should hold which channels have what functionality

  • Scheduled questions days and time of day should be configurable, will need to revisit the cron functionality to see how it can be made dynamic

  • Handle timezone as well

  • #25

  • Daily question channel(s)

  • Music scan channel(s), enabling auto reaction to music posts

  • Daily question missed questions

    • enabled/disabled
    • answer timeframe
    • reminders

Create playlists

Create different playlists using the metadata saved with the media - dependent on #18

  • Genre playlists
  • Everything playlist
  • All playlists linked by users

Could be future conceptual playlists:

  • Friday playlists

  • Seasonal playlists

  • Geography playlists

  • Convert platform playlists to other

  • Playlists should be created in both Spotify and Youtube.

  • Interaction with the bot should be possible to get the playlists, probably a slash command.

Dynamic cron schedules

To enable app admins to set their own scheduled time for the message, we need to be able to dynamically set the cron schedule.

Could continue to use cloud scheduler.. will need to figure how the post can be multi-tenanted

Exclude other bot users from the pool

Currently, the random member from the channel chosen can be another slack bot which is undesirable.

When MusicalChair is added to a channel, it should scan for bot users using the users_info method of the slack_bolt sdk and add those bot users to the permanent exclusions state. This would also require for new members added to the channel to be acted upon, checking if it is a bot or not.

This should help achieve the desired outcome:

non_bot_members = [member for member in members if not client.users_info(user=member)["user"]["is_bot"]]

Make opting in and out use a set

It is currently possible for users to click opt-in or opt-out multiple times before the ack response comes back, and for each time clicked - the user gets added/excluded an extra time.

Add track metadata

Pull media artist, name, genres.

Will have to cater for (plan a way forward for)

  • Individual song links

  • Full album links

  • Playlist links

  • Artist/channel links
    As both Spotify and Youtube support this functionality, even if we only want individual songs, the rest need to be filtered out.

  • Get the 'other' platform's URL for the same song.

Store data in the Firestore song collection, each posted link being a media item.

Might warrant the collection being called a 'media' collection as we could add a link_type to it too. (track/album/playlist/artist)

Possible structure, expansion of what's already in src/features/playlist_handler.py:

media_data = {
        "link_type": "track",
        "original_source": "youtube" if "youtube" in url else "spotify",
        "youtube_url": url if "youtube" in url else "",
        "spotify_url": url if "spotify" in url else "",
        "metadata": {
            "genre": [],
            "artist": "",
            "song_name": "",
            "album": ""
        },
        "posts": [
            {
                "date": event.get('ts', ''),
                "user_id": event.get('user', '')
            }
        ]
    }

app_home_opened initial functionality

A meaningful home page when the user visits the app.

Messages like:

  • You are currently in the rotation pool and are 7% likely to be chosen next
  • You are not currently in the rotation pool, you can always opt-back in.

Functionality required:

  • opt-in/opt-out
    Just add to permanent exclusions if opted out, if user is not in exclusions, they are in the pool.

Act on new users joining

In conjunction with #26, when a legitimate new user joins a channel, show them the status of if they are in the question pool or not and give them the option to opt-in/out

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update dependency python-multipart to v0.0.9

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

docker-compose
docker-compose.yaml
dockerfile
Dockerfile
  • python 3.11-slim
pip_requirements
src/requirements.txt
  • aiohttp ==3.8.4
  • fastapi ==0.95.0
  • google-api-python-client ==2.84.0
  • google-cloud-firestore ==2.11.0
  • google-cloud-run ==0.7.1
  • google-cloud-storage ==2.8.0
  • Jinja2 ==3.1.2
  • python-multipart ==0.0.6
  • slack-bolt ==1.17.0
  • uvicorn ==0.21.1
terraform
terraform/main.tf

  • Check this box to trigger a request for Renovate to run again on this repository

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.