<commit_before>request = require "request"

class Slack
  constructor: (@token, @domain) ->
    @apiMode = unless @domain then true else false
    @url = @composeUrl()

  composeUrl: =>
    if @apiMode
      #retrun api url
      return "https://slack.com/api/"
    else
      #return web hook mode
      return "https://#{@domain}.slack.com/services/hooks/incoming-webhook?token=#{@token}"

  webhook: (options, callback) =>

    request.post
      url: @url 
      body: JSON.stringify
        channel: options.channel
        text: options.text
        username: options.username
        icon_url: options.icon_url || ""
        attachments: options.attachments
    , (err, body, response) ->
      if err or response isnt "ok"
        return callback err, null
      
      callback err, {
        ok: true
      }

  api: (method, options, callback) =>

    if typeof options is "function"
      callback = options
      options = {}

    options.token = @token<commit_msg>Added support for icon_emoji<commit_after>request = require "request"

class Slack
  constructor: (@token, @domain) ->
    @apiMode = unless @domain then true else false
    @url = @composeUrl()

  composeUrl: =>
    if @apiMode
      #retrun api url
      return "https://slack.com/api/"
    else
      #return web hook mode
      return "https://#{@domain}.slack.com/services/hooks/incoming-webhook?token=#{@token}"

  webhook: (options, callback) =>

    request.post
      url: @url 
      body: JSON.stringify
        channel: options.channel
        text: options.text
        username: options.username
        icon_url: options.icon_url || ""
        icon_emoji: options.icon_emoji || ""
        attachments: options.attachments
    , (err, body, response) ->
      if err or response isnt "ok"
        return callback err, null
      
      callback err, {
        ok: true
      }

  api: (method, options, callback) =>

    if typeof options is "function"
      callback = options
      options = {}

    options.token = @token
{'fraction_non_alphanumeric': 0.11408730158730158, 'fraction_numerical': 0.0, 'mean_word_length': 2.3011456628477904, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 4, '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': '7118026', 'n_tokens_mistral': 604, 'n_tokens_neox': 593, 'n_words': 166}