Slack API Цвета - PullRequest
       67

Slack API Цвета

0 голосов
/ 14 марта 2019

В моем свободном рабочем пространстве более 2000 каналов, и я пытаюсь создать слабого бота с помощью Hubot, чтобы проверить, существует ли определенный канал, используя Slack API convocations.list.Я перебираю все каналы из API, чтобы посмотреть, соответствует ли он конкретному каналу, который я ищу.Тем не менее, я продолжаю получать сообщение «FATAL ERROR: неэффективные сжатые метки вблизи предела кучи. Выделение не удалось - куча JavaScript не хватает памяти».Знаете почему?

  robot.respond /test (.*)/i, (res) ->
    # SLACK API to get all channels
    request = require("request")
    fs = require("fs")

    channel_name = res.match[1]

    current_cursor = ''
    is_end = false


    while is_end == false
      opts = {
        method: 'GET',
        uri: 'https://slack.com/api/conversations.list',
        formData: {
          token: 'token',
          cursor: "#{current_cursor}",
          types: 'public_channel', 'private_channel',
        }
      }
      request.post opts, (error, httpRes, body) ->
        if error
          res.send "Slack API Error"
          return
        data = JSON.parse(body)

        # Iterates through the channel list to find the channel with the same name
        for channel in data.channels
          if channel.name == channel_name
            res.send "Exist"
            is_end = true
            return

        # Search the next page of data by storing the cursor
        current_cursor = data.response_metadata.next_cursor
        # If there is no more data, the cursor should be ''
        if current_cursor == ''
          is_end = true
          res.send "Channel name does not exist"
...