This tutorial combines the power of Slack and the Kinsta API to build a Slackbot capable of managing various site tasks. With this Slackbot, we perform actions such as checking site status, clearing a site's cache, restarting a site's PHP engine, and lots more.
Read the full article.
- Clone or fork the repository.
During the deployment process, Kinsta will automatically install dependencies defined in your package.json
file.
When deploying, add the following environment variables:
SLACK_SIGNING_SECRET="YOUR_SIGNING_SECRET"
SLACK_BOT_TOKEN="xoxb-YOUR_BOT_TOKEN"
APP_TOKEN="xapp-YOUR_APP_TOKEN"
KINSTA_COMPANY_ID = "YOUR_COMPANY_ID"
KINSTA_API_KEY = "YOUR_API_KEY"
Kinsta automatically sets the PORT
environment variable. You should not define it yourself and you should not hard-code it into the application. Use process.env.PORT
in your code when referring to the server port.
(async () => {
// Start your app
await app.start(process.env.PORT);
console.log(`⚡️ Kinsta Bot app is running on port ${process.env.PORT}!`);
})();
When deploying an application Kinsta will automatically create a web process with npm start
as the entry point. Make sure to use this command to run your server. If you would like to use another command you will need to modify the runtime process in MyKinsta.
"scripts": {
"start": "node app.js"
},
Whenever a deployment is initiated (through creating an application or re-deploying due to an incoming commit), the npm install
and npm build
commands are run.
/environment_id [site_name]
: Get the environment ID for a given site name.
Parameters:
site_name
(required): The name of the site.
Example:
/environment_id my-website
/site_id [site_name]
: Get the site ID for a given site name.
Parameters:
site_name
(required): The name of the site.
Example:
/site_id my-website
/operation_status [operation_id]
: Check the status of a Kinsta operation using the operation ID.
Parameters:
operation_id
(required): The ID of the operation.
Example:
/operation_status 123456
/clear_site_cache [environment_id]
: Clear the cache for a given environment.
Parameters:
environment_id
(required): The environment ID.
Example:
/clear_site_cache 987654
/restart_php_engine [environment_id]
: Restart the PHP engine for a given environment.
Parameters: environment_id (required): The environment ID.
Example:
/restart_php_engine 987654
/get_backups [environment_id]
: Fetch all backups (manual, scheduled, and system-generated) for a given environment.
Parameters:
environment_id
(required): The environment ID.
Example:
/get_backups 987654
/get_downloadable_backups [environment_id]
: Fetch all downloadable backups for a given environment.
Parameters:
environment_id
(required): The environment ID.
Example:
/get_downloadable_backups 987654
/restore_backup [target_environment_id] [backup_id] [environment_name]
: Restore a backup for a target environment using a given backup ID and environment name.
Parameters:
target_environment_id
(required): The ID of the target environment. backup_id (required): The ID of the backup.environment_name
(required): The name of the environment from which the backup originated.
Example:
/restore_backup 123 456 staging
/add_manual_backup [environment_id] [tag]
: Create a manual backup with a specific tag for a given environment.
Parameters:
environment_id
(required): The environment ID.tag
(required): A tag for the backup.
Example:
/add_manual_backup 987654 "Backup before update"
/delete_backup [backup_id]
: Delete a backup by its ID.
Parameters:
backup_id
(required): The ID of the backup to delete.
Example:
/delete_backup 456789
- /get_site_logs [environment_id] [file_name] [lines]: Get site logs from a specific environment.
Parameters:
environment_id
(required): The environment ID.file_name
(optional): The log file name (default: error).lines
(optional): Number of lines to fetch (default: 1000).
Example:
/get_site_logs 987654 error 500
- /schedule_backup [environment_id] [tag] [time]: Schedule a backup at a specific time.
Parameters:
environment_id
(required): The environment ID.tag
(required): The tag for the backup.time
(required): The time to schedule the backup (in HH 24-hour format).
Example:
/schedule_backup 987654 "Scheduled Backup" 14:30
/backup_all_sites [tag]
: Create a manual backup for all environments across all sites.
Parameters:
tag
(optional): A tag for the backups (default: default-backup-tag).
Example:
/backup_all_sites "Maintenance Backup"
/backup_multiple_envs [tag] [env_id1] [env_id2] ...
: Create backups for multiple environments with a specific tag.
Parameters:
tag
(required): The tag for the backup.env_ids
(required): Space-separated environment IDs.
Example:
/backup_multiple_envs "Multiple Envs Backup" 987654 876543
/schedule_backup_all_sites [tag] [time]
: Schedule backups for all sites at a specific time.
Parameters:
tag
(required): The tag for the backups.time
(required): The time to schedule the backup (in HH 24-hour format).
Example:
/schedule_backup_all_sites "Scheduled Backup" 15:00
Kinsta is a developer-centric cloud host / PaaS. We’re striving to make it easier for you to share your web projects with your users. Focus on coding and building, and we’ll take care of deployment and provide fast, scalable hosting. + 24/7 expert-only support.