File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,7 +3,8 @@ MYMX_WEBHOOK_SECRET=replace_me
33EVENT_STORE = ../../data/events.jsonl
44RULES_PATH = ../../rules.json
55NOTIFY_THRESHOLD = 60
6- MATRIX_HOMESERVER = https://matrix.beeper.com
6+ MATRIX_HOMESERVER = https://matrix-client.matrix.org
77MATRIX_ACCESS_TOKEN = replace_me
8- MATRIX_ROOM_ID = !roomid:beeper.local
8+ MATRIX_ROOM_ID =
99MATRIX_ROOM_STORE = ../../data/matrix-room.json
10+ MATRIX_INVITE_USER = @your-main-account:matrix.org
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ const matrixHomeserver = process.env.MATRIX_HOMESERVER || "https://matrix.beeper
1616const matrixAccessToken = process . env . MATRIX_ACCESS_TOKEN || "" ;
1717let matrixRoomId = process . env . MATRIX_ROOM_ID || "" ;
1818const matrixRoomStore = process . env . MATRIX_ROOM_STORE || "./matrix-room.json" ;
19+ const matrixInviteUser = process . env . MATRIX_INVITE_USER || "" ;
1920
2021if ( ! secret ) {
2122 throw new Error ( "Missing MYMX_WEBHOOK_SECRET" ) ;
@@ -189,9 +190,26 @@ async function ensureMatrixRoom(): Promise<boolean> {
189190
190191 matrixRoomId = roomId ;
191192 saveRoomId ( roomId ) ;
193+
194+ if ( matrixInviteUser ) {
195+ await inviteMatrixUser ( roomId , matrixInviteUser ) ;
196+ }
192197 return true ;
193198}
194199
200+ async function inviteMatrixUser ( roomId : string , userId : string ) : Promise < boolean > {
201+ const url = `${ matrixHomeserver } /_matrix/client/v3/rooms/${ encodeURIComponent (
202+ roomId
203+ ) } /invite?access_token=${ encodeURIComponent ( matrixAccessToken ) } `;
204+ const payload = { user_id : userId } ;
205+ const resp = await fetch ( url , {
206+ method : "POST" ,
207+ headers : { "Content-Type" : "application/json" } ,
208+ body : JSON . stringify ( payload ) ,
209+ } ) ;
210+ return resp . ok ;
211+ }
212+
195213// MyMX needs raw text body to verify signatures.
196214app . use (
197215 express . text ( {
You can’t perform that action at this time.
0 commit comments