Send Slack Notifications from Autonomous Database

Describes how to configure Slack so that you can send messages, alerts, or output of a query from Autonomous Database to a Slack Channel. Also describes the procedures you use to send Slack notifications.

Prepare to Send Slack Notifications from Autonomous Database

To send Slack notifications, configure your Slack application to receive messages from Autonomous Database. Next, create a credential to use with DBMS_CLOUD_NOTIFICATION procedures to send Slack notifications from Autonomous Database.

To use Slack with DBMS_CLOUD_NOTIFICATION procedures:

  1. Create your Slack app.

    The Slack app is installed in a Slack Workspace, which in turn has Channels where messages can be sent. The bot token of the Slack app must have the following permission scopes defined:

    channels:read
    chat:write
    files:write

    See Creating an app for information on setting up a Slack app.

  2. A Slack admin must add the Slack App to the channels to which DBMS_CLOUD_NOTIFICATION can send message through the "Integrations" option in the channel.

    See Basic app setup for more information.

  3. Share the app's bot token with the Autonomous Database instance ADMIN user.

    The Slack bot token is available in the Slack app specific page, under https://app.slack.com.

    See Basic app setup for more information.

  4. On the Autonomous Database instance, the ADMIN creates a credential object to access the Slack app.

    The credential's username is SLACK_TOKEN and the password is the bot token.

    For example:

    BEGIN
       DBMS_CLOUD.CREATE_CREDENTIAL(
         credential_name => 'SLACK_CRED',
         username    => 'SLACK_TOKEN',
         password    => 'xoxb-34....96-34....52-zW....cy');
    END;
    /

    See CREATE_CREDENTIAL Procedure for more information.

  5. The ADMIN user provides access to the Slack credential to users that want to send Slack notifications.
  6. Configure access control to allow user access to external network services (Slack).
    BEGIN
     DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE (
      host         => 'slack.com', 
      lower_port   => 443,
      upper_port   => 443,
      ace          => xs$ace_type(
          privilege_list => xs$name_list('http'),
          principal_name => example_invoking_user, 
          principal_type => xs_acl.ptype_db)); 
    END;

    See Configuring Access Control for External Network Services for more information.

Send Messages to a Slack Channel

You can use the DBMS_CLOUD_NOTIFICATION package to send messages to a Slack channel.

  1. Obtain access to the credential object to send notifications to a Slack channel.

    The ADMIN user creates the credential object you use to send Slack notifications. See Prepare to Send Slack Notifications from Autonomous Database for more information.

  2. Use SEND_MESSAGE to send a message to a Slack channel.
    BEGIN
       DBMS_CLOUD_NOTIFICATION.SEND_MESSAGE(
          provider          => 'slack',
          credential_name   => 'SLACK_CRED',
          message           => 'Alert from Autonomous Database...',
          params            => json_object('channel' value 'C0....08'));
    END;
    / 

    Use the params parameter to specify the Slack channel.

    • channel. Specifies the Channel ID.

      The Channel ID is a unique ID for a channel and is different from the channel name. In Slack, when you view channel details you can find the Channel ID on the “About” tab. See How to Find your Slack Team ID and Slack Channel ID for more information.

See SEND_MESSAGE Procedure for more information.

Send Query Results to a Slack Channel

You can use the DBMS_CLOUD_NOTIFICATION package to send the results of a query to a Slack channel.

  1. Obtain access to the Slack credential to send notifications to a Slack channel.

    The ADMIN user creates the credential object you use to send Slack notifications. See Prepare to Send Slack Notifications from Autonomous Database for more information.

  2. Use SEND_DATA to send the output of query to a Slack channel.
    BEGIN
      DBMS_CLOUD_NOTIFICATION.SEND_DATA(
          provider => 'slack',
          credential_name => 'SLACK_CRED',
          query => 'SELECT username, account_status, expiry_date FROM USER_USERS WHERE rownum < 5',
          params => json_object('channel' value 'C0....08',
                                'type' value 'csv'));
    END;
    /

    Use the params parameter to specify the Slack channel and the data type:

    • channel. Specifies the Channel ID.

      The Channel ID is a unique ID for a channel and is different from the channel name. In Slack, when you view channel details you can find the Channel ID on the “About” tab. See How to Find your Slack Team ID and Slack Channel ID for more information.

    • type. Specifies the output type. Valid values are: 'csv' or 'json'.

See SEND_DATA Procedure for more information.

Related Topics