Slack - how to post a link to network folder? - slack-api

I'm using a webhook to post messages to Slack via PowerShell script and I'd like to include a link to a network folder. I was able to do it with
<file://server/folder|files>
however when the generated 'files' link is clicked nothing happens. Is there a way to specify target so that a clicked link opens in a new window? If I copy the generated link and paste it into the browser, the index is rendered just fine and that would be sufficient for my purposes. Are there any alternative solutions?

You may have some success with Slack's Link Buttons, which specifically open links in new browser tabs when clicked.
{
"text": "Test Link Buttons",
"channel": "C061EG9SL",
"attachments": [
{
"fallback": "Test link button to file://server/folder",
"actions": [
{
"type": "button",
"name": "file_request_123456",
"text": "Test",
"url": "file://server/folder",
"style": "primary",
"confirm": "Really?"
}
]
}
]
}
Slack Message Builder example

Related

Slack API - how to send multiple images so they are shown in a gallery

When I send multiple images via api using blocks like this:
{
"blocks": [
{
"type": "image",
"title": {
"type": "plain_text",
"text": "Please enjoy this photo of a kitten"
},
"image_url": "http://placekitten.com/500/500",
"alt_text": "An incredibly cute kitten."
},
{
"type": "image",
"title": {
"type": "plain_text",
"text": "Please enjoy this photo of a kitten"
},
"image_url": "http://placekitten.com/500/500",
"alt_text": "An incredibly cute kitten."
},
{
"type": "image",
"title": {
"type": "plain_text",
"text": "Please enjoy this photo of a kitten"
},
"image_url": "http://placekitten.com/500/500",
"alt_text": "An incredibly cute kitten."
}
]
}
Slack shows them like a separate blocks and doesn't combine them into a gallery:
slack screenshot - API
When I upload them using Slack app in one message - it combines them into a gallery:
slack screenshot - with gallery
I've tried blocks, attachments, third-party urls, permalinks after file.upload - the result is the same, Slack doesn't combine them into gallery.
So, the question is - how do I make it that Slack shows several images in a gallery?
UPD:
Just got an answer from Slack developers support:
slack dev support answer screenshot
Unfortunately, horizontal/gallery formatting of images is not possible
using the block kit builder. However, I'm going to go ahead and pass
your email on to our product team so that they can take this into
consideration for future updates.
Based on your comment,
[...] permalinks after file.upload [...]
this related answer might help (I also added this clarification there).
When uploading files and collecting their permalinks, you must link them in the text param in the message payload (putting them in a mrkdwn block in the blocks param will not work).
In javascript, this looks like:
const result1 = await web.files.upload({...})
const result2 = await web.files.upload({...})
await web.chat.postMessage({
text: `Here are files in a gallery view <${result1.file.permalink| ><${result2.file.permalink| >`,
...
})

Slack message "link button" not showing when URL contains underscore

I searched high and low but couldn't find a solution for this...
I'm designing a basic slack message with link buttons and found that the button will not show in the message when the host contains an 'underscore'...
You can try below example here: https://api.slack.com/docs/messages/builder
{
"text": "some text here...",
"attachments": [
{
"title": "TITLE",
"actions": [
{
"type": "button",
"text": "Link button",
"url": "https://www.some-site.com"
}
]
}
]
}
When you change www.some-site.com to www.some_site.com, the button disappears ...
Any suggestions on how to format the url so that the button shows up? According to the documentation, only the &, < and > characters need to be escaped, correct? I also tried encoding the URL, that didn't help either ... help?
This is a valid response from Slack, since www.some_site.com is not a valid URL.
You can not use underscores in hostnames, where hostname in your example is some-site. You can however use underscores in the label of a URL, so e.g. www_super.some-site.com should work.
Sources:
- https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names
- http://domainkeys.sourceforge.net/underscore.html

Open URL in browser from Message Button using Slack API

I am sending the users a slack message with a button through a Slack App. On every click of the button, I generate a new URL.
At the moment, I am able to return the URL back as a message. The user clicks on the message to open the URL in the browser.
Instead of the sending a message back, I want to open the URL directly in the browser using slack API.
How can I accomplish it? I can't seem to find anything in the documentation that does that.
Thanks
PS: Google Drive integration does that already.
It appears Slack introduced this feature recently.
As documented in https://api.slack.com/docs/message-attachments#link_buttons
"actions": [
{
"type": "button",
"text": "Book flights 🛫",
"url": "https://flights.example.com/book/r123456"
}
It's possible to preview in Slack's interactive message builder
Unfortunately slack does not support opening urls from message buttons.
You can monitor what slack is planning on releasing here though: https://trello.com/b/ZnTQyumQ/slack-platform-roadmap-for-developers :)
According to Slack, message attachments is the "old way" of composing messages, which will be deprecated in favour of the new Block Kit API.
I found this example on how to do button links on their docs, using the actions object in the message payload.
I haven't implemented it yet, but you can send the message to a channel in your workspace straight from the docs and try it, and it does open the link in the browser as expected.
Update 04/2022
{
"blocks": [
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View",
"emoji": true
},
"style": "primary",
"url": "https://flights.example.com/book/r123456"
}
]
}
]
}
Test on Slack Blockit Builder: Link

Button/Link inside UILabel to switch to another ViewController

I want to show some Facebook posts inside my iOS app. I get the whole post as a JSON-object from the Graph API. Works pretty fine.
So, if a user makes a new post and tags any page inside this post, the user-id (or page-id) is also included in that JSON object, giving me the offset and length inside the text, which should link to that page. (Sounds weird, so let me give you an example):
{
"id": "135416986571191_709831435796407",
"from": {
"category": "Musician/band",
"name": "DANNIC",
"id": "135416986571191"
},
"to": {
"data": [
{
"category": "Musician/band",
"name": "Tom & Jame",
"id": "423531801036780"
},
{
"category": "Record label",
"name": "Revealed Recordings",
"id": "104563552952573"
}
]
},
"message": "Wait For You (Tom & Jame Remix) is coming out in 2 days on Revealed Recordings!",
"message_tags": {
"14": [
{
"id": "423531801036780",
"name": "Tom & Jame",
"type": "page",
"offset": 14,
"length": 10
}
],
"59": [
{
"id": "104563552952573",
"name": "Revealed Recordings",
"type": "page",
"offset": 59,
"length": 19
}
]
},
"picture": "https://fbcdn-vthumb-a.akamaihd.net/hvthumb-ak-xfa1/v/t15.0-10/10876067_709831642463053_709831435796407_64260_924_b.jpg?oh=49c825ff152d98de125820093b5cff05&oe=5551397E&__gda__=1431085295_7c41923cf64cc0946a39e85b705ee691",
....
....
As you can see, there is the "message_tags", which contains two page-ids, the name and offset and length. I want to replace the text in the "message" with a UIButton or just a link to that page. How can I do that?
Here is a screenshot of that post how it looks inside the Facebook App:
As you can see, the "Tom & Jame" is clickable and the rest (except "Revealed Recordings") is normal text. If you tap on 'Tom & Jame' it will switch to another View Controller showing the page of them. That's exactly what I want inside my app.
I know I could use an NSAttributedText for my label, and use the NSLinkAttributedName to make the text clickable. But I don't want my app to switch to safari and open the facebook page, I want to stay inside my app and just switch to another UIViewController, showing the infos of that page etc.
Can I use my app's url scheme for that link, even though I stay inside my app? Or can I put a UIButton inside that label and handle the tap inside my view controller?
Whats the best solution for that? Any help is appreciated! :)
What I would do is put the text in a UITextView and use NSAttributedText. I would construct the URLs in a manner that I could parse later (just enough to get UITextView to render a link, but it doesn't have to be a real URL on facebook).
Then I would override shouldInteractWithURL which is sent to the delegate of UITextView. Here, I could re-parse the URL, retrieve the data, and load my subsequent view controller.
Take a look at the reference here: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextViewDelegate_Protocol/index.html#//apple_ref/occ/intfm/UITextViewDelegate/textView:shouldInteractWithURL:inRange:

How to get "Project Id" to create a Direct Link?

I have my project name, but not the numeric Project Id. The latter is needed to use HTML Direct Links.I'm using JIRA 5.0.1
How do I get the numeric Project Id for a given project name?
I've searched the Project Administration area, several other places, the documentation, Google, etc but still can't find a way to get that value.
Thanks.
This solution does not require admin rights:
Navigate to https://jira.YOURDOMAIN.TLD/rest/api/2/project/YOURPROJECTNAME and read the id in the JSON response:
{
"self":"https://jira.YOURDOMAIN.TLD/rest/api/2/project/YOURPROJECTNAME",
"id":"12345", ☜ Project Id
"key":"YOURPROJECTNAME",
"description":..
:
}
Navigate to https://jira.YOURDOMAIN.TLD/rest/api/2/project to get a JSON list of projects.
Bonus: here's a one-liner in Groovy to get the ID:
groovy -e "println new groovy.json.JsonSlurper().parseText("https://jira.YOURDOMAIN.TLD/rest/api/2/project/YOURPROJECTNAME".toURL().text)?.id ?: 'not found'"
A java.io.FileNotFoundException probably means that your JIRA server requires authentication.
Here's a one-liner to list all the visible projects and their ID:
groovy -e "new groovy.json.JsonSlurper().parseText('https://jira.YOURDOMAIN.TLD/rest/api/2/project'.toURL().text)?.each{println it.key+' = '+it.id}"
The easiest way is to do it from the web browser:
Go to the Administration page.
Select the Project from the menu.
Hover over 'Edit Project' link and check the link href (in the status bar).
It should be something like http://servername:8080/secure/project/EditProject!default.jspa?pid=10040
Where pid is the id you are looking for.
For Jira 6.x:
place the cursor on EDIT Project button and
look at the url being redirected at bottom left of the screen
This solution doesn't require admin rights and shows you all of the projects the current user can view.
https://example.com/rest/api/2/project
Responses found here.
https://docs.atlassian.com/jira/REST/latest/#d2e4972
returns a json array.
[
{
"self": "http://www.example.com/jira/rest/api/2/project/EX",
"id": "10000",
"key": "EX",
"name": "Example",
"avatarUrls": {
"24x24": "http://www.example.com/jira/secure/projectavatar?size=small&pid=10000",
"16x16": "http://www.example.com/jira/secure/projectavatar?size=xsmall&pid=10000",
"32x32": "http://www.example.com/jira/secure/projectavatar?size=medium&pid=10000",
"48x48": "http://www.example.com/jira/secure/projectavatar?size=large&pid=10000"
},
"projectCategory": {
"self": "http://www.example.com/jira/rest/api/2/projectCategory/10000",
"id": "10000",
"name": "FIRST",
"description": "First Project Category"
}
},
{
"self": "http://www.example.com/jira/rest/api/2/project/ABC",
"id": "10001",
"key": "ABC",
"name": "Alphabetical",
"avatarUrls": {
"24x24": "http://www.example.com/jira/secure/projectavatar?size=small&pid=10001",
"16x16": "http://www.example.com/jira/secure/projectavatar?size=xsmall&pid=10001",
"32x32": "http://www.example.com/jira/secure/projectavatar?size=medium&pid=10001",
"48x48": "http://www.example.com/jira/secure/projectavatar?size=large&pid=10001"
},
"projectCategory": {
"self": "http://www.example.com/jira/rest/api/2/projectCategory/10000",
"id": "10000",
"name": "FIRST",
"description": "First Project Category"
}
}
]
Exporting a ticket in XML reveals the project ID for me. I am not admin, so can't access the admin page. The rest/json trick didn't work for me, either. The XML of an issue has the following,
<project id="1234" key="test">TEST Project</project>

Resources