Esteban Vargas
Esteban Vargas

Reputation: 594

How to make Slack app send a private message via an incoming webhook to someone specific?

I created a Slack app that sends a series of interactive messages to a channel. In my Slack API dashboard, I see that I can create and remove hooks. Right now the hook url that I have set up in my code is the one for the Slackbot channel.

But the problem is that such a message only gets sent to me.

I want to send the Slackbot messages to Alice in situation A, and to Bob in situation B. Not just to myself, the guy who configured the app.

What's the best way to do this?

Upvotes: 1

Views: 1976

Answers (1)

Aditya Rao
Aditya Rao

Reputation: 108

I would suggest that you should not use hooks for this. A more sane way to do this right would be via chat.postMessage Web API method which is documented here!

This is because hooks are tied to specific conversations and that approach quickly hits a wall on what it can really achieve, especially messaging different people. Once you start using the web API it's pretty simple. Just ask for the scope during app installation (remember to add that scope in your dashboard), subscribe to the event in your API dashboard and then you are good to go.

Everytime you send a message via that method, Slack will send you a payload which you can use for testing and logging etc.

You can see all the different ways to message programmatically inside Slack here.

Upvotes: 4

Related Questions