Connecting MI Slackbot to Metric Insights

This article details how to finish the MI Slackbot configuration by establishing connectivity between MI Slackbot and a Metric Insights server.

PREREQUISITES:

  1. Deploy MI Slackbot
  2. Build a bot app in Slack
  3. Connect Slack bot app to the main MI application

1. Build a Dataset for MI Slackbot

The Dataset for MI Slackbot will contain information about all elements in Metric Insights.

Before building a Dataset:

  1. Make sure you are logged in as Admin User
  2. Check that there is at least one Element in Metric Insights
    • If there are no elements in the MI application, it will be impossible to Validate the Dataset (as the SQL query will not return any results)
1.1. Access Dataset Editor > Data tab
  1. Access Dataset Editor > Data tab via New > Datasets > Create New
  2. Configure the Settings:
    1. Data Source for the Dataset should be set to "Dashboard DB"
    2. Enter the SQL statement (exact statement is provided in Section 1.2)
  3. Validate
  4. Save
  5. Dataset ID: copy the Dataset ID from the URL
    • It will be required for MI Slackbot configuration. See details in Section 5

For more information on how to create a Dataset, refer to Create a Dataset from any Data Source

1.2. Copy the SQL statement from this section
select
    de.element_id,
    IFNULL(last_sv.segment_value_id, 0) as segment_value_id,
    IFNULL(de.segment_id, 0) as segment_id,
    IFNULL(last_sv.element_short_name, concat(de.name,' ', IFNULL(sv.value_display_name,''))) as name,
    de.name as element_name,
    sv.value_display_name as segment_value,
    seg.name as segment_name,
    de.type,
    ert.reporting_tool_name as external_report_type,
    de.certified_ind,
    last_sv.metric_last_measurement_value_formatted as metric_last_measurement_value,
    last_sv.last_measurement_time,
    GROUP_CONCAT(t.name separator ',') AS keywords,
    '' AS slack_channels,
    de.description,
    mint.name as interval_name,
    IFNULL(devl.view_count, 0) as view_count
FROM dashboard_element AS de
JOIN dashboard_category AS dc ON (dc.category_id=de.category_id)
LEFT JOIN measurement_interval mint on mint.measurement_interval_id = de.measurement_interval_id
LEFT JOIN segment as seg on (de.segment_id=seg.segment_id)
LEFT JOIN dashboard_element_topic AS det ON (det.dashboard_element_id=de.element_id)
LEFT JOIN topic AS t ON (t.topic_id=det.topic_id)
LEFT JOIN last_dashboard_element_segment_value as last_sv on (last_sv.element_id=de.element_id)
LEFT JOIN segment_value as sv ON (last_sv.segment_value_id=sv.segment_value_id)
LEFT JOIN external_report_type as ert ON (ert.external_report_type_id=de.external_report_type_id)
LEFT JOIN (
        select sum(total_view_count) as view_count, element_id, segment_value_id
        from dashboard_element_view_log
        group by element_id, segment_value_id) AS devl
    ON devl.element_id=de.element_id and devl.segment_value_id=last_sv.segment_value_id
WHERE last_sv.last_measurement_time_flag='Y'
GROUP BY de.element_id, last_sv.segment_value_id
ORDER BY de.element_id, last_sv.segment_value_id

2. Create credentials in MI Application

Application ID and Application Key credentials are used to configure MI Slackbot (Slackbot.ini file) as described in Section 5.

These credentials will be encrypted to prevent third-party breaches. For more information, go to Slack App Encryption

2.2. Name your External Application
  1. Access External Applications page> click [+ New External Application]
  2. Name: provide a meaningful name for your External Application
  3. Save to proceed
2.3. Get Credentials for External App
  1. User management access: set to "yes" in order for Slack App to be able to access MI Users
  2. Cross Domain access: switch from default to "yes" if your MI Slackbot is installed on a different server than the main MI application
  3. Show credentials: click to obtain access credentials
    1. Application ID and Application key are required to configure MI Slackbot.ini file. The details on how they are used are provided in Section 5

3. Configure Slackbot.ini file

To access the Slackbot.ini file, you must be an admin with root privileges.

In the production version of 6.x (General Availability) the Slackbot.ini file will be populated automatically.

In order to allow the MI Slackbot to communicate with the Slack App, you need to connect via SSH to the server with the installed MI Slackbot and modify the Slackbot configuration file.

Slackbot.ini  file is to be found at /opt/mi/iv/engine/config/slackbot.ini

NOTE:

  1. When the MI Slackbot is installed, the emtpy Slackbot.ini file is generated
  2. The first time the MI Slackbot is launched, its configuration file will contain the following values (view below)
  1. instance_hostname: name of the server where the MI App is installed
  2. instance_bot_hostname: hostname of the server where the MI Slackbot is installed 
    • Should be specified only if the Bot is installed separately from the MI App
  3. url_path: part of the URL between the domain name and the bot-endpoints 
    • Defaults to  "/slack"
    • Should be changed only if the corresponding changes were made in the apache configuration file 
  4. api_token: Bot User OAuth Access Token
  5. bot_token: OAuth Access Token
  6. app_id: Application ID 
    • Obtained from External Application in Metric Insights
    • See details in Section 2
  7. app_key: Application Key 
    • Obtained from External Application in Metric Insights
    • See details in Section 2
  8. app_user: Admin User in Metric Insights
  9. dataset_id: default "0" value should be replaced with the ID of the Dataset built for the MI Slack App
  10. send_broadcasts: enables broadcast messages
    • These are notification messages for all channels where the bot is participating
    • Such messages can be sent on restarts or sync fails
  11. slack_signing_secret: secret used to verify Slack requests
  12. ms_id: Microsoft Teams Bot ID
    • To be specified when using MI Slackbot for Slack integration
  13. ms_key: Microsoft Teams Bot key
    • Password in Microsoft Teams; to be specified when using MI Slackbot for Slack integration
  14. tenant_id: globally unique identifier for your organization in Microsoft Azure
    • Should be configured if the MI Slackbot is used in Microsoft Teams
  15. slack_enabled: to enable Slack Integration, set to "True"
  16. ms_teams_enabled: to enable Microsoft Teams Integration, set to "True"
  17. type: defines the type of variable ("global" or "channel-specific")

4. Restart MI Slackbot

In order to restart the MI Slackbot, run the following command:

sudo docker restart mi-slackbot

5. What's next?

Having restarted the MI Slackbot, you can make full use of the available functionality (getting data from Metric Insights and sharing it in a Slack Channel).

For more information, refer to Access content via a Slack App