Working with Slack Bot

See: Basic Slack app setup

See Your Created Apps to get bot token

Initial Setup

$ echo 'export SLACK_BOT_TOKEN=xoxb-1234567890-1234567890123-abcdef1234567890' >> ~/.zshrc

Get Channel Info

A conversation object contains information about a channel-like thing in Slack. It might be a public channel, a private channel, a direct message, or a multi-person direct message.

$ curl -sF token=${SLACK_BOT_TOKEN} | jq .


Need to add some permission to list some channels type. See:

$ curl -s -F token=${SLACK_BOT_TOKEN} | jq '.channels[] | select(.is_archived != true and .is_channel == true and .is_private == false and .name_normalized == "note")'

List all private, public, channels, private groups and direct message

And filter with jq to get a specific channel

$ curl -sF token=${SLACK_BOT_TOKEN}\?types=public_channel,private_channel,mpim,im\&exclude_archived=true\&limit=200 | jq '.channels[] | select(.name == "test3")'

Get Channel Id

Use cursor and limit to get more result since the result is limited by 100 by default


$ curl -sF token=${SLACK_BOT_TOKEN}\?types=public_channel\&exclude_archived=true\&limit=500 | jq -r .response_metadata.next_cursor

$ curl -sF token=${SLACK_BOT_TOKEN}\?types=public_channel\&exclude_archived=true\&limit=500\&cursor=dGVhbTpDMTRBOU5LRUU= | jq -r '.channels[] | select(.name == "github-actions-test") | .id'

Related: Node.js: Slack API

Leave a Comment

Your email address will not be published. Required fields are marked *