You are here

protected function Slack::prepareMessage in Slack 8

Prepare message meta fields for Slack.

Parameters

string $webhook_url: Webhook for Slack basic functions.

string $channel: The channel in the Slack service to send messages.

string $username: The bot name displayed in the channel.

Return value

array Config array.

1 call to Slack::prepareMessage()
Slack::sendMessage in src/Slack.php
Sends a message to a Slack channel.

File

src/Slack.php, line 107

Class

Slack
Send messages to Slack.

Namespace

Drupal\slack

Code

protected function prepareMessage($webhook_url, $channel, $username) {
  $config = $this->config
    ->get('slack.settings');
  $message_options = [];
  if (!empty($channel)) {
    $message_options['channel'] = $channel;
  }
  elseif (!empty($config
    ->get('slack_channel'))) {
    $message_options['channel'] = $config
      ->get('slack_channel');
  }
  if (!empty($username)) {
    $message_options['username'] = $username;
  }
  elseif (!empty($config
    ->get('slack_username'))) {
    $message_options['username'] = $config
      ->get('slack_username');
  }
  $icon_type = $config
    ->get('slack_icon_type');
  if ($icon_type == 'emoji') {
    $message_options['icon_emoji'] = $config
      ->get('slack_icon_emoji');
  }
  elseif ($icon_type == 'image') {
    $message_options['icon_url'] = $config
      ->get('slack_icon_url');
  }
  $message_options['as_user'] = TRUE;
  return [
    'webhook_url' => $webhook_url,
    'message_options' => $message_options,
  ];
}