Created
April 6, 2011 05:49
-
-
Save jamescarlos/905205 to your computer and use it in GitHub Desktop.
Send a message to campfire
This file contains 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 | |
// Usage and set up | |
// change your-site to the subdomain being used for your campfire url | |
// use the api token for the user you want posting the message | |
// set the room id that you want the message to be posted to | |
define('CAMPFIRE_URL', 'https://your-site.campfirenow.com/'); | |
define('CAMPFIRE_API_TOKEN', 'apitokengoeshere'); | |
$room_id = 12345; | |
$message = 'I are a robot.'; | |
sendCampfireMessage($room_id, $message); | |
function sendCampfireMessage($room_id, $message, $message_type = 'TextMessage') | |
{ | |
$request = array('message' => array('type' => $message_type, 'body' => $message)); | |
return campfirePost($room_id, 'speak', $request); | |
} | |
function campfirePost($room_id, $action, $data = null) | |
{ | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, CAMPFIRE_URL . 'room/' . $room_id . '/' . $action . '.json'); | |
curl_setopt($ch, CURLOPT_USERPWD, CAMPFIRE_API_TOKEN . ':x'); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
curl_setopt($ch, CURLOPT_VERBOSE, 0); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json')); | |
if ($data) | |
{ | |
curl_setopt($ch, CURLOPT_POST, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); | |
} | |
$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