This shows you the differences between two versions of the page.
Next revision | Previous revision Last revision Both sides next revision | ||
projects:owncastmatrix [2021/04/07 20:56] admin created |
projects:owncastmatrix [2021/04/07 21:06] admin |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Owncast/Matrix ====== | ====== Owncast/Matrix ====== | ||
- | I run this code to link an Owncast chat to a Matrix room. It's designed to be temporary (you just run it from the command line) but it would be easy to modify to always be searching for when a stream starts. I've seperated out the Owncast-to-Matrix and Matrix-to-Owncast components so you can choose which one you want (or run both). It uses my very simple [[Projects/Matrix PHP Class]]. | + | See also: https://opensource.glasgow.social/projects/matrix_owncast |
+ | |||
+ | I run this code to link an Owncast chat to a Matrix room. It's designed to be temporary (you just run it from the command line) but it would be easy to modify to always be searching for when a stream starts. I've seperated out the Owncast-to-Matrix and Matrix-to-Owncast components so you can choose which one you want (or run both). OwncastToMatrix uses my very simple [[Projects/Matrix PHP Class]] but MatrixToOwncast doesn't require it. | ||
<code php OwncastToMatrix.php> | <code php OwncastToMatrix.php> | ||
Line 53: | Line 55: | ||
$room_id = "!room_id:homeserver"; | $room_id = "!room_id:homeserver"; | ||
+ | $sender_name = "@botname:homeserver.com"; // IMPORTANT: use this to stop the script looping and repeating what the bot is saying on each chat/room | ||
while(true) { | while(true) { | ||
Line 59: | Line 62: | ||
if(is_array($data['chunk']) and sizeof($data['chunk'])>0) { | if(is_array($data['chunk']) and sizeof($data['chunk'])>0) { | ||
foreach($data['chunk'] as $message) { | foreach($data['chunk'] as $message) { | ||
- | if($message['sender'] != '@adelaide:glasgow.social') { | + | if($message['sender'] != $sender_name) { |
if($message['content']['msgtype'] == "m.text") { | if($message['content']['msgtype'] == "m.text") { | ||
if(!empty($message['content']['body'])) { | if(!empty($message['content']['body'])) { |