Slack and Teams notifications
Post Smooth POS events to Slack or Microsoft Teams with Glue.
Get Smooth POS news where your team already talks. With a Glue job and the Send Notification step, you can post to a Slack or Microsoft Teams channel when something happens in Smooth POS, or on a schedule. This guide covers the setup from start to finish, with a few ready-made jobs.
1. Create an incoming webhook
Smooth POS posts to a channel through an incoming webhook: a private https address that belongs to that channel.
- Slack: create a Slack app for your workspace, turn on Incoming Webhooks, add a new webhook and pick the channel. Copy the webhook URL. It starts with
https://hooks.slack.com/. - Microsoft Teams: create an incoming webhook for the channel in Teams and copy its URL. How you do this depends on your Teams setup, so check with your Teams admin.
Make one webhook per channel. A Glue job can post to as many as you like.
2. Save the URL in private data
Anyone with the URL can post to your channel, so treat it like a password. Store it in private data instead of typing it into a Glue step:
curl -X POST "https://api.smoothpos.net/mycompany/privatedata/slack_ops.json" \
-H "X-Smoothpos-Auth: YOUR_TOKEN" \
-H "Content-Type: text/plain" \
-d "https://hooks.slack.com/services/..."Your API user needs the mycompany_update permission. See API users and tokens.
3. Read it in your Glue job
Every job below starts the same way:
-
API Request: Get Private Data, Key
slack_ops, Response variableslack_res. -
Script: Read the webhook URL
var pd = JSON.parse($.slack_res.body); $.slack_url = pd[Object.keys(pd)[0]].trim();
Then use {{ slack_url }} in the Send Notification step's Webhook URL.
Notifications shouldn't stop the jobLeave Fail on bad response code off unless the message is the whole point of the job. That way a Slack or Teams hiccup doesn't stop the real work.
Example: Stocktake completed
Trigger: System Hook, stocktake_status_change.
-
API Request: Get Private Data, Key
teams_stock, Response variableteams_res. -
Script: Read the change
var change = JSON.parse($.default); $.stocktake_id = change.stocktake_id; $.warehouse_id = change.warehouse_id; $.is_complete = change.after === "Complete"; var pd = JSON.parse($.teams_res.body); $.teams_url = pd[Object.keys(pd)[0]].trim(); -
If Condition: If the stocktake is complete, Condition
$.is_complete === true. -
Send Notification: Post to Teams, nested under THEN: Channel Microsoft Teams, Webhook URL
{{ teams_url }}, TitleStocktake {{ stocktake_id }} complete, MessageThe stocktake for warehouse {{ warehouse_id }} is complete. See the variances under Inventory → Stocktakes.
Example: Daily sales by store
Trigger: Scheduled, daily at 6:00 am.
-
API Request: Get Private Data, Key
slack_ops, Response variableslack_res. -
Script: Build the report
var pd = JSON.parse($.slack_res.body); $.slack_url = pd[Object.keys(pd)[0]].trim(); var now = new Date(); var y = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1); var day = y.toISOString().slice(0, 10); $.day = day; $.run_body = JSON.stringify({ data_source: "sales", columns: [ {field: "store_name", name: "Store"}, {field: "total", name: "Sales", aggregation: "sum"} ], sort: {field: "total", aggregation: "sum", direction: "desc"}, period: {from_date: day + "T00:00:00", to_date: day + "T23:59:59", timezone: "Australia/Sydney"}, filters: [] }); -
API Request: Run a report, Body
{{ run_body }}, Response variablerun_res. -
Script: Write the message
var rows = JSON.parse($.run_res.body).results || []; $.message = rows.map(function (r) { return r.store_name + ": " + r.sum_total.toFixed(2); }).join("\n"); $.has_sales = rows.length > 0; -
If Condition: If there were sales, Condition
$.has_sales === true. -
Send Notification: Post to Slack, nested under THEN: Channel Slack, Webhook URL
{{ slack_url }}, TitleSales for {{ day }}, Message{{ message }}.
See Reports and exports for building the report.
More ideas
- Store Pickups that need a refund: Online orders and fulfilment.
- New promotions: Promotions.
- A weekly report file: Reports and exports.
- Big sales and failed syncs: Send Notification step.
Updated about 22 hours ago
