This is an old revision of the document!
It can be very simple to post a message to a channel on Matrix.
This script requires 'jq, the command line JSON processor.
sudo apt install jq
#!/bin/bash # Usage: # echo "Hello world" | ./post_to_matrix.sh msgtype=m.text homeserver=glasgow.social room=!BOrDFgeDdZZbUvfjjs:glasgow.social access_token=put_your_user_access_token_here curl -XPOST -d "$( jq -Rsc --arg msgtype "$msgtype" '{$msgtype, body:.}')" "https://$homeserver/_matrix/client/r0/rooms/$room/send/m.room.message?access_token=$accesstoken"
<?php $msgtype = "m.text"; $homeserver = "glasgow.social"; $room = "!BOrDFgeDdZZbUvfjjs:glasgow.social"; $access_token="put_your_user_access_token_here" $url = "https://$homeserver/_matrix/client/r0/rooms/$room/send/m.room.message?access_token=$access_token"; $msg = "Hello world"; $payload = json_encode(array("msgtype"=>$msgtype, "body"=>$msg)); $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); $response = curl_exec($ch); ?>