1 min read

Send a message tagging yourself programmatically in a Slack channel

The shortest tutorial to start your Slack integration

Slack
Send a message tagging yourself programmatically in a Slack channel

Introduction

This is a quick guide to show how to send a message to yourself programmatically using cURL in Slack using the Slack API.

1. Create a Slack app

Create a Slack app

  • Enter a name and select the slack workspace you want to test the app:

Create a Slack app 2

2. Give permission to write messages:

Once created, you need to go to the “OAuth & Permissions” section and give the bot permission to write messages:

scope

3. Install the app in your slack workspace

Scroll up and click on “Install to {your workspace}” button to enable the bot in your slack workspace:

oauth_token

(You need to reinstall the app everytime you change permissions)

4. Create a channel where the bot will send messages:

Go to the “Channels” section in Slack:

create_channel

5. Get the channel id:

Once channel created, go to the channel details:

channel_details

Scroll down and copy the channel id:

channel_id

We will use the bot token to send a message to yourself:

bot_token

6. Test the integration by sending a message tagging yourself.

Go find your user id, by click on your profile in Slack:

user_id

Copy the user id:

user_id

Open your terminal and replace the $BOT_TOKEN with the bot token, the channel id “C09XXXXXX” and the user id “U09XXXXXX” with the ones you copied in the previous steps:

curl -X POST \
-H "Authorization: Bearer $BOT_TOKEN" \
-H "Content-Type: application/json" \
-d '{"channel": "C09XXXXXX", "text": "Hello, world! <@U09XXXXXX>"}' \
https://slack.com/api/chat.postMessage

You should see the message in the channel:

message