This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
matrix_tools [2020/05/30 08:58] admin |
matrix_tools [2020/05/30 11:25] admin [Matrix Bot] it's not right Neo |
||
---|---|---|---|
Line 53: | Line 53: | ||
===== Listening to channels ===== | ===== Listening to channels ===== | ||
- | This is pretty straightforward. This is just how to see messages that are posted, but if you explore what is returned then you can see all sorts of things too (like joins, images, likes, invites etc). Very cool. | + | This is pretty straightforward. This is just how to see messages that are posted, but if you explore what is returned then you can see all sorts of things too (like joins, images, likes, invites etc). I run something like this on a terminal so I can see what's going on in all my channels at a glance. Very cool. |
<code php ListenToMatrix.php> | <code php ListenToMatrix.php> | ||
Line 83: | Line 83: | ||
} | } | ||
- | } | ||
function get_new_events($since) { | function get_new_events($since) { | ||
global $homeserver,$access_token; | global $homeserver,$access_token; | ||
Line 97: | Line 96: | ||
?> | ?> | ||
+ | </code> | ||
+ | |||
+ | You can follow one particular room just using GET requests, by doing something like this: | ||
+ | |||
+ | <code php> | ||
+ | function get_new_events($room) { | ||
+ | $homeserver = "glasgow.social"; | ||
+ | $access_token = "access_token_goes_here" | ||
+ | $url = "https://$homeserver/_matrix/client/r0/rooms/$room/messages?access_token=$access_token&from=$tracking_id"; | ||
+ | $data = json_decode(file_get_contents($url), true); | ||
+ | return $data; | ||
+ | } | ||
</code> | </code> | ||
===== Matrix Bot ===== | ===== Matrix Bot ===== | ||
- | * See [[Matrix Bot]] | + | The basis of my bot's interaction with Matrix is bascially the above code. Replace the echo line with with whatever you want to do (in my case, I look up a list of rules [i.e. pairs of regexes and their response functions] I use in IRC from a database and act accordingly). |