function slack_send_message in Slack 7
Same name and namespace in other branches
- 6 includes/slack.api.inc \slack_send_message()
Send message to the Slack.
Parameters
string $message: The message sent to the channel.
string $channel: The channel in the Slack service to send messages.
string $username: The bot name displayed in the channel.
Return value
bool|object Slack response.
3 calls to slack_send_message()
- MessageNotifierSlack::deliver in plugins/
notifier/ slack/ MessageNotifierSlack.class.php - Deliver a message via the required transport method.
- slack_rules_send_message_action in ./
slack.rules.inc - Rules action for sending a message to the Slack.
- slack_send_test_message_form_submit in includes/
pages/ slack.pages.inc - Submit handler for slack test message form.
File
- includes/
slack.api.inc, line 21 - Slack integration module API functions.
Code
function slack_send_message($webhook_url, $message, $channel = '', $username = '', $icon_options = array(), $attachment_options = array()) {
if (!$webhook_url) {
drupal_set_message(t('Please, enter the webhook value and try again'), 'error');
return FALSE;
}
if ($channel) {
$message_options['channel'] = $channel;
}
else {
$message_options['channel'] = slack_get_default_channel();
}
if ($username) {
$message_options['username'] = $username;
}
else {
$message_options['username'] = slack_get_default_username();
}
if (isset($icon_options['type'])) {
if ($icon_options['type'] == 'emoji') {
if ($icon_options['emoji']) {
$message_options['icon_emoji'] = $icon_options['emoji'];
}
else {
$message_options['icon_emoji'] = slack_get_default_icon_emoji();
}
}
elseif ($icon_options['type'] == 'image') {
if ($icon_options['icon']) {
$message_options['icon_url'] = $icon_options['icon'];
}
else {
$message_options['icon_url'] = slack_get_default_icon_url();
}
}
}
$result = _slack_send_message($webhook_url, $message, $message_options, $attachment_options);
return $result;
}