Plumber and the Slack API
See Slack and Plumber on R Views for a discussion of this code.
This asset shows how plumber
can be used to build a Slack slash command. The API is built on top of a simulated customer dataset that contains details about customer call history. The slash command provides access to customer status report as well as customer success rep reports directly from within Slack. The goal of this integration is to highlight the strengths of plumber
and how it can be used to reliably and securely integrate R with other products and services.
Using
Once you have created the slack app and the slash command as described in Getting Started, you can access the API from within the slack interface.
Commands
/cs help
/cs status <customer_id>
/cs rep <rep_name>
/cs region <region_name>
Examples
Try the following examples using the /cs
command with your slackbot.
/cs status 10
/cs rep Lovey Torp MD
`/cs region east
Simulated data
The API pulls data from a simulated customer dataset using the wakefield
package and the charlatan
package. You can use the following levels for rep
, region
, and id
.
Rep | Region | ID |
---|---|---|
Lovey Torp MD | North | 1 |
Marla Nitzsche | South | 2 |
Miss Halle Heidenreich DVM | East | 3 |
Miss Jayne Sanford | West | 4 |
Ms. Arely Strosin PhD | … | |
Sannie Schuppe DDS | 100 |
Details
Instead of registering a different command for each endpoint, the first argument provided to the slash command is the endpoint while the subsequent argument(s) (if necessary) provide additional data to be passed to the specified endpoint. This way, a single slash command serves multiple endpoints without polluting the slash command namespace.
To access a customer status report, enter /cs status <id>
in Slack, where id
is a valid customer ID from the simulated data. The customer status report includes the customer name, total calls, date of birth, and a plot call totals for the last 20 weeks. The color of the message is an indication of customer health. Green indicates the customer has no issues while red indicates the customer has a high volume of calls, indicating a potential problem.
Help for all available commands can be accessed by entering /cs help
or simply /cs
into Slack.