function slack_send_test_message_form_submit in Slack 7
Same name and namespace in other branches
- 6 includes/pages/slack.pages.inc \slack_send_test_message_form_submit()
Submit handler for slack test message form.
File
- includes/
pages/ slack.pages.inc, line 139 - Slack module page functions.
Code
function slack_send_test_message_form_submit($form, &$form_state) {
$webhook_url = slack_get_default_webhook_url();
$channel = $form_state['values']['slack_test_channel'];
$message = $form_state['values']['slack_test_message'];
$attachment_options = array();
$use_attachments = $form_state['values']['slack_attachment_enabled'];
if ($use_attachments) {
$attachment_options['pretext'] = $form_state['values']['slack_test_pretext'];
$attachment_options['text'] = $form_state['values']['slack_test_attachment_text'];
$attachment_options['title'] = $form_state['values']['slack_test_title'];
$attachment_options['title_link'] = $form_state['values']['slack_test_title_link'];
$attachment_options['color'] = $form_state['values']['slack_test_color'];
$attachment_options['image_url'] = $form_state['values']['slack_test_image_url'];
$attachment_options['author_name'] = $form_state['values']['slack_test_author_name'];
$attachment_options['author_link'] = $form_state['values']['slack_test_author_link'];
$attachment_options['author_icon'] = $form_state['values']['slack_test_author_icon'];
$attachment_options['footer'] = $form_state['values']['slack_test_footer'];
$attachment_options['footer_icon'] = $form_state['values']['slack_test_footer_icon'];
$attachment_options['ts'] = $form_state['values']['slack_test_ts'];
foreach ($form_state['values']['slack_attachment_mrkdwn'] as $option => $value) {
if ($value) {
$attachment_options['mrkdwn_in'][] = $option;
}
}
}
$icon_type = variable_get('slack_icon_type');
$icon = variable_get('slack_icon_url');
$emoji = variable_get('slack_icon_emoji');
$icon_options = array(
'icon' => $icon,
'emoji' => $emoji,
'type' => $icon_type,
);
$result = slack_send_message($webhook_url, $message, $channel, '', $icon_options, $attachment_options);
if (!$result) {
drupal_set_message(t("Message wasn't sent. Please, check slack module configuration."), 'error');
}
elseif (!isset($result->error) && $result->code == SLACK_CODE_OK) {
drupal_set_message(t('Message was successfully sent.'));
}
else {
drupal_set_message(t("Message wasn't sent."), 'error');
slack_watchdog_sending_error($result);
}
}