Jump to content

Performance/SlackBot

From Wikitech

The Slackbot offers an easy to use testing experience by starting testing right from the slack workspace. This documentation will walk you through the setup process, explain how the bot works, and provide you step-by-step guidance on how to configure and execute performance tests using the commands the bot supports.

Overview

Chart showing slackbot communication flow
Slackbot communication flow


This shows the flow of the bot and how it sends and receives results.

Getting Started

To use the bot, you will need to Install the following dependencies:

  • slack
  • flask
  • slackeventsapi
  • dotenv

Installation and Setup

Instructions for setting up and configuring the Slack App in the Slack workspace:

  • Go to <https://api.slack.com/apps> and create a new app.
  • In the "Basic Information" section, enter a name for your app and select a workspace.
  • In the "OAuth & Permissions" section, under scopes add “Bot Token Scope” OAuth Scopes" that you want to grant to your bot. For this app the scope granted is chat:write

Click "Install App to Workspace”, this might take a while depending on your network. When this is done, you will need to add the app to a channel, the /add command can be used to trigger the slack prompt that helps you with this.

screenshot showing how to use add command
use add command
  • Click on Add apps to this channel and search for perfworld app (or the name of your own app).
  • Click on perfworld to successfully add to the channel.
  • Your bot is now installed on your workspace and can be used to test the performance of websites.

Authentication and External dependencies or integration required

You will need to have a valid API token for both Slack and Sitespeed.io in order to use the Slackbot. You can generate these tokens from the respective websites.

  • Slack API: The Slackbot needs to be able to communicate with Slack. This is done through the Slack API.
  • Sitespeed.io API: This Slackbot uses the Sitespeed.io API to run performance tests on websites.

Authentication

  • To authenticate your bot, you will need to generate a Slack API token. You can do this by going to the "OAuth & Permissions" section of your app's settings in Slack.
  • Once you have generated your API tokens, you will need to add it to your bot's configuration. You can do this by editing the .env file and adding the following lines:
SLACK_TOKEN=YOUR_SLACK_API_TOKEN
SITESPEED_IO_API_KEY=YOUR_SITESPEED_IO_API_KEY
  • Signing secret should also be added to the .env file, this is under the Basic Information section of the app. A Slack signing secret is a unique string that is generated when you create a Slack app. It is used to verify that requests from Slack are authentic.
SIGNING_SECRET=YOUR_SLACK_SIGNING_SECRET

Bot Functionality

The current primary functionality of the Slackbot is to test the performance of websites. The bot uses the Sitespeed.io API to run performance tests on websites and then sends the results to the user in Slack.

The bot can be used to test the performance of any website. To do this, send a message to the bot with the URL of the website that you want to test. The bot will then run a performance test on the website and send the results to you in Slack.

Command Usage

Bot recognizes a whole list of command. To request for a test, in the channel type /performance-bot and provide the url you want to test :

/performance-bot https://en.wikipedia.org/wiki/Banana 

and send it to the channel as a message

/performance-bot usage
/performance-bot usage



Other commands can be passed to the  performance bot depending on what the user wants to perform

An example is wanting to run test iteration n number of times. The test command will look like this to run the iteration 5 times ;

/performance-bot https://en.wikipedia.org/wiki/Banana -n 5

So the template is: URL followed by parameters that needs to be passed with spaces in between them  

Check sitespeed.io documentation for more options that are available.

Test Result

The Slack bot sends a link of the completed job test to the User in this format:

Sample of test result
Sample of test result

A link to the test result is sent back to the user as a direct message. Click on it to view more information on the test. A link to the test result is sent back to the user as a direct message. Click on it to view more information on the test.