• Builds
  • latest 0.0.14 / 2018-04-19
  • Created 2017-12-18
  • Last modified 2018-09-12
  • grade 1


This act search on stackoverflow site for definied query and send them to your slack channel. Example of input: { "searchStrings": ["created:1d apify","created:1d crawler javascript"], "slackBotToken": "dhU6k07zhfFhBk0Kh" } Easy slack bot set up: - Go to and click on Create Slack app - Set up App name and slack channel as workspace - Go to your created app then go to Bot Users and set up name for your slack bot - Go to OAuth & Permissions and copy your OAuth Access Token and put in into input of this act (slackBotToken)


To run the actor, send a HTTP POST request to:<YOUR_API_TOKEN>

The POST payload will be passed as input for the actor. For more information, read the docs.

Example input

Content type: application/json; charset=utf-8

  "searchStrings": ["created:1d apify","created:1d crawler javascript"],
  "slackBotToken": "dhU6k07zhfFhBk0Kh"

Source code

Based on the apify/actor-node-puppeteer Docker image (see docs).

const Apify = require('apify');
const Slack = require('slack');

Apify.main(async () => {
    // Get input of your act
    const input = await Apify.getValue('INPUT');
    console.log('My input:');
    const slackBotToken = input.slackBotToken || process.env.SLACK_BOT_TOKEN;
    if (!input) throw new Error('Invalid input, must be JSON object!');
    if (!slackBotToken) throw new Error('Invalid input, slackBotToken is missing in input or env var!');
    if (!input.searchStrings) throw new Error('Invalid input, searchStrings is missing!');
    // Crawl pages for data
    console.log('Launching Puppeteer...');
    const browser = await Apify.launchPuppeteer();
    const results = [];

    for (const search of input.searchStrings) {
        const url = `${encodeURIComponent(search)}`;
        console.log(`Opening URL: ${url}`);
        const page = await browser.newPage();
        await page.goto(url);
        const questions = await page.$$eval('.search-result', (results) => {
            return => `- <${el.querySelector('.result-link a').href}|${el.querySelector('.result-link a').innerText}>`).join('\n');
        if (questions) results.push({ title: `search: ${search}`, text: questions })
        await new Promise(resolve => setTimeout(resolve, 5000))
    // Send results to slack
    if (results.length) {
        const bot = new Slack({ token: slackBotToken });
            channel: 'C5RMPH401',
            response_type: 'in_channel',
            text: 'Interesting stackoverflow questions:',
            attachments: results,
    console.log('My output:');
    await Apify.setValue('OUTPUT', results);