Template Content
About the template
About ScriptRunner Connect
What is ScriptRunner Connect?
Can I try it out for free?
Yes. ScriptRunner Connect comes with a forever free tier.
Can I customize the integration logic?
Absolutely. The main value proposition of ScriptRunner Connect is that you'll get full access to the code that is powering the integration, which means you can make any changes to the the integration logic yourself.
Can I change the integration to communicate with additional apps?
Yes. Since ScriptRunner Connect specializes in enabling complex integrations, you can easily change the integration logic to connect to as many additional apps as you need, no limitations.
What if I don't feel comfortable making changes to the code?
First you can try out our AI assistant which can help you understand what the code does, and also help you make changes to the code. Alternatively you can hire our professionals to make the changes you need or build new integrations from scratch.
Do I have to host it myself?
No. ScriptRunner Connect is a fully managed SaaS (Software-as-a-Service) product.
What about security?
ScriptRunner Connect is ISO 27001 and SOC 2 certified. Learn more about our security.
This template demonstrates how to create an incident in Statuspage from Slack slash command, and how to posts back a message to Slack channel containing the newly created incident ID.
Parameters
and change the PAGE_ID
and INCIDENT_STATUS
parameters to appropriate values for your StatusPage instance.Trigger a Slack slash command (/command_name <INCIDENT_NAME>
), after successful event processing a new incident should be created in Statuspage and that incident's id be sent back to Slack.
import Slack from './api/slack';
import Statuspage from './api/statuspage';
import { SlashCommandEvent } from '@sr-connect/slack/events';
/**
* This function creates a Statuspage incident based on data triggered by Slack's slash command,
* and then posts back a message to Slack containing newly created incident id.
*
* Command syntax: /command_name <INCIDENT_NAME>
*
* @param event Object that holds Slash Command event data
* @param context Object that holds function invocation context data
*/
export default async function (event: SlashCommandEvent, context: Context): Promise<void> {
if (context.triggerType === 'MANUAL') {
console.error('This script is designed to be triggered externally or manually from the Event Listener. Please consider using Event Listener Test Event Payload if you need to trigger this script manually.');
return;
}
const envVars = context.environment.vars as EnvVars;
try {
// Log out the event that was received
console.log('Create Statuspage incident slash command triggered', event);
// Extract incident name from Slack slash command event
const incidentName = event.text.trim();
// Check if the name is specified
if (!incidentName) {
// If not, post approriate message back to Slack channel where the command originated from
await Slack.Chat.postMessage({
body: {
channel: event.channel_id,
text: 'Incident name is required'
}
});
// And halt the operation
return;
}
// Log out the information that the incident is about to be created
console.log('Creating incident', {
page_id: envVars.PAGE_ID,
status: envVars.INCIDENT_STATUS,
name: incidentName
});
// Create the incident
const incident = await Statuspage.Incident.createIncident({
page_id: envVars.PAGE_ID,
body: {
incident: {
body: 'Incident created from Slack slash command',
name: incidentName,
status: envVars.INCIDENT_STATUS
}
}
});
// Log out the created incident id
console.log(`Incident created: ${incident.id}`);
// And post a message with the id of the newly created incident back to the Slack channel where the command originated from
await Slack.Chat.postMessage({
body: {
channel: event.channel_id,
text: `Incident created: ${incident.id}`
}
});
} catch (e) {
// If something goes wrong, log out the error
console.error('Error while processing slash command', e);
// And post an appropriate message back to the Slack channel where the command originated from
await Slack.Chat.postMessage({
body: {
channel: event.channel_id,
text: 'Something went wrong while creating an incident'
}
});
}
}
interface EnvVars {
readonly PAGE_ID: string;
readonly INCIDENT_STATUS: 'investigating' | 'identified' | 'monitoring' | 'resolved' | 'scheduled' | 'in_progress' | 'verifying' | 'completed';
}