Python web application needed to utilize modal window inside slack to make posting backblasts easier for PAX.
Go to https://api.slack.com/start/overview#creating to read up on how to create a slack app. Click their Create a Slack app
while signed into your F3 region's Slack. The main idea is that you will set up a slashcommand, e.g. /slackblast
or /backblast
, that will send the request to your server that is running this web application (we recommend using a free Azure App Service) that will respond with a command to tell Slack to open up a modal with the fields to fill out a backblast post. When the user hits submit on the modal, the information will be sent to your server where it will then format it and post to the designated Slack channel!
Bonus: the post will be in a format friendly for Paxminer to mine and gather stats.
Bonus 2: the post can be emailed to automatically post to Wordpress
Go to https://azure.microsoft.com/en-us/services/app-service/ to create a Free Azure App Service to host this web application. The VSCode Azure Extensions will be helpful to upload your own .env file with your region's specific Slack and opinionated settings. See how to integrate your Azure App Service with Github for easy deployments.
When you finish setting up and installing the slackblast app in Slack, you will get a bot token also available under the OAuth & Permissions settings. You'll also get a verification token and signing secret on the Basic Information settings. You will plug that information into your own .env file. When you finish creating the Azure app, you will need to get the URL and add it (with /slack/events
added to it) into three locations within the slackblast app settings. Lastly, you will need to add several Scopes to the Bot Token Scopes on the OAth & Permissions settings. Read on for the nitty gritty details.
slackblast requires the following environment variables:
SLACK_BOT_TOKEN=<YOURTOKEN>
SLACK_VERIFICATION_TOKEN=<SLACKVERIFICATIONTOKEN>
SLACK_SIGNING_SECRET=<SLACKSIGNINGSECRET>
POST_TO_CHANNEL=<False or True>
CHANNEL=<USER or THE_AO or channel-id>
# EMAIL_OPTION_HIDDEN_IN_MODAL=<False or True>
EMAIL_TO=<[email protected]>
GMAIL_USER=<[email protected]>
GMAIL_PWD=<app-password>
set SLACK_BOT_TOKEN
from the token on the oath page in the slack app
set SLACK_VERIFICATION_TOKEN
from the Basic Information -> Verification Token field in the settings for your slack app.
set POST_TO_CHANNEL
equal to True
or False
. Set to true if you are using paxminer. Indicates whether or not to take the modal data and post to a channel in slack.
set CHANNEL=channel-id
to the channel id (ID such as C01DB7S04KH -> NOT THE NAME) you want the modal results to post to by default.
set CHANNEL=THE_AO
to post to the channel that was selected in the modal by default.
set CHANNEL=USER
to post a DM from the slackblast to you with the results (testing) by default.
if CHANNEL
is blank or missing, then the default channel will be the channel the user typed the slashcommand.
NOTE: In the modal, the user can choose the "destination" and where to post to.
NOTE: In the modal, the user can choose where to post to.
set EMAIL_OPTION_HIDDEN_IN_MODAL
to True
to not show the email option in the modal. The default is to show the option in the modal. Email will still send if others options are set.
set EMAIL_TO
, GMAIL_USER
, and GMAIL_PWD
to send the post to an email address. You must set up the gmail account app password, see here: https://stackabuse.com/how-to-send-emails-with-gmail-using-python/ which refers to https://support.google.com/accounts/answer/185833. To automatically send the post into Wordpress, set the EMAIL_TO
address to the random Wordpress email generated by Wordpress, see here: https://wordpress.com/support/post-by-email/#:~:text=Go%20to%20My%20Site(s,posts%20by%20sending%20an%20email%E2%80%9D.
See .env-f3nation-community file for help on local development
The url for your deployed app needs to be placed in three locations in the slackblast app in Slack:
- Interactivity and Shortcuts
- Request URL
- Options Load URL
- Slash Commands
- Request URL
Format of the URL to be used
https://<YOUR-AZURE-APP-NAME>/slack/events
Scopes
app_mentions:read
channels:read
chat:write
chat:write.public
commands
im:write
users:read
users:read.email
main_slackblast.yml or main_.yml contains the code to deploy on Azure via github repository. However, this will be unique to your own installation and is gitignored by default since you shouldn't need to change this as Azure sets it for you.
- Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
- More GitHub Actions for Azure: https://github.com/Azure/actions
- More info on Python, GitHub Actions, and Azure App Service: https://aka.ms/python-webapps-actions
Use vscode locally with a .env
file with the above variables. With vscode Azure extension, you can right-click on 'Application Settings' and it will upload your .env
variables right into the AppService.
Pushing to the github repo should trigger a new deployment to Azure if you set up the AppService correct.
To run locally:
pip install -r requirements.txt
gunicorn -k uvicorn.workers.UvicornWorker --bind "0.0.0.0:8000" --log-level debug app:app
In another console, use the url output by ngrok to update your slackblast app settings:
ngrok http 8000
See .env-f3nation-community file for more details on local development
Thanks goes to these awesome PAX (emoji key):
Trent ๐ค ๐ป ๐ ๐งโ๐ซ ๐ |
yankeestom ๐ค ๐ป ๐ |
willhlaw ๐ค ๐ป ๐ ๐ |
This project follows the all-contributors specification. Contributions of any kind welcome!