Skip to content
Snippets Groups Projects
Commit e0cf040a authored by Thomas Hackl's avatar Thomas Hackl
Browse files

first try at posting messages into a room

parent ca6df06b
No related branches found
No related tags found
No related merge requests found
......@@ -51,8 +51,14 @@ class MatrixChatController extends AuthenticatedController
$this->hasToCreate = false;
$room->requireMembership($this->account->getLinkedAccount());
$room->sendMessage(
'Avengers... assemble.',
'<!-- HTML -->Hulk <strong>SMASH</strong>!'
);
}
}
}
public function require_room_action()
......
......@@ -158,4 +158,27 @@ class MatrixRoom extends SimpleORMap
}
}
/**
* Sends a message into the current room, sender is the Stud.IP system account.
*
* @param string $title
* @param string $body
*/
public function sendMessage($title, $body)
{
$content = [
'msgtype' => 'm.text',
'format' => 'm.format.custom_html',
'body' => strip_tags($title . ":\n" . $body),
'formatted_body' => htmlReady('<strong>' . $title . '</strong><br>' . $body),
];
MatrixClient::get()->sendRoomEvent(
MatrixAccount::requireSystemAccount(),
$this->getLinkedRoom(),
'm.room.message',
'',
$content
);
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment