Skip to content

Instantly share code, notes, and snippets.

@lewayotte
Created Nov 14, 2018
Embed
What would you like to do?
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