You are here

function _slack_send_message in Slack 7

Same name and namespace in other branches
  1. 6 includes/slack.api.inc \_slack_send_message()

Send message to the Slack with more options.

Return value

object Can contain: success fail fail

  • data: ok No hooks Invalid channel specified
  • status message: OK Not found Server Error
  • code: 200 404 500
  • error: - Not found Server Error
1 call to _slack_send_message()
slack_send_message in includes/slack.api.inc
Send message to the Slack.

File

includes/slack.api.inc, line 72
Slack integration module API functions.

Code

function _slack_send_message($webhook_url, $message, $message_options = array(), $attachment_options = array()) {
  $headers = array(
    'Content-Type' => 'application/json',
  );
  $message = _slack_process_message($message);
  $message_options['text'] = $message;
  $attachment_options['fallback'] = $message;
  if (!empty($attachment_options['text'])) {
    $attachment_options['text'] = _slack_process_message($attachment_options['text']);
  }
  $message_options['attachments'] = array(
    $attachment_options,
  );
  $sending_data = '';
  if (!defined('JSON_UNESCAPED_SLASHES')) {
    $sending_data = str_replace('\\/', '/', json_encode($message_options));
  }
  else {
    $sending_data = json_encode($message_options, JSON_UNESCAPED_SLASHES);
  }
  $options = array(
    'method' => 'POST',
    'data' => $sending_data,
    'headers' => $headers,
  );
  $sending_url = $webhook_url;
  $result = drupal_http_request($sending_url, $options);
  return $result;
}