PHP Code:
<?php
# Based on a script by Sha1Sum, modified by Clarity
class GroupMeBot {
public $group, $id, $user_id, $group_id;
public function __construct($id) {
$this->id = $id;
}
public function post($message) {
$post_text = utf8_encode($message);
$ch = curl_init();
$post_contents = array(
'bot_id' => $this->id,
'text' => $post_text,
);
$post = json_encode($post_contents);
$arr = array();
array_push($arr, 'Content-Type: application/json; charset=utf-8');
curl_setopt($ch, CURLOPT_HTTPHEADER, $arr);
curl_setopt($ch, CURLOPT_URL, 'https://api.groupme.com/v3/bots/post');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_exec($ch);
curl_close($ch);
}
}
$bot = new GroupMeBot('Your GroupMe Bot ID Here');
$msg_json = file_get_contents('php://input');
$msg = json_decode($msg_json);
$user_id = $msg->user_id;
$group_id = $msg->group_id;
$inquirer_name = $msg->name;
$from = $msg->name;
$text = $msg->text;
if (!substr($text, 0, 1) == '!')
exit();
$available_keywords = array(
'reply',
'logout',
'terminate'
);
$no_trigger = strtolower(substr($text, 1));
$unstripped_keywords = explode(' ', $no_trigger);
$keywords = array();
foreach ($unstripped_keywords as $keyword) {
$keywords[] = trim($keyword, ' ,');
}
if (in_array('reply', $keywords) || in_array('logout', $keywords) || in_array('terminate', $keywords)) {
$username = "mySQL username";
$password = "mySQL password";
$database = "mySQL database";
$server = "mySQL server address";
$db_handle = mysql_connect($server, $username, $password);
$db_found = mysql_select_db($database, $db_handle);
if ($db_found) {
$SQL = "SELECT * FROM Communicator WHERE ID = 1";
$result = mysql_query($SQL);
if($result){
$SQL = "UPDATE `Communicator` SET `Reply` = '".$text."' WHERE `ID` = 1";
$result = mysql_query($SQL);
if($result)
print "Success - command added.";
else
print "Failure - command was not added.";
}
}
}
?>