Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit a7e6d8e

Browse files
authored
Merge pull request #5396 from matrix-org/dbkr/query_for_phone_numbers
Support thirdparty lookup for phone numbers
2 parents cbd568a + 333b138 commit a7e6d8e

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/SlashCommands.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,14 +1001,29 @@ export const Commands = [
10011001
description: _td("Opens chat with the given user"),
10021002
args: "<user-id>",
10031003
runFn: function(roomId, userId) {
1004-
if (!userId || !userId.startsWith("@") || !userId.includes(":")) {
1004+
// easter-egg for now: look up phone numbers through the thirdparty API
1005+
// (very dumb phone number detection...)
1006+
const isPhoneNumber = userId && /^\+?[0123456789]+$/.test(userId);
1007+
if (!userId || (!userId.startsWith("@") || !userId.includes(":")) && !isPhoneNumber) {
10051008
return reject(this.getUsage());
10061009
}
10071010

10081011
return success((async () => {
1012+
if (isPhoneNumber) {
1013+
const results = await MatrixClientPeg.get().getThirdpartyUser('im.vector.protocol.pstn', {
1014+
'm.id.phone': userId,
1015+
});
1016+
if (!results || results.length === 0 || !results[0].userid) {
1017+
throw new Error("Unable to find Matrix ID for phone number");
1018+
}
1019+
userId = results[0].userid;
1020+
}
1021+
1022+
const roomId = await ensureDMExists(MatrixClientPeg.get(), userId);
1023+
10091024
dis.dispatch({
10101025
action: 'view_room',
1011-
room_id: await ensureDMExists(MatrixClientPeg.get(), userId),
1026+
room_id: roomId,
10121027
});
10131028
})());
10141029
},

0 commit comments

Comments
 (0)