load(); $dotenv->required(['SERVER_HOST', 'SERVER_USER', 'SERVER_PASS']); $server = $_SERVER['SERVER_HOST']; $user = $_SERVER['SERVER_USER']; $pass = $_SERVER['SERVER_PASS']; // Firstly, init \ATDev\RocketChat\Chat::setUrl($server); // No trailing / on the https://host.domain // Now, login $result = \ATDev\RocketChat\Chat::login($user, $pass); if (!$result) { // Log the error $error = \ATDev\RocketChat\Chat::getError(); // And out } else { // Do something $myText = "Hello @all - need to upgrade this instance. Hopefully back shortly"; // All Rooms are converted to hyphenated $groupID = "systemadmin"; $groupID = strtolower($groupID); $myUserId = $result->getUserId(); $listing = \ATDev\RocketChat\Groups\Group::listing(); if (!$listing) { // Log the error $error = \ATDev\RocketChat\Groups\Group::getError(); // Bail and logout } else { foreach ($listing as $group) { $myGroup = strtolower($group->getName()); // echo $group->getName() . "
"; //$myRoomId = $group->getRoomId(); if ($myGroup == $groupID) { // Send a message $myRoomId = $group->getRoomId(); $message = new \ATDev\RocketChat\Messages\Message(); $message->setRoomId($myRoomId); $message->setText($myText); $messageresult = $message->postMessage(); if (!$messageresult) { // Log the error $error = $message->getError(); } } } $result = \ATDev\RocketChat\Chat::logout(); } // Never logged in or has logged out }