If your team works on a Slack workspace, and the team has to maintain a bunch of different email ids and wish to be notified of every email instantly on slack; there is a hack for you.
After setting up your Slackbot chat as a forward emailing address of your email account (Steps expalined below)
this bot watches for messages in the Slackbot chat and whenever a message arrives with an attached email, It forwards it to a channel as a message.
You can create a account for just emails as the emails appear in the DM of the user that sets up the app. If you want to avoid two notifications, one from the slackbot and one from this app, it is advised to use a secondary account to setup this app.
[something]@[workspace].slack.com
files:read
, im:history
in User Token Scopesincoming-webhook
in Bot Token ScopesHere we will deploy on fly for simplicity. This can be deployed to any other hosting provider or the app can be self hosted if you choose to do so. Do note that though deployment on fly is optional, deployment itself is not! If you have deployed the app elsewhere, please set the environment variables accordingly.
For fly ensure: You have the
flyctl
installed, If not follow the steps flyctl installation. If you haven't logged in:fly auth login
Then in the root of the repo:
$ flyctl launch # generates the fly.toml file for this project
Note: after this step, you need to edit Procfile according to your needs, here in this directory Procfile is already configured for you, so select N when prompted to edit.
$ flyctl secrets set APP_ID=... # set the environment variables, do this for all env variables
$ fly deploy # deploys the master branch
If you are stuck anywhere, please refer to flyctl docs
Aside: One quick way to test that the deployment was semi-successful is to visit the deployed URL and it should redirect to the github's repo. The app processes the POST requests and all GET requests are forwarded to the repo's page.
Now time to configure the environment variables on heroku!
Config Variable | Description |
---|---|
APP_ID |
You get this when you create the app |
INCOMING_WEBHOOK_URL |
You get this when you install the app on one channel |
TEAM_ID |
ID of your slack workspace. |
USLACKBOT_CHANNEL |
The ID of the direct messaging channel between you and @slackbot |
VERIFICATION_TOKEN |
You get this when you create the app |
Note that the Slack IDs (for channel, users, files) are alphanumeric uppercase string of 9 characters. In browser, if you have opened the chat with the slackbot the URL will be of the format:
https://app.slack.com/client/<TEAM_ID>/<USLACKBOT_CHANNEL>/
For more details on finding team and channel ID see this question on stackoverflow.
You can set these variables via cli in the directory containing fly.toml:
$ flyctl secrets set APP_ID=...
Do note the link to which server is deployed, we will set it up in slack settings in a moment.
message.im
in Subscribe to events on behalf of usersVoilà the setup is complete!
A PHP version of email-to-slack by Mehdi Chaouch
The deployment doesn't work?
If these steps don't work please file an Issue.