Skip to content

Instantly share code, notes, and snippets.

@elsassph
Last active February 21, 2023 12:18
Show Gist options
  • Save elsassph/49582cdc8c64823833bb to your computer and use it in GitHub Desktop.
Save elsassph/49582cdc8c64823833bb to your computer and use it in GitHub Desktop.
Create a VoiceChatAPI room from Slack
<?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!
?>
@elsassph
Copy link
Author

elsassph commented Aug 8, 2014

Create a group voice chat room from Slack.

Usage:

  1. host the PHP script somewhere public,
  2. replacing "your slack API token here" by your auth token,
  3. create a new "Slash Command" (like /voice) and point it on the script,
  4. enjoy :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment