Using Slack slash command to run local app - slack

I want to write a Slack command to open Skype For Business (SfB).
The command will be something along the lines of:
/sfb my.colleague#company.com
SfB recognises the sip protocol, so I can type sip:my.colleague#company.com in my browser and it will open a conversation with my colleague in SfB.
However, on inspection of the Slack Integration pages, it seems that commands have to call a public url starting with http://.
There is an official Skype command for Slack, so I assume that what I'm trying to do is possible, and I'm just missing a step.

Slash commands work a bit differently.
Once a users issues your slash command, the request URL you specified will receive a special HTTP POST request from Slack (see here). You need an app running on that request URL (e.g. a Python script) that understands the format of the the slash request coming from Slack. And that URL needs to be reachable from the public Internet.
You can however open URLs on your local browser through Slack, albeit not in one step. Here is how it could work:
Use enters slash command
App responds with a message containing text link or link button, with your sip link.
User clicks on the link

Related

Slack slash command: Respond as user, not app

When sending the response to a Slack slash command, I would like to send it under the user that has launched the slach command.
I have created a Slack app with a slash command. It calls my Flask webservice and I use the "response_url" webhook to write something back to the channel. The response in the channel is given by my app. This works as expected. But I would like for the response to be displayed as if a user has given it.
An example would be the Slack plugin from giphy. If I call it, I get an ephemeral message to choose the gif I would like. But then it is posted in the channel under my name.
So I have 2 questions:
How does the API call look like to respond to the slash command as a specific user?
What permissions for my app are required to allow for such behaviour of the app?
The Slack API documentation is comprehensive, but much research didn't yield the result I wanted.
Thanks!
When you are using response_url, you can't customize your username or icon. For this, you'll need to use chat.postMessage API method. There are now two ways to achieve what you need here:
Use user token: This gives you access to take actions on the behalf of the user. Although, you'll need to take authorization from every user you want post the message as.
Request chat:write.customize scope with your bot token: You can post a message with icon_url and username parameters where you can provide the user's icon and name respectively for both the parameters. This is much easier, as this only requires one-time authorization.
More information in the official documentation.

Trigger slack commands programmatically from slack app [duplicate]

I'm writing a simple slack bot which should execute other slack commands upon being called. Everything is up and running, however the slack commands this bot issues don't seem to be executed.
For instance my bot posts /giphy kitten every hour and the message appears just like that in the channel (so the sending side seems to work), but the slash command itself isn't executed. If I post the same command into the same channel myself it works as expected. Are bots not allowed to execute slash commands?
Bots can use the undocumented API method chat.command to invoke slash commands.
See here for an unofficial documentation page of this API method.
This question was also answered here.
The command chat.command needs the permission scope post, which only legacy tokens have and which is not available for Slack apps.
I just asked the Slack customer support if sending slash commands programmatically is still possible and received the following reply:
I'm afraid not. Slash commands can only be triggered by human-sent
messages from the client. Apologies.

Send message to another slack bot [duplicate]

I'm writing a simple slack bot which should execute other slack commands upon being called. Everything is up and running, however the slack commands this bot issues don't seem to be executed.
For instance my bot posts /giphy kitten every hour and the message appears just like that in the channel (so the sending side seems to work), but the slash command itself isn't executed. If I post the same command into the same channel myself it works as expected. Are bots not allowed to execute slash commands?
Bots can use the undocumented API method chat.command to invoke slash commands.
See here for an unofficial documentation page of this API method.
This question was also answered here.
The command chat.command needs the permission scope post, which only legacy tokens have and which is not available for Slack apps.
I just asked the Slack customer support if sending slash commands programmatically is still possible and received the following reply:
I'm afraid not. Slash commands can only be triggered by human-sent
messages from the client. Apologies.

Icinga Notification in Slack Containing URL

I have integrated Slack with our Icinga (Nagios based) monitoring and we are sending notifications from icinga to slack channels
In icinga notification's service description field we are including a URL for the monitoring page for that particular notification as HTML code but the problem is Slack is not respecting the html code and is displaying the URL as a text.
Any idea how can I make the links URL (Clickable)
We are transitioning from hip-chat to slack and I have different possibilities of escaping char, putting in direct URL but none worked
Below is the notification with direct URL in service description
SS ABC Integration - application-test- app/'http://monitoringhost.com/icinga/cgi-bin/extinfo.cgi?type=2&host=hostserver&service=Load Average per CPU' Load Average per CPU on hostserver is OK
Below is with html code in the services description
hostnameB/<a href='http://monitoringhost.com/icinga/cgi-bin/extinfo.cgi?type=2&host=hostnameB&service=SS Test Application-Demo-Sub - Last Submission Status'>SS Test Application-Demo-Sub - Last Submission Status on hostnameB</a> is OK
We want the URL to be clickable
To make a piece of text function as a link, you can send it to the API as
<http://www.foo.com|Link to foo>[1].
The system will also automatically detect URLs that are simply inserted, so if you sent -
Hey, have you seen http://www.foo.com ?, it would automatically make the URL a link.
Hope that helps!
[1] https://api.slack.com/docs/message-formatting#linking_to_urls
Figure out that the script is sending all of the available variables to the slack and slack is app is picking just a few of them....
We ended up writing our own notification script; which only sends a few variables as an attachment to slack

Slack polls with HTTP Response

I'm trying to have my backend create a poll for a given user and when the user responds to the poll receive the response on the backend. However I cannot find a way to do the second part with an API available.
I know I can use Incoming Webhooks to send a command to users slackbot channel: /poll .. ... ... however I'm unsure how to receive a response from when user selects one of the options in the poll.
OK, one approach would be
Slash command for the /pollcommand, it will send a request to your app every time a user enters the command
Your app can then sends the actual message containing the poll details back to the channel incl. message menus simply by responding to the slash request or with Web API e.g. chat.PostMessage
User chooses polls option from message menus. Chosen option is send back to your app by Slack.
This is just one approach. Alternatively you could also show the options as message buttons or open a Dialog for the user.
I would advise against using outgoing webhooks, since its no longer part of the main features (and slash commands and interactive menus will send a request directly to your app anyway). Also Web API / chat.PostMessage is better than Incoming webhooks.

Resources