diff --git a/lib/plugins/matrix/send.js b/lib/plugins/matrix/send.js index ac2df5ebd6..49e24e1bce 100644 --- a/lib/plugins/matrix/send.js +++ b/lib/plugins/matrix/send.js @@ -9,20 +9,25 @@ function send( room, accessToken, retries = 3, - backoff = 5000 + backoff = 5000, + transactionId ) { + if (!transactionId) { + transactionId = `ssio-${Date.now()}`; + } const retryCodes = new Set([408, 429, 500, 503]); return new Promise((resolve, reject) => { const request = _request( { host, port: 443, - path: `/_matrix/client/r0/rooms/${room}/send/m.room.message?access_token=${accessToken}`, + path: `/_matrix/client/v3/rooms/${room}/send/m.room.message/${transactionId}`, headers: { + Authorization: `Bearer ${accessToken}`, 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(JSON.stringify(data), 'utf8') }, - method: 'POST' + method: 'PUT' }, res => { const { statusCode, statusMessage } = res; @@ -36,7 +41,8 @@ function send( room, accessToken, retries - 1, - backoff * 2 + backoff * 2, + transactionId ); }, backoff); } else {