Skip to content

Instantly share code, notes, and snippets.

@lewayotte
Created November 14, 2018 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lewayotte/bbdf17055417b33f6ac5e9af9edd8e7d to your computer and use it in GitHub Desktop.
Save lewayotte/bbdf17055417b33f6ac5e9af9edd8e7d to your computer and use it in GitHub Desktop.
Merriam Webster Word of the Day integration for Slack
<?php
$wotd = get_wotd();
if ( !empty( $wotd ) ) {
send_to_slack( $wotd );
}
function get_wotd() {
$rss = new DOMDocument();
$rss->load( 'https://www.merriam-webster.com/wotd/feed/rss2' );
$link = '';
foreach ($rss->getElementsByTagName('item') as $node) {
$link = $node->getElementsByTagName('link')->item(0)->nodeValue;
break;
}
return str_replace( ' ', '%20', $link );
}
function send_to_slack( $message ) {
$ch = curl_init( 'https://slack.com/api/chat.postMessage' );
$data = http_build_query([
'token' => 'YOURTOKEN',
'channel' => '#general',
'text' => $message, //'Hello, Foo-Bar channel message.',
'unfurl_links' => true
]);
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'POST' );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
$result = curl_exec( $ch );
curl_close( $ch);
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment