Support bot start param in t.me links (#1603)

This commit is contained in:
Alexander Zinchuk 2021-12-24 01:25:56 +01:00
parent f974f86c6d
commit 0196153ab2

View File

@ -593,6 +593,7 @@ addReducer('openTelegramLink', (global, actions, payload) => {
username: part1, username: part1,
messageId: messageId || Number(chatOrChannelPostId), messageId: messageId || Number(chatOrChannelPostId),
commentId, commentId,
startParam: params.start,
}); });
} }
}); });
@ -610,7 +611,9 @@ addReducer('acceptInviteConfirmation', (global, actions, payload) => {
}); });
addReducer('openChatByUsername', (global, actions, payload) => { addReducer('openChatByUsername', (global, actions, payload) => {
const { username, messageId, commentId } = payload!; const {
username, messageId, commentId, startParam,
} = payload!;
(async () => { (async () => {
const chat = selectCurrentChat(global); const chat = selectCurrentChat(global);
@ -620,7 +623,7 @@ addReducer('openChatByUsername', (global, actions, payload) => {
actions.focusMessage({ chatId: chat.id, messageId }); actions.focusMessage({ chatId: chat.id, messageId });
return; return;
} }
await openChatByUsername(actions, username, messageId); await openChatByUsername(actions, username, messageId, startParam);
return; return;
} }
@ -1258,6 +1261,7 @@ async function openChatByUsername(
actions: GlobalActions, actions: GlobalActions,
username: string, username: string,
channelPostId?: number, channelPostId?: number,
startParam?: string,
) { ) {
// Open temporary empty chat to make the click response feel faster // Open temporary empty chat to make the click response feel faster
actions.openChat({ id: TMP_CHAT_ID }); actions.openChat({ id: TMP_CHAT_ID });
@ -1275,6 +1279,9 @@ async function openChatByUsername(
} else { } else {
actions.openChat({ id: chat.id }); actions.openChat({ id: chat.id });
} }
if (startParam) {
actions.startBot({ botId: chat.id, param: startParam });
}
} }
async function openCommentsByUsername( async function openCommentsByUsername(