Modules@robinpath/slack
slack

@robinpath/slack

0.1.1Node.jsPublic

Slack Web API and Incoming Webhooks client for messaging, channels, reactions, file uploads, and user management

Slack

Slack Web API and Incoming Webhooks client for messaging, channels, reactions, file uploads, and user management

Package: @robinpath/slack | Category: Messaging | Type: Integration

Authentication

slack.setToken "default" "xoxb-your-token" {"defaultChannel": "general"}

Call this once at the start of your script before using any other function. Credentials persist for the duration of the script execution.

Use Cases

Use the slack module when you need to:

  • Send a message to a Slack channel via chat.postMessage -- Use slack.send to perform this operation
  • Send a message via a Slack Incoming Webhook URL (no token needed) -- Use slack.sendWebhook to perform this operation
  • Reply to a message thread via chat.postMessage with thread_ts -- Use slack.reply to perform this operation
  • Add an emoji reaction to a message via reactions.add -- Use slack.react to perform this operation
  • Upload a file to a Slack channel using the new file upload API -- Use slack.upload to perform this operation

Quick Reference

FunctionDescriptionReturns
setTokenStore a Slack Bot User OAuth Token for a workspace{workspaceId, defaultChannel}
sendSend a message to a Slack channel via chat.postMessage{ts, channel}
sendWebhookSend a message via a Slack Incoming Webhook URL (no token needed){ok, status}
replyReply to a message thread via chat.postMessage with thread_ts{ts, channel}
reactAdd an emoji reaction to a message via reactions.add{ok, channel, timestamp, emoji}
uploadUpload a file to a Slack channel using the new file upload API{ok, fileId, files}
listChannelsList Slack channels via conversations.listArray of {id, name, topic}
getHistoryGet message history for a channel via conversations.historyArray of message objects
setStatusSet the authenticated user's status via users.profile.set{ok, profile}
userInfoGet user information via users.info{id, name, real_name, email, is_admin}
createChannelCreate a new Slack channel via conversations.create{id, name, is_private}
updateMessageUpdate an existing message via chat.update{ts, channel, text}

Functions

setToken

Store a Slack Bot User OAuth Token for a workspace

Module: slack | Returns: object -- {workspaceId, defaultChannel}

slack.setToken "default" "xoxb-your-token" {"defaultChannel": "general"}
ParameterTypeRequiredDescription
workspaceIdstringYesWorkspace identifier (e.g. 'default')
tokenstringYesBot User OAuth Token (xoxb-...)
optionsobjectNo{defaultChannel?: string}

send

Send a message to a Slack channel via chat.postMessage

Module: slack | Returns: object -- {ts, channel}

slack.send "default" "#general" "Hello from RobinPath!"
ParameterTypeRequiredDescription
workspaceIdstringYesWorkspace identifier
channelstringYesChannel ID or name
textstringYesMessage text
optionsobjectNo{blocks?, unfurlLinks?, threadTs?}

sendWebhook

Send a message via a Slack Incoming Webhook URL (no token needed)

Module: slack | Returns: object -- {ok, status}

slack.sendWebhook "https://hooks.slack.com/services/T.../B.../xxx" "Deploy complete!"
ParameterTypeRequiredDescription
webhookUrlstringYesIncoming Webhook URL
textstringYesMessage text
optionsobjectNo{username?, iconEmoji?, blocks?}

reply

Reply to a message thread via chat.postMessage with thread_ts

Module: slack | Returns: object -- {ts, channel}

slack.reply "default" "C01234" "1234567890.123456" "Got it, thanks!"
ParameterTypeRequiredDescription
workspaceIdstringYesWorkspace identifier
channelstringYesChannel ID
threadTsstringYesParent message timestamp
textstringYesReply text
optionsobjectNo{blocks?, unfurlLinks?}

react

Add an emoji reaction to a message via reactions.add

Module: slack | Returns: object -- {ok, channel, timestamp, emoji}

slack.react "default" "C01234" "1234567890.123456" "thumbsup"
ParameterTypeRequiredDescription
workspaceIdstringYesWorkspace identifier
channelstringYesChannel ID
timestampstringYesMessage timestamp
emojistringYesEmoji name (e.g. 'thumbsup' or ':thumbsup:')

upload

Upload a file to a Slack channel using the new file upload API

Module: slack | Returns: object -- {ok, fileId, files}

slack.upload "default" "C01234" "./report.pdf" {"title": "Report", "initialComment": "Here is the report"}
ParameterTypeRequiredDescription
workspaceIdstringYesWorkspace identifier
channelstringYesChannel ID to share the file in
filePathstringYesLocal path to the file
optionsobjectNo{title?, initialComment?}

listChannels

List Slack channels via conversations.list

Module: slack | Returns: array -- Array of {id, name, topic}

slack.listChannels "default" {"limit": 50}
ParameterTypeRequiredDescription
workspaceIdstringYesWorkspace identifier
optionsobjectNo{types?, limit?}. types: 'public_channel,private_channel'

getHistory

Get message history for a channel via conversations.history

Module: slack | Returns: array -- Array of message objects

slack.getHistory "default" "C01234" {"limit": 10}
ParameterTypeRequiredDescription
workspaceIdstringYesWorkspace identifier
channelstringYesChannel ID
optionsobjectNo{limit?, oldest?, latest?}

setStatus

Set the authenticated user's status via users.profile.set

Module: slack | Returns: object -- {ok, profile}

slack.setStatus "default" "Working from home" ":house_with_garden:"
ParameterTypeRequiredDescription
workspaceIdstringYesWorkspace identifier
textstringYesStatus text
emojistringYesStatus emoji (e.g. ':house_with_garden:')
optionsobjectNo{expiration?: number} — Unix timestamp when status expires

userInfo

Get user information via users.info

Module: slack | Returns: object -- {id, name, real_name, email, is_admin}

slack.userInfo "default" "U01234ABC"
ParameterTypeRequiredDescription
workspaceIdstringYesWorkspace identifier
userIdstringYesSlack user ID (e.g. 'U01234')

createChannel

Create a new Slack channel via conversations.create

Module: slack | Returns: object -- {id, name, is_private}

slack.createChannel "default" "project-updates" {"isPrivate": true}
ParameterTypeRequiredDescription
workspaceIdstringYesWorkspace identifier
namestringYesChannel name (lowercase, no spaces)
optionsobjectNo{isPrivate?: boolean}

updateMessage

Update an existing message via chat.update

Module: slack | Returns: object -- {ts, channel, text}

slack.updateMessage "default" "C01234" "1234567890.123456" "Updated message text"
ParameterTypeRequiredDescription
workspaceIdstringYesWorkspace identifier
channelstringYesChannel ID
tsstringYesTimestamp of the message to update
textstringYesNew message text
optionsobjectNo{blocks?}

Error Handling

All functions throw on failure. Common errors:

ErrorCause
Token is requiredCheck the error message for details
Channel is requiredCheck the error message for details
Webhook URL is requiredCheck the error message for details
Webhook request failed (${response.status}): ${errText}Check the error message for details
Thread timestamp (threadTs) is requiredCheck the error message for details
Message timestamp is requiredCheck the error message for details
Emoji name is requiredCheck the error message for details
File path is requiredCheck the error message for details
@desc "Send and validate result"
do
  set $result as slack.send "default" "#general" "Hello from RobinPath!"
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. List and iterate Channels

Retrieve all items and loop through them.

@desc "Setup authentication"
do
  slack.setToken $token
enddo

@desc "List channels and iterate results"
do
  set $result as slack.listChannels "default" {"limit": 50}
  each $item in $result
    print $item
  end
enddo

2. Create a new item with send

Create a new resource and capture the result.

@desc "Setup authentication"
do
  slack.setToken $token
enddo

@desc "Send"
do
  set $result as slack.send "default" "#general" "Hello from RobinPath!"
  print "Created: " + $result
enddo

3. Create and update workflow

Create an item and then update it.

@desc "Setup authentication"
do
  slack.setToken $token
enddo

@desc "Send and update message"
do
  set $created as slack.send "default" "#general" "Hello from RobinPath!"
  # Update the created item
  slack.updateMessage "default" "C01234" "1234567890.123456" "Updated message text"
enddo

4. Check before creating

List existing items and only create if needed.

@desc "Setup authentication"
do
  slack.setToken $token
enddo

@desc "List channels and send"
do
  set $existing as slack.listChannels "default" {"limit": 50}
  if $existing == null
    slack.send "default" "#general" "Hello from RobinPath!"
    print "Item created"
  else
    print "Item already exists"
  end
enddo

5. Multi-step Slack workflow

Chain multiple slack operations together.

@desc "Setup authentication"
do
  slack.setToken $token
enddo

@desc "Send, send webhook, and more"
do
  set $r_send as slack.send "default" "#general" "Hello from RobinPath!"
  set $r_sendWebhook as slack.sendWebhook "https://hooks.slack.com/services/T.../B.../xxx" "Deploy complete!"
  set $r_reply as slack.reply "default" "C01234" "1234567890.123456" "Got it, thanks!"
  print "All operations complete"
enddo

6. Safe send with validation

Check results before proceeding.

@desc "Setup authentication"
do
  slack.setToken $token
enddo

@desc "Send and validate result"
do
  set $result as slack.send "default" "#general" "Hello from RobinPath!"
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • discord -- Discord module for complementary functionality
  • teams -- Teams module for complementary functionality
  • telegram -- Telegram module for complementary functionality
  • whatsapp -- WhatsApp module for complementary functionality
  • json -- JSON module for complementary functionality

Versions (1)

VersionTagPublished
0.1.1latest1 months ago
Install
$ robinpath add @robinpath/slack

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.1
LicenseMIT
Unpacked Size7.2 KB
Versions1
Weekly Downloads46
Total Downloads46
Stars0
Last Publish1 months ago
Created1 months ago