fahad_ansari
fahad_ansari

Reputation: 33

Send Hyperlink to call an api in Slack message

my question is very simple. I want to send a link/button with a slack message and when receiver click on that link it calls an api to perform some task. here is my code:

$msg = "hey! click to approve <a href='http://api2342.in/API/api.php'>Approve</a>";
self::sendSlackMessage($slackId,$msg);

I have this sendSlackMessage API to send a message to the Slack user which receives two parameters, and its working fine. I just need to figure out how to send a link to call an API to perform a certain task.

Upvotes: 2

Views: 3171

Answers (1)

Erik Kalkoken
Erik Kalkoken

Reputation: 32737

This is very easy to do, just use the correct syntax for links in messages, which is <http://www.foo.com|www.foo.com>.

So for your example:

$msg = "hey! click to approve <http://api2342.in/API/api.php|Approve>";

Check out the excellent official documentation for more information on how to use links with Slack.

Or if you want to improve your user experience use link buttons instead of a naked link.

Upvotes: 6

Related Questions