Slack Connection
In this page we go through the process of creating a Resources Slack connection.
Create Slack App
First, you will need to navigate to Slack api to create an app with a name and a Slack domain. Here we walk through creating a simple slack app which allows a bot to post a message to a user.
Set up the Slack Resource
Slack Examples
Having set up your Slack connection, you can now use it in your ScriptRunner scripts using the resource Connection Name.
Using Blocks and Attachments
The following example sends a message using blocks and attachments. In this case the message text provided is used as a fallback option.
import com.onresolve.scriptrunner.slack.SlackUtil
SlackUtil.message("slack",
"acme-developers",
"This is the fallback message text",
[
username : "ScriptRunner Bot",
blocks : [
[
type: 'section',
text: [
type: 'plain_text',
text: 'Message text'
]
]
],
attachments: [
[
pretext: 'Introductory text',
text : 'Text message as part of attachment'
],
]
]
)Uploading a File
Upload file to a Slack channel. Scope files:write is required. You can either upload a file to a channel (if the bot user is part of this channel) or to a specific user:
import com.onresolve.scriptrunner.slack.SlackUtil
SlackUtil.upload("slack",
"acme-developers",
new File("/tmp/file.txt"),
[
text : 'Fallback text',
initial_comment: 'Comment about the file being uploaded',
]
)In a Post Function
As another example, you can add the following to a post function to send a message to the project manager with the issue priority and summary after it is created.
import com.onresolve.scriptrunner.slack.SlackUtil
SlackUtil.message("slack",
"acme-developers",
"${issue.priority.name} priority issue created: *${issue.summary}*"
)