PHDI Alerts Service (1.2.11)

Download OpenAPI specification:Download

PHDI Alerts Container

This Docker container provides a simple API for sending alerts via SMS, Slack, or Microsoft Teams. It can be run as a local service or deployed as part of a full pipeline using PHDI Building Blocks as in CDCgov/phdi-azure.

Usage

Some manual steps need to be taken to enable alerts in your particular environment.

SMS

In order to send text messages, you'll need to create an Azure Communication Service. Follow this quickstart guide to set up the resource. Once created, you'll need to provide the name of your resource as an environment variable (COMMUNICATION_SERVICE_NAME) to the container.

The first time you make a call to /sms-alert, the container will purchase a phone number to use for sending text messages. This will charge your Azure account $2/month to reserve the phone number.

Support for other SMS providers besides Azure are coming soon!

Sample request

POST /sms-alert

{
    "phone_number": "+19168675309",
    "message": "Hi this is a test"
}

Slack

To send alerts to your Slack workspace, you'll need to create a Slack application. Follow this guide to create the Slack app, giving it a name you'll recognize, such as PHDI Alerts. The OAuth access token must be provided to the container as an environment variable (SLACK_BOT_TOKEN). You must also invite the application to any channel you wish to alert (type /invite in the channel and choose "Add apps to channel"). To get the ID of a channel, right click the channel name and choose "View channel details". The ID is at the bottom of the modal that appears.

Sample request

POST /slack-alert

{
    "channel_id": "C04GKBFMGRM",
    "message": "Hi this is a test"
}

Microsoft Teams

To send alerts to Microsoft Teams, you'll need to create a webhook in the channel you wish to alert. To add an incoming webhook to a Teams channel:

  1. Navigate to the channel where you want to add the webhook and select (•••) Connectors from the top navigation bar.
  2. Search for Incoming Webhook, and add it.
  3. Click Configure and provide a name for your webhook.
  4. Copy the URL which appears and click "OK".

Provide this URL as an environment variable (TEAMS_WEBHOOK_URL) to the container.

Sample request

POST /teams-alert

{
    "message": "Hi this is a test"
}

Health Check

Check service status. If an HTTP 200 status code is returned along with '{"status": "OK"}' then the service is available and running properly.

Responses

Response samples

Content type
application/json
{
  • "status": "OK"
}

Sms Alert

Send an SMS alert to a phone number. :param input: A JSON formated request body with schema specified by the SmsAlertInput model.

Request Body schema: application/json
phone_number
required
string (Phone Number)

The phone number to send the alert to.

message
required
string (Message)

The message to send to the phone number.

Responses

Request samples

Content type
application/json
{
  • "phone_number": "string",
  • "message": "string"
}

Response samples

Content type
application/json
null

Slack Alert

Send a Slack alert to a channel. :param input: A JSON formated request body with schema specified by the SlackAlertInput model.

Request Body schema: application/json
channel_id
required
string (Channel Id)

The Slack channel ID to send the alert to.

message
required
string (Message)

The message to send to the Slack channel.

Responses

Request samples

Content type
application/json
{
  • "channel_id": "string",
  • "message": "string"
}

Response samples

Content type
application/json
null

Teams Alert

Send a Teams alert to a channel. :param input: A JSON formated request body with schema specified by the TeamsAlertInput model.

Request Body schema: application/json
message
required
string (Message)

The message to send to the Teams channel.

Responses

Request samples

Content type
application/json
{
  • "message": "string"
}

Response samples

Content type
application/json
null