Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a Slack Webhook programmatically

Is there a way I can use the Slack API to create an incoming and outgoing webhook for a channel I just created?

like image 305
masterforker Avatar asked Nov 01 '16 23:11

masterforker


People also ask

How do I create a webhook URL?

To set up a webhook, go to the settings page of your repository or organization. From there, click Webhooks, then Add webhook. Alternatively, you can choose to build and manage a webhook through the Webhooks API. Webhooks require a few configuration options before you can make use of them.

What is my Slack webhook URL?

You can get the "Webhook URL" from Slack by the following steps. 1. Open the "Apps & Custom Integrations" page in the Slack menu, enter "Incoming WebHooks" in the search box of the page, and click on the "Incoming WebHooks" item displayed.

How Webhooks work in Slack?

Incoming Webhooks are a simple way to post messages from apps into Slack. Creating an Incoming Webhook gives you a unique URL to which you send a JSON payload with the message text and some options. You can use all the usual formatting and layout blocks with Incoming Webhooks to make the messages stand out.

Is Slack webhook deprecated?

The legacy Incoming Webhook is deprecated and not recommended. The latest / recommended way is using Slack App or Incoming Webhooks in Slack App.


2 Answers

No, I do not think that feature exists, but you can just use any existing webhook with the newly created channel or use the Event API to get the same result.

Incoming Webhooks

You can redirect an incoming webhook to any channel by providing the channel name as parameter in your call. (see Channel override)

Outgoing Webhooks

Your existing outgoing webhook will work with any channel, as long as you use triger words when you created them. If that is not an option, I would recommend to look at the new Event API that would allow you to get the same functionality as with outgoing webhooks, but without having to provide a channel name in the first place. Check out the event types message.channels and message.groups.

like image 175
Erik Kalkoken Avatar answered Sep 25 '22 21:09

Erik Kalkoken


Generating Incoming Webhook URLs programmatically -

Incoming Webhooks can be easily generated during the standard OAuth install flow.

If you are going to distribute your app, it's likely you're already planning to use the OAuth process anyway.

  1. Change your scopes

  2. Grab Incoming Webhook URL from the OAuth Response

https://api.slack.com/messaging/webhooks#incoming_webhooks_programmatic

like image 26
Vivek Kumar Avatar answered Sep 21 '22 21:09

Vivek Kumar