Let AI write emails and messages for you 🔥

Send slack messages from the server for important events

Gourav Goyal

Gourav Goyal

Apr 11, 2023

You can send messages on a Slack channel whenever something important happens on the server. For example, new user payment received, some important API threw an error, user submitted some feedback, user was not able to log-in, payment issue, deployment errors, etc so that you could quickly act upon it. It’s also a good way to keep your team notified about it if your team already uses Slack. You can also have different Slack channels to get notified about critical errors, user feedback, etc.

Here’s how it looks:

Create a free Slack Bot that would send messages

They call it Slack App.

  • Go to Scopes → enter chat:write

Get Bot Token

Click “Install to Workspace”

  • Copy the Bot token

Get Channel ID to post to

Go to Channel info and copy “Channel ID”:

Add Bot to that Channel

Go to Channel “Integration” tab and add that Bot as app.

Send message to Slack channel as Bot

Here’s the Typescript snippet for it:

export async function sendSlackMessage(msg: string) {
  const response = await fetch("https://slack.com/api/chat.postMessage", {
    method: "POST",
    headers: {
      "Content-Type": "application/json; charset=utf-8",
      Authorization: `Bearer ${SLACK_BOT_TOKEN}`,
    body: JSON.stringify({
      channel: CHANNEL_ID,
      text: msg,

  return response;
That's all, folks!

Gourav Goyal

Gourav Goyal