<commit_before>import Promise from 'bluebird'

const create = obj => {
  let resolve = null
  let reject = null
  const promise = new Promise((r, rj) => {
    resolve = r
    reject = rj
  })

  const messageId = new Date().toISOString() + Math.random()

  const newEvent = Object.assign(
    {
      _promise: promise,
      _resolve: resolve,
      _reject: reject,
      __id: messageId
    },
    obj
  )

  return newEvent
}

const validateChannelId = channelId => {
  if (!/\w+/.test(channelId)) {
    throw new Error('Invalid channel id')
  }
}

const validateText = text => {
  if (typeof text !== 'string') {
    throw new Error('Text must be a string.')
  }
}

const validateAttachments = attachments => {
  if (typeof attachments !== 'object') {
    throw new Error('Expected attachments type to be an object')
  }
}

const createText = (channelId, text, options = {}) => {
  validateChannelId(channelId)
  validateText(text)

  return create({
    platform: 'slack',
    type: 'text',
    text: text,
    raw: {
      channelId: channelId,
      options: options
    }
  })
}

const createAttachments = (channelId, attachments, options = {}) => {
  validateChannelId(channelId)
  validateAttachments(attachments)

  return create({
    platform: 'slack',
    type: 'attachments',
    text: 'App sent an attachments',
    raw: {
      channelId: channelId,
      attachments: attachments,
      options: options
    }
  })
}

const createReaction = (name, options = {}) => {
  return create({
    platform: 'slack',
    type: 'reaction',
    text: 'App sent a reaction',
    raw: {
      name: name,
      options: options
    }
  })
}

const createUpdateText = (ts, channelId, text, options = {}) => {
  validateChannelId(channelId)
  validateText(text)

  return create({
    platform: 'slack',<commit_msg>fix(slack): added callback_id to attachment (resolve #876)<commit_after>import Promise from 'bluebird'

const create = obj => {
  let resolve = null
  let reject = null
  const promise = new Promise((r, rj) => {
    resolve = r
    reject = rj
  })

  const messageId = new Date().toISOString() + Math.random()

  const newEvent = Object.assign(
    {
      _promise: promise,
      _resolve: resolve,
      _reject: reject,
      __id: messageId
    },
    obj
  )

  return newEvent
}

const validateChannelId = channelId => {
  if (!/\w+/.test(channelId)) {
    throw new Error('Invalid channel id')
  }
}

const validateText = text => {
  if (typeof text !== 'string') {
    throw new Error('Text must be a string.')
  }
}

const validateAttachments = attachments => {
  if (typeof attachments !== 'object') {
    throw new Error('Expected attachments type to be an object')
  }
}

const createText = (channelId, text, options = {}) => {
  validateChannelId(channelId)
  validateText(text)

  return create({
    platform: 'slack',
    type: 'text',
    text: text,
    raw: {
      channelId: channelId,
      options: options
    }
  })
}

const createAttachments = (channelId, attachments, options = {}) => {
  validateChannelId(channelId)
  validateAttachments(attachments)

  attachments = attachments.map(attachment => {
    if (attachment.callback_id) {
      return attachment
    }

    const defaultPrefix = attachment.text ? attachment.text.replace(/\s/g, '_') : 'slack_attachment'
    const defaultCallbackId = `${defaultPrefix}:${Date.now()}`

    return { ...attachment, callback_id: defaultCallbackId }
  })

  return create({
    platform: 'slack',
    type: 'attachments',
    text: 'App sent an attachments',
    raw: {
      channelId: channelId,
      attachments: attachments,
      options: options
    }
  })
}

const createReaction = (name, options = {}) => {
  return create({
    platform: 'slack',
    type: 'reaction',
    text: 'App sent a reaction',
    raw: {
      name: name,
      options: options
    }
  })
}

const createUpdateText = (ts, channelId, text, options = {}) => {
  validateChannelId(channelId)
  validateText(text)

  return create({
    platform: 'slack',
{'fraction_non_alphanumeric': 0.13133068520357497, 'fraction_numerical': 0.0007447864945382324, 'mean_word_length': 2.9772951628825273, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '673573', 'n_tokens_mistral': 1271, 'n_tokens_neox': 1247, 'n_words': 339}