Send Alerts by SMS, Emails, Teams, Slack

When you need to send a notification after finding an anomaly in model solution or deliver a data analysis report via email, you can use the send_alerts() method from our Python toolkit within a script step inside a Pipeline.

In v11.1 we introduced new integrations for the context.api.send_alerts()method. The platform can now generate alerts through the following services:

  • SMS
  • Email
  • Slack
  • Teams
  • WhatsApp

Additionally, you can check our Python SDK documentation article for more information.

Send Alerts

The basic structure ofcontext.api.send_alerts() includes

  • message: A string containing the message to be sent.
  • recipients: A list of recipients (email, phone number, channel, ...)
  • alert_type: wizata_dsapi.AlertType that defines the type of alerts:
    • wizata_dsapi.AlertType.SMS
    • wizata_dsapi.AlertType.EMAIL
    • wizata_dsapi.AlertType.SLACK
    • wizata_dsapi.AlertType.TEAMS
    • wizata_dsapi.AlertType.WHATSAPP
  • subject (only for emails): A string containing the email subject.
  • cc (only for emails): A list of CC recipients.

Examples:

# Email example
def send_alert_to_mail(context: wizata_dsapi.Context):
    context.api.send_alerts(
        message="This message will be sent to your email",
        recipients=["[email protected]"],
        alert_type=wizata_dsapi.AlertType.EMAIL,
        subject="Test email support"
    )
# Slack example
def send_alert_to_slack(context: wizata_dsapi.Context):
    context.api.send_alerts(
        message="Message sent to the Slack channel written inside recipients list",
        recipients=['your-slack-channel'],
        alert_type=wizata_dsapi.AlertType.SLACK
    )
# Slack example
def send_alert_by_SMS(context: wizata_dsapi.Context):
    context.api.send_alerts(
        message="Message sent by SMS",
        recipients=['+XXXXXXXXXXX'],
        alert_type=wizata_dsapi.AlertType.SMS
    )
# Teams example
def send_alert_by_teams(context: wizata_dsapi.Context):
    context.api.send_alerts(
        message="Message sent to the Teams channel written inside recipients list",
        recipients=['your-teams-channel'],
        alert_type=wizata_dsapi.AlertType.TEAMS
    )

Configuration

Email

Email capabilities are built-in within the app, they will be sent through our servers using cloud services.

SMS

SMS capabilities are built-in within the app, they will be sent through our servers using cloud services.

Slack

To use slack you need to generate a webhook with permissions to the channel(s) you want to use.

Generate the webhook

There's different ways to generate a webhook on slack, such as creating your own app (see slack webhooks) or using a generic app such as incoming webhooks

Once you have your webhook it should have a structure similar to:

https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX

Add webhook to custom.ini

Add your webhook to the custom.ini file (see configuration)

[slack]  
webhook=https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX

Additional webhooks

If you desire to use another webhook that the default one, you can name it and pass its name to the function manually.

[slack]
webhook=https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
second_webhook=https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXX
def send_alert_to_slack(context: wizata_dsapi.Context):
    context.api.send_alerts(
        message="Message sent to the Slack channel written inside recipients list",
        recipients=['your-slack-channel'],
        alert_type=wizata_dsapi.AlertType.SLACK,
        webhook="second_webhook"
    )

send_alerts() method also accept blocks parameter as a list of blocks ID's for advanced Slack formatting blocks configuration.

For more information, please refer to their official documentation.

Teams

To use Microsoft Teams you need to generate a webhook with permissions to the channel(s) you want to use.

Generate the webhook

There's different ways to generate a webhook on Microsoft Teams, we recommend using a generic app such as incoming webhooks

Once you have your webhook it should have a structure similar to:

https://xxxxx.webhook.office.com/xxxxxxxxx

Add webhook to custom.ini

Add your webhook to the custom.ini file (see configuration)

[teams]  
webhook=https://xxxxx.webhook.office.com/xxxxxxxxx

As a practical guide to this topic, in the following article we will present an example on how to send an email notification if an anomaly was detected