mautrix / go Goto Github PK
View Code? Open in Web Editor NEWA Golang Matrix framework.
Home Page: https://maunium.net/go/mautrix
License: Mozilla Public License 2.0
A Golang Matrix framework.
Home Page: https://maunium.net/go/mautrix
License: Mozilla Public License 2.0
Running tests in "maunium.net/go/mautrix/pushrules" fails due to skew between that package and the event package.
$ go test
# maunium.net/go/mautrix/pushrules_test [maunium.net/go/mautrix/pushrules.test]
./condition_displayname_test.go:29:3: unknown field 'MsgType' in struct literal of type event.Content
./condition_displayname_test.go:30:3: unknown field 'Body' in struct literal of type event.Content
./condition_displayname_test.go:38:3: unknown field 'MsgType' in struct literal of type event.Content
./condition_displayname_test.go:39:3: unknown field 'Body' in struct literal of type event.Content
./condition_displayname_test.go:48:3: unknown field 'MsgType' in struct literal of type event.Content
./condition_displayname_test.go:49:3: unknown field 'Body' in struct literal of type event.Content
./condition_test.go:48:4: unknown field 'MsgType' in struct literal of type event.Content
./condition_test.go:49:4: unknown field 'Body' in struct literal of type event.Content
./condition_test.go:94:22: undefined: event.Member
./condition_test.go:101:29: undefined: event.Member
./condition_test.go:101:29: too many errors
FAIL maunium.net/go/mautrix/pushrules [build failed]
I have attempted to fix this by wrapping the MsgType
and Body
fields in Parsed: event.MessageEventContent
and renaming uses of event.Member
to event.MemberEventContent
, but while this now builds there are obviously semantic changes that I am missing.
$ go test
--- FAIL: TestPushCondition_Match_DisplayName (0.00s)
condition_displayname_test.go:35:
Error Trace: condition_displayname_test.go:35
Error: Should be true
Test: TestPushCondition_Match_DisplayName
--- FAIL: TestPushRule_Match_Content (0.00s)
rule_test.go:107:
Error Trace: rule_test.go:107
Error: Should be true
Test: TestPushRule_Match_Content
--- FAIL: TestPushRule_Match_Content_ImplicitGlob (0.00s)
rule_test.go:139:
Error Trace: rule_test.go:139
Error: Should be true
Test: TestPushRule_Match_Content_ImplicitGlob
FAIL
It looks like several maps throughout intent/client related code paths aren't accessed in a concurrency-friendly way (according to the stack trace below and a quick skim through the code base), which can cause crashes due to races:
fatal error: concurrent map writes
goroutine 46766 [running]:
runtime.throw(0x9f2a0e, 0x15)
/usr/local/go/src/runtime/panic.go:1116 +0x72 fp=0xc000076b40 sp=0xc000076b10 pc=0x437c72
runtime.mapassign_faststr(0x94fa60, 0xc0001c1770, 0xc000618cc0, 0x3d, 0xc0006062d0)
/usr/local/go/src/runtime/map_faststr.go:211 +0x3f1 fp=0xc000076ba8 sp=0xc000076b40 pc=0x4163b1
maunium.net/go/mautrix/appservice.(*AppService).Client(0xc000104900, 0xc000618cc0, 0x3d, 0x2)
/go/pkg/mod/maunium.net/go/[email protected]/appservice/appservice.go:170 +0x1f3 fp=0xc000076c18 sp=0xc000076ba8 pc=0x815033
maunium.net/go/mautrix/appservice.(*AppService).NewIntentAPI(0xc000104900, 0xc000618c01, 0x30, 0x1)
/go/pkg/mod/maunium.net/go/[email protected]/appservice/intent.go:36 +0x155 fp=0xc000076cb0 sp=0xc000076c18 pc=0x817dd5
maunium.net/go/mautrix/appservice.(*AppService).Intent(0xc000104900, 0xc000618c00, 0x3d, 0xc000618c00)
/go/pkg/mod/maunium.net/go/[email protected]/appservice/appservice.go:143 +0xf7 fp=0xc000076d18 sp=0xc000076cb0 pc=0x814c37
[...]
(the rest of the stack trace is omitted as it's application-specific and isn't relevant to mautrix-go)
Since the EventProcessor
's default mode is to start a new goroutine for each new event, it's quite easy to get in a situation in which two goroutine want to e.g. access an intent or a client in reaction to an incoming event.
Hi,
How can I send formatted message in markdown or html to a chatroom ?
Here you can find my simple try with the example code :
package main
import (
"flag"
"fmt"
"os"
"time"
"maunium.net/go/mautrix"
"maunium.net/go/mautrix/event"
)
var homeserver = flag.String("homeserver", "", "Matrix homeserver")
var username = flag.String("username", "", "Matrix username localpart")
var password = flag.String("password", "", "Matrix password")
func main() {
flag.Parse()
if *username == "" || *password == "" || *homeserver == "" {
_, _ = fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
flag.PrintDefaults()
os.Exit(1)
}
fmt.Println("Logging into", *homeserver, "as", *username)
client, err := mautrix.NewClient(*homeserver, "", "")
if err != nil {
panic(err)
}
_, err = client.Login(&mautrix.ReqLogin{
Type: "m.login.password",
Identifier: mautrix.UserIdentifier{Type: mautrix.IdentifierTypeUser, User: *username},
Password: *password,
StoreCredentials: true,
})
if err != nil {
panic(err)
}
fmt.Println("Login successful")
syncer := client.Syncer.(*mautrix.DefaultSyncer)
syncer.OnEventType(event.EventMessage, func(source mautrix.EventSource, evt *event.Event) {
diff := time.Since(time.Unix(evt.Timestamp/1000, 0))
if diff < time.Second*10 {
if evt.Sender != client.UserID {
fmt.Printf("<%[1]s> %[4]s (%[2]s/%[3]s)\n", evt.Sender, evt.Type.String(), evt.ID, evt.Content.AsMessage().Body)
client.SendText(evt.RoomID, "`nok`")
client.SendText(evt.RoomID, "```html\n<b>nok</b>\n```")
client.SendText(evt.RoomID, "<code>nok</code>")
}
}
})
err = client.Sync()
if err != nil {
panic(err)
}
}
None of the messages are formatted in Element:
When I inspect a formatted message, the json seems like that:
{
"type": "m.room.message",
"sender": "SENDER",
"content": {
"msgtype": "m.text",
"body": "`ok`",
"format": "org.matrix.custom.html",
"formatted_body": "<code>ok</code>"
},
"origin_server_ts": 1611261145159,
"unsigned": {
"age": 73212340,
"transaction_id": "TRANSACTION_ID"
},
"event_id": "EVENT_ID",
"room_id": "ROOM_ID"
}
The non functionnal message look like that:
{
"type": "m.room.message",
"sender": "SENDER",
"content": {
"msgtype": "m.text",
"body": "`nok`"
},
"origin_server_ts": 1611340455640,
"unsigned": {
"age": 308
},
"event_id": "EVENT_ID",
"room_id": "ROOM_ID"
}
As you can see, format
and formatted_body
are missing in my message but I can't find a method in client
to send html.
Thank you.
We see lots of this on requests to POST /_matrix/client/r0/join/{roomIdOrAlias}
from clients with user-agents like Go-http-client/2.0
:
2022-07-26 00:04:32,466 - synapse.http.servlet - 663 - WARNING - POST-1079194 - Unable to parse JSON: Expecting value: line 1 column 1 (char 0) (b'')
... which suggests something is making requests with a malformed (empty?) body. I think many of these requests are coming from projects based on mautrix.
Currently Synapse accepts this, but it's not spec-compliant and we'll be fixing this in Synapse soon: matrix-org/synapse#13388.
Please could you make sure to include (at least) an empty json object in the request body?
Hello,
I'm trying to develop a bot on top of mautrix-go and faced odd issue - OlmMachine.ProcessSyncResponse panics on canonicaljson.RawJSONFromResult
. The issue reproduced on synapse 1.49.1, 1.49.2 and different matrix accounts (I created a new account just to be sure the issue is not caused by some kind of "state" saved into that account) and different mautrix-go versions (0.10.5, 0.10.7, 0.10.8).
here log (level=trace) with stacktrace:
api.DEBUG req #1: POST https://matrix.example.com/_matrix/client/r0/login <sensitive content omitted>
api.DEBUG Stored credentials for @bot2:example.com/MEYOTENOCI after login
matrix.DEBUG restoring previous session...
api.DEBUG req #2: GET https://matrix.example.com/_matrix/client/r0/user/@bot2:example.com/account_data/com.example.bot.session_token
api.DEBUG req #3: GET https://matrix.example.com/_matrix/client/r0/presence/@bot2:example.com/status
matrix.DEBUG previous session restored successfully. Closing current session...
api.DEBUG req #4: POST https://matrix.example.com/_matrix/client/r0/logout
matrix.DEBUG hydrating bot...
api.DEBUG req #5: GET https://matrix.example.com/_matrix/client/r0/profile/@bot2:example.com/displayname
bot.DEBUG bot has been created
api.DEBUG req #6: GET https://matrix.example.com/_matrix/client/r0/user/@bot2:example.com/account_data/com.example.bot.batch_token
api.DEBUG req #7: PUT https://matrix.example.com/_matrix/client/r0/user/@bot2:example.com/account_data/com.example.bot.batch_token {"NextBatch":""}
bot.DEBUG data store initialized
bot.DEBUG end-to-end encryption support initialized
bot.DEBUG starting bot...
api.DEBUG req #8: PUT https://matrix.example.com/_matrix/client/r0/presence/@bot2:example.com/status {"presence":"online"}
matrix.INFO bot has been started
api.DEBUG req #9: GET https://matrix.example.com/_matrix/client/r0/sync?filter=0&since=s547269_18739377_0_454979_142756_283_12908_826018_10&timeout=30000
olm.TRACE Device list changes in /sync: [@bot2:example.com] (trace: 00:47:43.282723)
olm.TRACE Finished handling device list changes (trace: 00:47:43.282723)
olm.DEBUG Sync response said we have 0 signed curve25519 keys left, sharing new ones... (trace: 00:47:43.282933)
bot.FATAL matrix bot crashed: ProcessResponse panicked! since=s547269_18739377_0_454979_142756_283_12908_826018_10 panic=runtime error: slice bounds out of range [:157] with capacity 155
goroutine 1 [running]:
runtime/debug.Stack()
/usr/lib/go/src/runtime/debug/stack.go:24 +0x65
maunium.net/go/mautrix.(*DefaultSyncer).ProcessResponse.func1()
/home/user/go/pkg/mod/maunium.net/go/[email protected]/sync.go:133 +0x66
panic({0x8f9e60, 0xc00062e348})
/usr/lib/go/src/runtime/panic.go:1038 +0x215
maunium.net/go/mautrix/crypto/canonicaljson.RawJSONFromResult(...)
/home/user/go/pkg/mod/maunium.net/go/[email protected]/crypto/canonicaljson/json.go:274
maunium.net/go/mautrix/crypto/canonicaljson.sortJSONObject.func1({0x3, {0xc0006783e6, 0x17}, {0xc0006783e7, 0x15}, 0x0, 0x86, {0x0, 0x0, 0x0}}, ...)
/home/user/go/pkg/mod/maunium.net/go/[email protected]/crypto/canonicaljson/json.go:113 +0x2d4
github.com/tidwall/gjson.Result.ForEach({0x5, {0xc0006783e5, 0x8a}, {0x0, 0x0}, 0x0, 0x85, {0x0, 0x0, 0x0}}, ...)
/home/user/go/pkg/mod/github.com/tidwall/[email protected]/gjson.go:293 +0x52c
maunium.net/go/mautrix/crypto/canonicaljson.sortJSONObject({0x5, {0xc0006783e5, 0x8a}, {0x0, 0x0}, 0x0, 0x85, {0x0, 0x0, 0x0}}, ...)
/home/user/go/pkg/mod/maunium.net/go/[email protected]/crypto/canonicaljson/json.go:110 +0x165
maunium.net/go/mautrix/crypto/canonicaljson.sortJSONValue({0x5, {0xc0006783e5, 0x8a}, {0x0, 0x0}, 0x0, 0x85, {0x0, 0x0, 0x0}}, ...)
/home/user/go/pkg/mod/maunium.net/go/[email protected]/crypto/canonicaljson/json.go:62 +0x289
maunium.net/go/mautrix/crypto/canonicaljson.sortJSONObject({0x5, {0xc000678360, 0x110}, {0x0, 0x0}, 0x0, 0x0, {0x0, 0x0, 0x0}}, ...)
/home/user/go/pkg/mod/maunium.net/go/[email protected]/crypto/canonicaljson/json.go:136 +0x5f3
maunium.net/go/mautrix/crypto/canonicaljson.sortJSONValue({0x5, {0xc000678360, 0x110}, {0x0, 0x0}, 0x0, 0x0, {0x0, 0x0, 0x0}}, ...)
/home/user/go/pkg/mod/maunium.net/go/[email protected]/crypto/canonicaljson/json.go:62 +0x289
maunium.net/go/mautrix/crypto/canonicaljson.SortJSON({0xc000678120, 0xc000676140, 0x110}, {0xc000678240, 0x0, 0x110})
/home/user/go/pkg/mod/maunium.net/go/[email protected]/crypto/canonicaljson/json.go:51 +0x23a
maunium.net/go/mautrix/crypto/canonicaljson.CanonicalJSONAssumeValid({0xc000678000, 0x110, 0x120})
/home/user/go/pkg/mod/maunium.net/go/[email protected]/crypto/canonicaljson/json.go:42 +0x96
maunium.net/go/mautrix/crypto/olm.(*Account).SignJSON(0x8b5ea0, {0x88ad60, 0xc000626230})
/home/user/go/pkg/mod/maunium.net/go/[email protected]/crypto/olm/account.go:244 +0x72
maunium.net/go/mautrix/crypto.(*OlmAccount).getInitialKeys(0xc0005e4230, {0xc0000d2138, 0xc0001c8000}, {0xc0001ae040, 0xc0000c25e0})
/home/user/go/pkg/mod/maunium.net/go/[email protected]/crypto/account.go:60 +0x439
maunium.net/go/mautrix/crypto.(*OlmMachine).ShareKeys(0xc00014e000, 0x940ad0)
/home/user/go/pkg/mod/maunium.net/go/[email protected]/crypto/machine.go:486 +0x4b
maunium.net/go/mautrix/crypto.(*OlmMachine).HandleOTKCounts(0xc00014e000, 0xc000652088)
/home/user/go/pkg/mod/maunium.net/go/[email protected]/crypto/machine.go:202 +0x2ac
maunium.net/go/mautrix/crypto.(*OlmMachine).ProcessSyncResponse(0xc00014e000, 0xc000652000, {0xc0000da5c0, 0xc000663b68})
/home/user/go/pkg/mod/maunium.net/go/[email protected]/crypto/machine.go:229 +0x1b6
maunium.net/go/mautrix.(*DefaultSyncer).ProcessResponse(0xc0000ce7d0, 0xc000652000, {0xc0000da5c0, 0x34})
/home/user/go/pkg/mod/maunium.net/go/[email protected]/sync.go:138 +0x12e
maunium.net/go/mautrix.(*Client).SyncWithContext(0xc00011c2a0, {0x9b9730, 0xc0000a2000})
/home/user/go/pkg/mod/maunium.net/go/[email protected]/client.go:284 +0x46f
maunium.net/go/mautrix.(*Client).Sync(...)
/home/user/go/pkg/mod/maunium.net/go/[email protected]/client.go:225
gitlab.com/example.com/bot/matrix.(*Bot).Start(0xc00014c400)
/home/user/projects/example.com/bot/matrix/bot.go:159 +0x8c
main.main()
/home/user/projects/example.com/bot/cmd/cmd.go:46 +0x19f
Please, help me to fix that
I have a problem with the encryption keys. When I send an encrypted message with this sdk using basically this code, the encryption keys won't go to all of my devices. e.g. my phone can only decrypt the message if my desktop client is open. Is there a way to send the keys to all of my sessions and not only to one?
Hello, im use UploadBytes()
for upload a file , but... how send this file in a room?
looking for go libs to create a go bot for matrix but since most channels are encrypted I need it to support OLM for e2ee. does mautrix-go supports this? will it support it?
The Matrix developers have deprecated libolm. I haven't seen an official statement about why, but, based on the timing, it seems that this is because there's a vulnerability of some sort with a coordinated disclosure deadline of August 14. The official replacement for libolm is vodozemac, but it's written in Rust and they don't appear to have any official C API that I could find.
I see you already have a pure-Go implementation of the Olm protocol, so my suggestion would be that you switch to that (and address the vulnerability, whatever it is, if it's a protocol vulnerability instead of an implementation flaw in libolm).
As a side point, and please let me know if there's a better place to ask this question: Has there been a cryptographic audit of goolm?
I would like to know how do you do to do not have any passwords/secrets in the config file.
It is a bad practice to have any secrets in a file. I use the kubernetes orchestrator to store the config file but we can use ENV vars or passing options to set the secrets.
We can considerate this as a new feature.
The spec says you get a 400 if thread_id
is invalid for some way, and when the imessage bridge tries to MarkRead
, synapse says synapse.http.server - 108 - INFO - POST-5463- <XForwardedForRequest at 0xpointer method='POST' uri='/_matrix/client/v3/rooms/REDACTED/receipt/m.read/REDACTED?user_id=@REDACTED' clientproto='HTTP/1.1' site='RED'> SynapseError: 400 - Content must be a JSON object.
Whenever call events arrive, we get a log message like this:
DEBUG [2021-05-06T22:22:26.606378555Z] Failed to parse content of [$tFsRCPRjzbsPMfBBDPwtygFdo0PPa2rd67yKWZJdFYU m.call.hangup unsupported content type m.call.hangup (message)] (%!s(MISSING)): %!v(MISSING)
It looks like this is just because the Call events types aren't recognised as Message events in GuessClass
- looks like the structures are all there so I guess the types just need to be added here?
Also I'm not sure where the %s(MISSING) stuff is coming from in the log line. For unknown event types, maybe something like, "Unknown message type /: not parsing" would be a better debug log?
Do we have any example on how to use it?
Hi there,
I use following code to login:
_, err := client.Login(&mautrix.ReqLogin{
Type: "m.login.password",
Identifier: mautrix.UserIdentifier{
Type: mautrix.IdentifierTypeUser,
User: username,
},
Password: password,
StoreCredentials: true,
})
after upgrade to v0.9.25 it panics with following stack trace:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x79da10]
goroutine 1 [running]:
maunium.net/go/mautrix.(*Client).Login(0xc00020a2a0, 0xc0001c4540)
/home/rakshazi/go/pkg/mod/maunium.net/go/[email protected]/client.go:697 +0x370
...
I'd like to use client.Store
to inspect the joined rooms and memebers without sending explicit requests that are prone to race conditions. However, I also need my bot not to answer to old messages so I use mautrix.OldEventIgnorer
for that purpose like this:
var oei mautrix.OldEventIgnorer
oei.Register(client.Syncer.(mautrix.ExtensibleSyncer))
Then I register store updates:
client.Syncer.(*mautrix.DefaultSyncer).OnEvent(client.Store.(*mautrix.InMemoryStore).UpdateState)
Then I access the room list later after sync (in response to a user command) like this:
client.Store.(*mautrix.InMemoryStore).Rooms
And this map is empty because the initial sync gets skipped completely according to the OldEventIgnorer
logic. The bot will only update the room states for new rooms that it joins after launch but not for everything that happened before. Is there any way to make it work?
PS: for now I made it work with this simple handler:
func skipOldMessages(resp *mautrix.RespSync, since string) bool {
if since != "" {
return true
}
for id, r := range resp.Rooms.Join {
events := []*event.Event{}
for _, e := range r.Timeline.Events {
if e.Type.Class != event.MessageEventType {
events = append(events, e)
}
}
r.Timeline.Events = events
resp.Rooms.Join[id] = r
}
return true
}
It simply removes all message events from the initial sync but leaves everything else intact so the other handlers can populate the initial state. It can't handle more complex situations when the bot leaves and rejoins later (unlike the vanilla implementation) but currently I don't need this functionality. Maybe these two approaches can be combined?
I am trying to get the sqlstore running with MySQL, therefore I chose the dialect "sqlite3" as it seems like only sqlite3 and postgres are supported (however I did not find any documentation on that) and it should work with a MySQL flavored database.
But as soon as I call CreateTables()
it fails due to invalid syntax as the commands executed include the datatype "bytea" which is not available in slqlite nor mysql.
SQL Error
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'bytea NOT NULL
Sample code
cryptoStore := crypto.NewSQLCryptoStore(db, "sqlite3", account, id.DeviceID(config.DeviceID), []byte(config.DeviceKey), cryptoLogger{"Crypto"})
err := cryptoStore.CreateTables()
if err != nil {
panic (err)
}
Hi, it looks like applications using mautrix-go quietly continue running even after a homerserver restart but after the restart don't get any new messages anymore.
Is there something in my application I need to do to handle this?
I currently basically use
syncer := client.Syncer.(*mautrix.DefaultSyncer)
syncer.OnEventType(...) { ... }
client.Sync()
Can i send an encrypted message to room? And how?
It appears that Client.SendReaction
is not doing anything. Running against synapse 1.22.1.
Took the example app and added a line with hardcoded room and event id:
resp, err := client.SendReaction("!xpfpdJfdQocOPCHqsc:matrix.ilikeorangutans.me", "$JdonuOlEtCTip1dTQBHkh-VhN6J_y6PhANtvRbmSJTY", "❤️")
// error handling ...
There's no error being returned and I get an event id but the reaction doesn't show up in any other client.
Am I doing something wrong?
Commit 1380e23 breaks mautrix/go build on go 1.15.
os.CreateTemp
is introduced in go 1.16, and will be failed to build on go 1.15 like:
go vet ./...
# maunium.net/go/mautrix
Error: ../../../go/pkg/mod/maunium.net/go/[email protected]/client.go:447:15: undefined: os.CreateTemp
make: *** [Makefile:19: vet] Error 2
Error: Process completed with exit code 2.
Related build log: https://github.com/beyondstorage/go-community/pull/34/checks?check_run_id=3648623888
mautrix/go
should be able to build on go 1.14
as described in go.mod
:
So here are some possible fixes:
go 1.14
to go 1.16
.ioutil.TempFile
instead.To avoid those problems, maybe we can introduce GitHub actions to build upon all supported go versions?
https://matrix.org/blog/2021/09/13/vulnerability-disclosure-key-sharing
Can someone address these vulnerabilities, and whether mautrix and apps like gomuks are affected by either or both of them?
It uses reflection which slows things down at runtime.
Looks like we could consider Code generating it .
it will also open up possibilities of building wasm based gui with tinygo if that’s your cup of tea.. tinygo does not support reflection because it’s a non garbage collection compiler I believe but could be wrong
I was wrong :)
https://tinygo.org/docs/reference/lang-support/ Says it does garbage collection
How to send image to a room? SendImage()
?
Excuse me, could you please make an example of sending an image to the room?
Don't know if I'm missing something, but I have the scenario where I have a config of the RoomIDs to check/send a message to (it might not be one that is joined yet). To interact with the rooms I need to pass an actual type of id.RoomID - which I'm unable to do since it isn't exported.
Can we get a simple function that could convert a string into a type of id.RoomID?
mautrix-python uses set-pl <level> [mxid]
mautrix-go uses set-pl [user ID] <power level>
This is inconsistent. I filed the bug here, because the majority of bridges are python, so if this is changed, it should probably be changed in mautrix-go. Although I think the mautrix-go version is more intuitive.
https://matrix.org/docs/spec/appendices#user-identifiers specifies that the localpart of a Matrix user ID must be at least 1 character, but UserID.Parse()
accepts user IDs with an empty (i.e. 0 char) localpart.
When running for the first time the example (https://github.com/mautrix/go/tree/master/example), i.e. the DB is still absent, the app enters into the eternal loop:
Sep 7 22:48:33 DBG Didn't get session, giving up component=crypto event_id=$safN7AYO6xeXslY... session_id=5g9ToVb5FWMSskJ...
Sep 7 22:48:35 DBG Decrypting received event component=crypto event_id=$WxZZxuYcL6G0cdzRra... session_id=2wQfe...
Sep 7 22:48:35 DBG Couldn't find session, requesting keys and waiting longer... component=crypto event_id=$OGcdkw... session_id=TtZEX1xUIRvrEWwFWt... wait_seconds=22
Sep 7 22:48:35 DBG Couldn't find session, waiting for keys to arrive... component=crypto event_id=$WxZZxuYcL6... session_id=2wQfe...
Sep 7 22:48:35 DBG Sending request body={...} method=PUT req_id=14 url=https://matrix-client.matrix.org/_matrix/client/v3/sendToDevice/m.room_key_request/...
Sep 7 22:48:36 DBG Request completed duration=672.420254 method=PUT path=/v3/sendToDevice/m.room_key_request/... req_id=14 response_length=2 response_mime=application/json status_code=200
Sep 7 22:48:36 DBG Sent key request component=crypto device_id=... room_id=!ErrZ...:matrix.org session_id=TtZEX1xU... user_id=...
Sep 7 22:48:36 DBG Didn't get session, giving up component=crypto event_id=$s0uowRHgRRCf.... session_id=FUVV....
If you cancel the execution and start the app again, from the second run and on everything works fine. It seems there's the problem with the DB creation and initial population.
We now get:
DEBU[2021-07-05 14:08:23.275] Failed to parse content of [$AksdclQoima3XlUHHSWaeK3XUQes62uGgFUjWqfySnA m.call.invite json: cannot unmarshal string into Go struct field CallInviteEventContent.version of type int] (%!s(MISSING)): %!v(MISSING)
on incoming voip events
This field changed to a string in voip version 1 to allow us to support namespaced versions, so I'm afraid it can now be either a string or an int.
$ go mod init test
go: creating new go.mod: module test
$ go get maunium.net/go/mautrix@HEAD
go: finding maunium.net HEAD
go: finding maunium.net/go/mautrix HEAD
go: finding maunium.net/go HEAD
go: downloading maunium.net/go/mautrix v0.1.0-alpha.3.0.20200209182939-9df6760d40d2
go: extracting maunium.net/go/mautrix v0.1.0-alpha.3.0.20200209182939-9df6760d40d2
go get: maunium.net/go/[email protected] requires
gopkg.in/russross/[email protected]: go.mod has non-....v2 module path "github.com/russross/blackfriday/v2" at revision v2.0.1
Hi, I want my clients to be able to create and join private rooms. I can create private rooms. However, I couldn't find out how the web clients know that the have been invited to join a room. I also couldn't find out what kind of event gets sent upon an invite in the client-server API specification. Can you guys help me how to write a handler for invites?
They don't have a session_id
, so they can't be stored in the inbound megolm session table
It doesn't seem to bee too buggy anymore and would be useful for homeservers using sso. Maybe use the com.devture.shared_secret_auth
flow if /_matrix/client/r0/login
doesn't report m.login.password
as supported.
Since the olm stuff depends on C libraries, it would be nice if the c dep could be disabled with build tags.
Matrix 1.4 allows to send private read receipts. I would like to add this feature as a preference in gomuks.
Currently it uses MarkRead
function:
Line 1526 in d0c13d2
Maybe MarkReadPrivate
can be added ? I can try to add it if you think this is a good way to do it.
Funny title but I can't figure out how to get the names of the rooms in a space.
I'm stuck with only the roomIDs from room.State[event.StateSpaceChild].
I tried getting the state events with client.State(roomID) but it gets denied due to permissions.
I see there is a GET /hierarchy api which I don't think is in mautrix yet. Would that be the only way? Thank you.
Hi! I'm interested in building bridges on top of this library, but there's currently little documentation or examples of what needs to be implemented, or what the bridge lifecycle is, which makes getting started a bit hard.
Is there a very basic bridge that implements the bare-minimum that could be used as a base for starting? I'm currently reading through the code of the slack and gmessages bridges
I'm working on adding space
to mautrix/whatsapp and came to know mautrix/go hasn't implemented the m.space.parent
type.
For now I'm defining it manually using
Type: event.Type{Type: "m.space.parent", Class: event.StateEventType},
But opened this issue to track the progress for this feature (can close it if it is tracked else-where)
In
https://github.com/tulir/mautrix-go/blob/fdceb4cac97f5717358367ab8a19533d0ad375e3/crypto/olm/account.go#L214
the Ed25519 (fingerprint / signing if I'm not mistaken) key is returned first and Curve25519 (identity) key second, but
https://github.com/tulir/mautrix-go/blob/fdceb4cac97f5717358367ab8a19533d0ad375e3/crypto/account.go#L30
https://github.com/tulir/mautrix-go/blob/fdceb4cac97f5717358367ab8a19533d0ad375e3/crypto/account.go#L37 https://github.com/tulir/mautrix-go/blob/fdceb4cac97f5717358367ab8a19533d0ad375e3/crypto/account.go#L44
instead consider the identity key comes first.
If I'm correct, the keys' types in OlmAccount
should also be switched.
Hi!
I've just started with Go and want to rewrite my bot (php-code).
So far I get messages and mark them as read without a problem. But I don't see any way to get only unread messages.
On php I'm using the next_batch with the count of unread messages per room (rooms//messages?from=<next_batch>&dir=b&limit=<unread_count>)
I've seen next_batch in the source, but still don't get how I can use it >.<
How do I achieve this? :)
It would be good to have another example showing how encryption is used.
After many hours of trial and error along with looking through the gomuks source code I have got basic E2EE working with this library, but am unsure if I am doing it the right way.
I also can't figure out to keep E2EE working across restarts, even when I persist the crypto store, token and device id I am just met with "no session with given id found" errors.
A code example showing the right way to get encryption working with this library would really help me.
Alternatively a high-level "checklist" of everything that needs to be set up would be equally useful, e.g. what event listeners need to be set up, what functions need to be called, what data needs to be persisted etc.
Hi !
I'm starting using matrix and would like to use go mautrix in order to handle room membership with an admin.
I saw you already have implemented a client, a method to register and also methods to do actions on users.
So I would like to create a new file roommembershipapi.go in synapseadmin folder and implement this:
https://matrix-org.github.io/synapse/latest/admin_api/room_membership.html
What do you think about it?
Have a good day :)
Thank you for this library. I've just been struggling to get the human readable names of rooms like "General" and "Random".
I think room.GetStateEvent(event.StateRoomName, "")
is what I need but I'm just getting nil
.
Here's an example program:
package main
import (
"fmt"
"maunium.net/go/mautrix"
"maunium.net/go/mautrix/event"
)
func login(client *mautrix.Client, user, password string) (*mautrix.RespLogin, error) {
return client.Login(&mautrix.ReqLogin{
Type: "m.login.password",
Identifier: mautrix.UserIdentifier{
Type: mautrix.IdentifierTypeUser,
User: user,
},
Password: password,
})
}
const (
user = // put username
password = // put password
)
func main() {
client, err := mautrix.NewClient("https://matrix.org", "", "")
resp, err := login(client, user, password)
if err != nil {
panic("Failed to log in.")
}
client.SetCredentials(resp.UserID, resp.AccessToken)
response, err := client.JoinedRooms()
if err != nil {
panic("Failed to get rooms.")
}
// Prints: [!UbWBtSLQIpZcZJsLXn:matrix.org !BVmJKGPchhqhmdbKoq:matrix.org !hMdfRMncIdgqvhSUZK:matrix.org]
fmt.Println("roomIDs:", response.JoinedRooms)
for _, roomID := range response.JoinedRooms {
room := mautrix.NewRoom(roomID)
// Prints <nil> for each of them :(
fmt.Println(room.GetStateEvent(event.StateRoomName, ""))
}
}
Any idea of what's wrong? Thank you.
I tried to run "./build.sh" Under /opt/mautrix-whatsapp.
Below error is prompted.
maunium.net/go/mautrix-whatsapp/database
database/backfillqueue.go:34:6: BackfillType redeclared in this block
database/backfill.go:34:6: other declaration of BackfillType
database/backfillqueue.go:37:2: BackfillImmediate redeclared in this block
database/backfill.go:37:2: other declaration of BackfillImmediate
database/backfillqueue.go:38:2: BackfillForward redeclared in this block
database/backfill.go:38:2: other declaration of BackfillForward
database/backfillqueue.go:39:2: BackfillDeferred redeclared in this block
database/backfill.go:39:2: other declaration of BackfillDeferred
database/backfillqueue.go:42:24: method BackfillType.String already declared at database/backfill.go:42:24
database/backfillstate.go:27:22: *BackfillState does not satisfy dbutil.DataStruct[*BackfillState] (wrong type for method Scan)
have Scan(dbutil.Scannable) *BackfillState
want Scan(dbutil.Scannable) (*BackfillState, error)
database/backfillstate.go:67:6: BackfillState redeclared in this block
database/backfill.go:285:6: other declaration of BackfillState
database/backfillstate.go:77:25: method BackfillState.Scan already declared at database/backfill.go:297:25
database/backfillstate.go:87:25: method BackfillState.Upsert already declared at database/backfill.go:308:25
database/backfillstate.go:91:25: method BackfillState.SetProcessingBatch already declared at database/backfill.go:324:25
database/backfillstate.go:27:22: too many errors
I tried below command and no luck.
sudo rm -rf /usr/local/go
go clean -modcache
wget https://go.dev/dl/go1.22.3.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.22.3.linux-amd64.tar.gz
Can anyone help me to fix this issue.
Code snippet:
syncer.OnEventType(event.StateMember, func(source mautrix.EventSource, evt *event.Event) {
if evt.Content.AsMember().Membership == event.MembershipJoin {
fmt.Println(client.GetDeviceInfo(id.DeviceID(evt.Sender)))
}
...
Output:
<nil> failed to GET /_matrix/client/r0/devices/@user:homeserver.tld: M_NOT_FOUND (HTTP 404): Not found
This was previously reported in #17, where @tulir responded that
[crypto/olm] already is optional: the crypto module isn't imported from any other module
crypto and crypto/olm are not modules themselves, they're packages within the mautrix/go module, and the rules which govern which packages get compiled are a bit subtle. There are some "tree-shaking" style optimizations at the compilation stage which can elide packages within a module that don't get directly imported, but they're more or less implementation details, so authors can't rely on them to manage optionality in this way.
In short: every package in a module is "part" of that module. Optionality has to be expressed at the module level — i.e. make crypto/olm a separate module altogether — or, if it works, as build constraints in the package — i.e. no-op implementations for unsupported architectures.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.