User Tools

Site Tools


matrix_tools

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision Both sides next revision
matrix_tools [2020/06/01 11:41]
admin
matrix_tools [2020/06/01 13:59]
admin
Line 10: Line 10:
  
 ===== Getting a room ID ===== ===== Getting a room ID =====
-  * Click on the three dots at the edge of a channel ​name and click ''​Settings''​+  * Click on the three dots at the edge of a room name and click ''​Settings''​
   * Choose ''​Advanced''​ to see the ''​Internal Room ID''​   * Choose ''​Advanced''​ to see the ''​Internal Room ID''​
   * #glasgow on the server is ''​!BOrDFgeDdZZbUvfjjs:​glasgow.social''​   * #glasgow on the server is ''​!BOrDFgeDdZZbUvfjjs:​glasgow.social''​
  
-===== Posting messages to a channel ​===== +===== Posting messages to a room ===== 
-It can be very simple to post a message to a channel ​on Matrix.+It can be very simple to post a message to a room on Matrix ​(note: you have to be a member of the room).
 ==== Via bash/curl ==== ==== Via bash/curl ====
 This script requires ''​jq'',​ the command line JSON processor. This script requires ''​jq'',​ the command line JSON processor.
Line 55: Line 55:
 </​file>​ </​file>​
  
-===== Listening to channels ​===== +===== Listening to rooms ===== 
-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.+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 rooms at a glance. ​ Very cool.
  
 <code php ListenToMatrix.php>​ <code php ListenToMatrix.php>​
Line 115: Line 115:
 ===== Matrix Bot ===== ===== 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). ​ 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). ​
 +
 +===== Posting images to a room =====
 +Media must first be uploaded to your homeserver, then you can send a new message, as above, using the ''​m.image''​ event type.  Here is an example in PHP that works as a '​copy'​ command.
 +<code php matrix_cp.php>​
 +
 +</​code>​
 +
 +
 +in bash that first uploads the file, then posts it to the room.  I've named it matrix_cp as it basically lets you copy a image to the room:
 +<code bash matrix_cp.sh>​
 +#!/bin/bash
 +# Usage:
 +# ./matrix_cp filename room_id alt_text
 +msgtype=m.text
 +homeserver=glasgow.social
 +room=!BOrDFgeDdZZbUvfjjs:​glasgow.social
 +access_token=put_your_user_access_token_here
 +</​code>​
matrix_tools.txt · Last modified: 2023/12/27 13:45 by admin