This is a demo Slack bot that integrates with the Schematic API to show notifications in Slack.
Note
This demo was created from the Bolt for JavaScript (TypeScript) Template App and uses the Bolt for JavaScript framework to create a Slack app.
Caution
This is a demo application and should not be used in production. It is intended to show how to integrate the Schematic API with Slack.
- Open https://api.slack.com/apps/new and choose "From an app manifest"
- Choose the workspace you want to install the application to
- Copy the contents of manifest.json into the text box that says
*Paste your manifest code here*
(within the JSON tab) and click Next - Review the configuration and click Create
- Click Install to Workspace and Allow on the screen that follows. You'll then be redirected to the App Configuration dashboard.
Before you can run the app, you'll need to store some environment variables.
- Copy
env.sample
to.env
- Open your apps configuration page from this list, click OAuth & Permissions in the left hand menu, then copy the Bot User OAuth Token into your
.env
file underSLACK_BOT_TOKEN
- Click Basic Information from the left hand menu and follow the steps in the App-Level Tokens section to create an app-level token with the
connections:write
scope. Copy that token into your.env
asSLACK_APP_TOKEN
.
npm install
npm start
To receive webhooks from the Schematic API, you'll need to expose your local server to the internet, for example, using ngrok
:
ngrok http 3000
- Open the Schematic dashboard
- Navigate to More > Integrations > Webhooks
- Click Create Webhook
- Enter a name for the webhook, e.g. "Slack Bot"
- Enter the URL provided by
ngrok
in the URL field:https://<your-ngrok-subdomain>.ngrok.io/schematic-webhook
- For the Events field, select the following events:
plan.entitlement.created
plan.entitlement.updated
plan.entitlement.deleted
- Click Save
- Open the Slack app and navigate to the channel you want to add the bot to
- Type
/
in the channel and select "Add apps to this channel" - Search for the app "Schematic Bot Demo" you created and click Add
In the channel you added the bot to, type /schematic subscribe <event>
where <event>
is one of the following:
plan.entitlement.created
plan.entitlement.updated
plan.entitlement.deleted
For example, type the following to subscribe to the plan.entitlement.updated
event:
/schematic subscribe plan.entitlement.updated
You should see a message from the bot confirming the subscription.
- To to the Schematic Plans dashboard
- Create, update, or delete a plan entitlement
You should see a message from the bot with details about the event that occurred.