How to get the all the channels in Slack workspace with conversation.list API?2019 Community Moderator ElectionHow do I get started with Node.jsHow do you get a list of the names of all files present in a directory in Node.js?How do I get the path to the current script with Node.js?How to get GET (query string) variables in Express.js on Node.js?Slack URL to open a channel from browserSlack clean all messages (~8K) in a channelHow to set slack reminder for private channelSlack API to get applications installed in a workspaceSlack API : Ability to view all recently added users to Slack ChannelSlack API to get available workspaces
How do anti-virus programs start at Windows boot?
What does it mean when multiple 々 marks follow a 、?
Is it illegal in Germany to take sick leave if you caused your own illness with food?
Extension of Splitting Fields over An Arbitrary Field
Need some help with my first LaTeX drawing…
Is it ok to include an epilogue dedicated to colleagues who passed away in the end of the manuscript?
Is all copper pipe pretty much the same?
Time travel short story where dinosaur doesn't taste like chicken
Replacing Windows 7 security updates with anti-virus?
Is "history" a male-biased word ("his+story")?
Co-worker team leader wants to inject the crap software product of his friends into our development. What should I say to our common boss?
Deleting missing values from a dataset
How to deal with a cynical class?
When two POV characters meet
Life insurance that covers only simultaneous/dual deaths
How is the Swiss post e-voting system supposed to work, and how was it wrong?
What is the dot in “1.2.4."
Confusion with the nameplate of an induction motor
It's a yearly task, alright
Latest web browser compatible with Windows 98
Force user to remove USB token
Single word request: Harming the benefactor
Does Linux have system calls to access all the features of the file systems it supports?
What has been your most complicated TikZ drawing?
How to get the all the channels in Slack workspace with conversation.list API?
2019 Community Moderator ElectionHow do I get started with Node.jsHow do you get a list of the names of all files present in a directory in Node.js?How do I get the path to the current script with Node.js?How to get GET (query string) variables in Express.js on Node.js?Slack URL to open a channel from browserSlack clean all messages (~8K) in a channelHow to set slack reminder for private channelSlack API to get applications installed in a workspaceSlack API : Ability to view all recently added users to Slack ChannelSlack API to get available workspaces
When I paginate through next_cursor, I get a different number of channels every time I hit the URL through NodeJS function.
Once the total channels fetched is 7488 another time it is 300. It differs every time I run the program.
URL : https://slack.com/api/conversations.list?types=public_channel&cursor=cursor=&exclude_archived=true&token=token
The issue is due to the rate limit of slack. conversation.list comes under tier 2 rate limit. That is only maximum 20 requests per minute.
function fetchData(){
getResponse(url);
function getResponse(url)
let tempData = '';
https.get(url, (resp) =>
resp.on('data', (chunk) =>
tempData += chunk;
);
resp.on('end', () =>
try
tempData = JSON.parse(tempData);
if(tempData.channels)
resultData.push(tempData.channels);
if (tempData.response_metadata && tempData.response_metadata.next_cursor)
if(tempData.response_metadata.next_cursor === '')
return resultData;
let cursorIndex = url.indexOf('cursor');
let newUrl = url.slice(0,cursorIndex);
let token = apiConstants.SLACK_API['ACCESS_TOKEN'];
let nextCursor = tempData.response_metadata.next_cursor.slice(0,tempData.response_metadata.next_cursor.length-1);
nextCursor = nextCursor + "%3D";
newUrl = newUrl + 'cursor=' + nextCursor + '&token='+ token;
getResponse(newUrl);
else
return resultData;
catch(err) console.log(err);
node.js slack slack-api
New contributor
add a comment |
When I paginate through next_cursor, I get a different number of channels every time I hit the URL through NodeJS function.
Once the total channels fetched is 7488 another time it is 300. It differs every time I run the program.
URL : https://slack.com/api/conversations.list?types=public_channel&cursor=cursor=&exclude_archived=true&token=token
The issue is due to the rate limit of slack. conversation.list comes under tier 2 rate limit. That is only maximum 20 requests per minute.
function fetchData(){
getResponse(url);
function getResponse(url)
let tempData = '';
https.get(url, (resp) =>
resp.on('data', (chunk) =>
tempData += chunk;
);
resp.on('end', () =>
try
tempData = JSON.parse(tempData);
if(tempData.channels)
resultData.push(tempData.channels);
if (tempData.response_metadata && tempData.response_metadata.next_cursor)
if(tempData.response_metadata.next_cursor === '')
return resultData;
let cursorIndex = url.indexOf('cursor');
let newUrl = url.slice(0,cursorIndex);
let token = apiConstants.SLACK_API['ACCESS_TOKEN'];
let nextCursor = tempData.response_metadata.next_cursor.slice(0,tempData.response_metadata.next_cursor.length-1);
nextCursor = nextCursor + "%3D";
newUrl = newUrl + 'cursor=' + nextCursor + '&token='+ token;
getResponse(newUrl);
else
return resultData;
catch(err) console.log(err);
node.js slack slack-api
New contributor
I think it would be helpful if you'd add the relevant part of your code in full - not just one line / URL.
– Erik Kalkoken
Mar 7 at 10:51
add a comment |
When I paginate through next_cursor, I get a different number of channels every time I hit the URL through NodeJS function.
Once the total channels fetched is 7488 another time it is 300. It differs every time I run the program.
URL : https://slack.com/api/conversations.list?types=public_channel&cursor=cursor=&exclude_archived=true&token=token
The issue is due to the rate limit of slack. conversation.list comes under tier 2 rate limit. That is only maximum 20 requests per minute.
function fetchData(){
getResponse(url);
function getResponse(url)
let tempData = '';
https.get(url, (resp) =>
resp.on('data', (chunk) =>
tempData += chunk;
);
resp.on('end', () =>
try
tempData = JSON.parse(tempData);
if(tempData.channels)
resultData.push(tempData.channels);
if (tempData.response_metadata && tempData.response_metadata.next_cursor)
if(tempData.response_metadata.next_cursor === '')
return resultData;
let cursorIndex = url.indexOf('cursor');
let newUrl = url.slice(0,cursorIndex);
let token = apiConstants.SLACK_API['ACCESS_TOKEN'];
let nextCursor = tempData.response_metadata.next_cursor.slice(0,tempData.response_metadata.next_cursor.length-1);
nextCursor = nextCursor + "%3D";
newUrl = newUrl + 'cursor=' + nextCursor + '&token='+ token;
getResponse(newUrl);
else
return resultData;
catch(err) console.log(err);
node.js slack slack-api
New contributor
When I paginate through next_cursor, I get a different number of channels every time I hit the URL through NodeJS function.
Once the total channels fetched is 7488 another time it is 300. It differs every time I run the program.
URL : https://slack.com/api/conversations.list?types=public_channel&cursor=cursor=&exclude_archived=true&token=token
The issue is due to the rate limit of slack. conversation.list comes under tier 2 rate limit. That is only maximum 20 requests per minute.
function fetchData(){
getResponse(url);
function getResponse(url)
let tempData = '';
https.get(url, (resp) =>
resp.on('data', (chunk) =>
tempData += chunk;
);
resp.on('end', () =>
try
tempData = JSON.parse(tempData);
if(tempData.channels)
resultData.push(tempData.channels);
if (tempData.response_metadata && tempData.response_metadata.next_cursor)
if(tempData.response_metadata.next_cursor === '')
return resultData;
let cursorIndex = url.indexOf('cursor');
let newUrl = url.slice(0,cursorIndex);
let token = apiConstants.SLACK_API['ACCESS_TOKEN'];
let nextCursor = tempData.response_metadata.next_cursor.slice(0,tempData.response_metadata.next_cursor.length-1);
nextCursor = nextCursor + "%3D";
newUrl = newUrl + 'cursor=' + nextCursor + '&token='+ token;
getResponse(newUrl);
else
return resultData;
catch(err) console.log(err);
node.js slack slack-api
node.js slack slack-api
New contributor
New contributor
edited Mar 7 at 17:48
Swaathi
New contributor
asked Mar 7 at 10:09
SwaathiSwaathi
62
62
New contributor
New contributor
I think it would be helpful if you'd add the relevant part of your code in full - not just one line / URL.
– Erik Kalkoken
Mar 7 at 10:51
add a comment |
I think it would be helpful if you'd add the relevant part of your code in full - not just one line / URL.
– Erik Kalkoken
Mar 7 at 10:51
I think it would be helpful if you'd add the relevant part of your code in full - not just one line / URL.
– Erik Kalkoken
Mar 7 at 10:51
I think it would be helpful if you'd add the relevant part of your code in full - not just one line / URL.
– Erik Kalkoken
Mar 7 at 10:51
add a comment |
1 Answer
1
active
oldest
votes
One way to do this reliably would be to use the Node Slack SDK's WebClient
, which has automatic pagination on cursor-paginated methods (like conversations.list
). It also automatically handles rate limits by queuing requests for the amount of time the responses from Slack indicate. Disclaimer: I work at Slack and contribute to this package.
The documentation covers the details of the automatic pagination support: https://slack.dev/node-slack-sdk/web_api#pagination. The first example could be used to get the complete list of channels if you simply replace web.conversations.history()
with web.conversations.list()
.
We don't recommend using this technique anymore, because its very rare that you actually need the whole list. In fact, automatic pagination will be removed in the next major version (v5.0.0) which will be released soon. But if this is really what you want to do (as indicated in your question), then you should look to the second example in that section. I've copied it below:
const WebClient = require('@slack/client');
// An access token (from your Slack app or custom integration - xoxp, or xoxb)
const token = process.env.SLACK_TOKEN;
const web = new WebClient(token);
async function getAllChannels(options)
async function pageLoaded(accumulatedChannels, res)
// Merge the previous result with the results in the current page
const mergedChannels = accumulatedChannels.concat(res.channels);
// When a `next_cursor` exists, recursively call this function to get the next page.
if (res.response_metadata && res.response_metadata.next_cursor && res.response_metadata.next_cursor !== '')
// Make a copy of options
const pageOptions = ...options ;
// Add the `cursor` argument
pageOptions.cursor = res.response_metadata.next_cursor;
return pageLoaded(mergedChannels, await web.conversations.list(pageOptions));
// Otherwise, we're done and can return the result
return mergedChannels;
return pageLoaded([], await web.conversations.list(options));
(async () =>
const allChannels = await getAllChannels( exclude_archived: true, types: 'public_channel' );
console.log(allChannels);
)();
PS. In version v5.0.0, we're planning to include a helper method that will make this much simpler. For now, the second example is the most forward-compatible way, and I recommend that you refactor it to use the helper once v5.0.0 is released.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Swaathi is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55041101%2fhow-to-get-the-all-the-channels-in-slack-workspace-with-conversation-list-api%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
One way to do this reliably would be to use the Node Slack SDK's WebClient
, which has automatic pagination on cursor-paginated methods (like conversations.list
). It also automatically handles rate limits by queuing requests for the amount of time the responses from Slack indicate. Disclaimer: I work at Slack and contribute to this package.
The documentation covers the details of the automatic pagination support: https://slack.dev/node-slack-sdk/web_api#pagination. The first example could be used to get the complete list of channels if you simply replace web.conversations.history()
with web.conversations.list()
.
We don't recommend using this technique anymore, because its very rare that you actually need the whole list. In fact, automatic pagination will be removed in the next major version (v5.0.0) which will be released soon. But if this is really what you want to do (as indicated in your question), then you should look to the second example in that section. I've copied it below:
const WebClient = require('@slack/client');
// An access token (from your Slack app or custom integration - xoxp, or xoxb)
const token = process.env.SLACK_TOKEN;
const web = new WebClient(token);
async function getAllChannels(options)
async function pageLoaded(accumulatedChannels, res)
// Merge the previous result with the results in the current page
const mergedChannels = accumulatedChannels.concat(res.channels);
// When a `next_cursor` exists, recursively call this function to get the next page.
if (res.response_metadata && res.response_metadata.next_cursor && res.response_metadata.next_cursor !== '')
// Make a copy of options
const pageOptions = ...options ;
// Add the `cursor` argument
pageOptions.cursor = res.response_metadata.next_cursor;
return pageLoaded(mergedChannels, await web.conversations.list(pageOptions));
// Otherwise, we're done and can return the result
return mergedChannels;
return pageLoaded([], await web.conversations.list(options));
(async () =>
const allChannels = await getAllChannels( exclude_archived: true, types: 'public_channel' );
console.log(allChannels);
)();
PS. In version v5.0.0, we're planning to include a helper method that will make this much simpler. For now, the second example is the most forward-compatible way, and I recommend that you refactor it to use the helper once v5.0.0 is released.
add a comment |
One way to do this reliably would be to use the Node Slack SDK's WebClient
, which has automatic pagination on cursor-paginated methods (like conversations.list
). It also automatically handles rate limits by queuing requests for the amount of time the responses from Slack indicate. Disclaimer: I work at Slack and contribute to this package.
The documentation covers the details of the automatic pagination support: https://slack.dev/node-slack-sdk/web_api#pagination. The first example could be used to get the complete list of channels if you simply replace web.conversations.history()
with web.conversations.list()
.
We don't recommend using this technique anymore, because its very rare that you actually need the whole list. In fact, automatic pagination will be removed in the next major version (v5.0.0) which will be released soon. But if this is really what you want to do (as indicated in your question), then you should look to the second example in that section. I've copied it below:
const WebClient = require('@slack/client');
// An access token (from your Slack app or custom integration - xoxp, or xoxb)
const token = process.env.SLACK_TOKEN;
const web = new WebClient(token);
async function getAllChannels(options)
async function pageLoaded(accumulatedChannels, res)
// Merge the previous result with the results in the current page
const mergedChannels = accumulatedChannels.concat(res.channels);
// When a `next_cursor` exists, recursively call this function to get the next page.
if (res.response_metadata && res.response_metadata.next_cursor && res.response_metadata.next_cursor !== '')
// Make a copy of options
const pageOptions = ...options ;
// Add the `cursor` argument
pageOptions.cursor = res.response_metadata.next_cursor;
return pageLoaded(mergedChannels, await web.conversations.list(pageOptions));
// Otherwise, we're done and can return the result
return mergedChannels;
return pageLoaded([], await web.conversations.list(options));
(async () =>
const allChannels = await getAllChannels( exclude_archived: true, types: 'public_channel' );
console.log(allChannels);
)();
PS. In version v5.0.0, we're planning to include a helper method that will make this much simpler. For now, the second example is the most forward-compatible way, and I recommend that you refactor it to use the helper once v5.0.0 is released.
add a comment |
One way to do this reliably would be to use the Node Slack SDK's WebClient
, which has automatic pagination on cursor-paginated methods (like conversations.list
). It also automatically handles rate limits by queuing requests for the amount of time the responses from Slack indicate. Disclaimer: I work at Slack and contribute to this package.
The documentation covers the details of the automatic pagination support: https://slack.dev/node-slack-sdk/web_api#pagination. The first example could be used to get the complete list of channels if you simply replace web.conversations.history()
with web.conversations.list()
.
We don't recommend using this technique anymore, because its very rare that you actually need the whole list. In fact, automatic pagination will be removed in the next major version (v5.0.0) which will be released soon. But if this is really what you want to do (as indicated in your question), then you should look to the second example in that section. I've copied it below:
const WebClient = require('@slack/client');
// An access token (from your Slack app or custom integration - xoxp, or xoxb)
const token = process.env.SLACK_TOKEN;
const web = new WebClient(token);
async function getAllChannels(options)
async function pageLoaded(accumulatedChannels, res)
// Merge the previous result with the results in the current page
const mergedChannels = accumulatedChannels.concat(res.channels);
// When a `next_cursor` exists, recursively call this function to get the next page.
if (res.response_metadata && res.response_metadata.next_cursor && res.response_metadata.next_cursor !== '')
// Make a copy of options
const pageOptions = ...options ;
// Add the `cursor` argument
pageOptions.cursor = res.response_metadata.next_cursor;
return pageLoaded(mergedChannels, await web.conversations.list(pageOptions));
// Otherwise, we're done and can return the result
return mergedChannels;
return pageLoaded([], await web.conversations.list(options));
(async () =>
const allChannels = await getAllChannels( exclude_archived: true, types: 'public_channel' );
console.log(allChannels);
)();
PS. In version v5.0.0, we're planning to include a helper method that will make this much simpler. For now, the second example is the most forward-compatible way, and I recommend that you refactor it to use the helper once v5.0.0 is released.
One way to do this reliably would be to use the Node Slack SDK's WebClient
, which has automatic pagination on cursor-paginated methods (like conversations.list
). It also automatically handles rate limits by queuing requests for the amount of time the responses from Slack indicate. Disclaimer: I work at Slack and contribute to this package.
The documentation covers the details of the automatic pagination support: https://slack.dev/node-slack-sdk/web_api#pagination. The first example could be used to get the complete list of channels if you simply replace web.conversations.history()
with web.conversations.list()
.
We don't recommend using this technique anymore, because its very rare that you actually need the whole list. In fact, automatic pagination will be removed in the next major version (v5.0.0) which will be released soon. But if this is really what you want to do (as indicated in your question), then you should look to the second example in that section. I've copied it below:
const WebClient = require('@slack/client');
// An access token (from your Slack app or custom integration - xoxp, or xoxb)
const token = process.env.SLACK_TOKEN;
const web = new WebClient(token);
async function getAllChannels(options)
async function pageLoaded(accumulatedChannels, res)
// Merge the previous result with the results in the current page
const mergedChannels = accumulatedChannels.concat(res.channels);
// When a `next_cursor` exists, recursively call this function to get the next page.
if (res.response_metadata && res.response_metadata.next_cursor && res.response_metadata.next_cursor !== '')
// Make a copy of options
const pageOptions = ...options ;
// Add the `cursor` argument
pageOptions.cursor = res.response_metadata.next_cursor;
return pageLoaded(mergedChannels, await web.conversations.list(pageOptions));
// Otherwise, we're done and can return the result
return mergedChannels;
return pageLoaded([], await web.conversations.list(options));
(async () =>
const allChannels = await getAllChannels( exclude_archived: true, types: 'public_channel' );
console.log(allChannels);
)();
PS. In version v5.0.0, we're planning to include a helper method that will make this much simpler. For now, the second example is the most forward-compatible way, and I recommend that you refactor it to use the helper once v5.0.0 is released.
answered Mar 10 at 2:26
AnkurAnkur
1,75521723
1,75521723
add a comment |
add a comment |
Swaathi is a new contributor. Be nice, and check out our Code of Conduct.
Swaathi is a new contributor. Be nice, and check out our Code of Conduct.
Swaathi is a new contributor. Be nice, and check out our Code of Conduct.
Swaathi is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55041101%2fhow-to-get-the-all-the-channels-in-slack-workspace-with-conversation-list-api%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I think it would be helpful if you'd add the relevant part of your code in full - not just one line / URL.
– Erik Kalkoken
Mar 7 at 10:51