-
-
Save michaeljhopkins/a6095e6fe60c24885543 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// first create a new voice chat room: | |
$options = array( | |
'http' => array( | |
'header' => "Content-type: application/x-www-form-urlencoded\r\n", | |
'method' => 'POST', | |
'content' => http_build_query(array()), | |
) | |
); | |
$context = stream_context_create($options); | |
$result = file_get_contents("http://voicechatapi.com/api/v1/conference/", false, $context); | |
if (!$result) $message = "Unable to create a room (no VoiceChatAPI response)"; | |
else | |
{ | |
$info = json_decode($result); | |
$url = $info->conference_url; | |
if (!$url) $message = "Unable to create a room (invalid VoiceChatAPI response)"; | |
else $message = "Your room is ready: <$url>"; | |
} | |
// then send the voicechatapi room url to the current slack room: | |
if (!$_POST["channel_id"]) die("Missing Slack channel_id"); | |
$data = array( | |
"token" => "your slack API token here", | |
"channel" => $_POST["channel_id"], | |
"text" => $message, | |
"username" => "Voice Chat API Bot" | |
); | |
$options = array( | |
'http' => array( | |
'header' => "Content-type: application/x-www-form-urlencoded\r\n", | |
'method' => 'POST', | |
'content' => http_build_query($data), | |
) | |
); | |
$context = stream_context_create($options); | |
$result = file_get_contents("https://slack.com/api/chat.postMessage", false, $context); | |
if (!$result) $message = "Unable to send message (no Slack API response): $message"; | |
else | |
{ | |
$info = json_decode($result); | |
if (!$info->ok) $message = "Unable to send message (invalid Slack API response): $message"; | |
} | |
// APIs FTW! | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment