matiaslina / Matrix-Client

Matrix client for Raku
Artistic License 2.0
13 stars 3 forks source link

`get-room-id` shows `M_UNKNOWN: Expected RoomAlias string to start with '#'`, even when input starts with `#` #16

Open Tyil opened 5 years ago

Tyil commented 5 years ago

I'm trying to get the Room ID using get-room-id, so I can start sending messages to the right room only.

my $room-id = $client.get-room-id("#the-life-of-sjon:matrix.org");

However, I keep getting the following error message:

M_UNKNOWN: Expected RoomAlias string to start with '#'
  in method get at /home/tyil/projects/personal/perl6-Local-Sjon/../perl6-Matrix-Client/lib/Matrix/Client/Requester.pm6 (Matrix::Client::Requester) line 43
  in method get-room-id at /home/tyil/projects/personal/perl6-Local-Sjon/../perl6-Matrix-Client/lib/Matrix/Client.pm6 (Matrix::Client) line 316
  in sub MAIN at /home/tyil/projects/personal/perl6-Local-Sjon/lib/Local/Sjon.pm6 (Local::Sjon) line 27
  in block <unit> at bin/sjon line 4

This is confusing, as the string I'm passing does start with a #. Is there any way I can start looking to figure out where it's going wrong?

matiaslina commented 5 years ago

Hey @Tyil,

What's your version of Matrix::Client? I'm trying the same snippet without errors in the latest version (0.5.1)

% perl6
To exit type 'exit' or '^D'
> use Matrix::Client
Nil
> my $c = Matrix::Client.new(:home-server<https://matrix.deprecated.org>);
Matrix::Client.new(device-id => Str, home-server => "https://matrix.deprecated.org", access-token => "")
> $c.get-room-id('#deprecated:matrix.deprecated.org')
!CrhcYlwlZRJtxskYqv:matrix.deprecated.org
> $c.get-room-id('%23deprecated:matrix.deprecated.org')
!CrhcYlwlZRJtxskYqv:matrix.deprecated.org
> $c.get-room-id('#the-life-of-sjon:matrix.org')
!iwJJhLVhPkJqYLeaLg:matrix.org

The fix at the time was replacing # with %23.

Could you try with the latest version?


As an explanation of the error, the room alias is on the URI and not on the query params. Without escaping the # the room alias is taken as a fragment identifier.

% curl 'https://matrix.deprecated.org/_matrix/client/r0/directory/room/%23the-life-of-sjon:matrix.org'
{
    "room_id": "!iwJJhLVhPkJqYLeaLg:matrix.org",
    "servers": [
        "matrix.org"
    ]
}
% curl 'https://matrix.deprecated.org/_matrix/client/r0/directory/room/#the-life-of-sjon:matrix.org'
{
    "errcode": "M_UNKNOWN",
    "error": "Expected RoomAlias string to start with '#'"
}

And that's why you're seeing the M_UNKNOWN: Expected RoomAlias string to start with '#'

Tyil commented 5 years ago

I'm not sure which version I have. I'll try to upgrade it to latest version with zef tomorrow to ensure I'm on the latest release.

-- With kind regards,

Patrick Spek

www: https://www.tyil.nl/ mail: p.spek@tyil.nl pgp: 1660 F6A2 DFA7 5347 322A 4DC0 7A6A C285 E2D9 8827

social: https://soc.fglt.nl/tyil git: https://gitlab.com/tyil/