Skip to content

Instantly share code, notes, and snippets.

@Braunson
Forked from elsassph/index.php
Last active August 29, 2015 14:15
Show Gist options
  • Save Braunson/6c196ad986a5514ae8fd to your computer and use it in GitHub Desktop.
Save Braunson/6c196ad986a5514ae8fd to your computer and use it in GitHub Desktop.
<?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