feat(auth): request secure messenger start sessions
This commit is contained in:
@@ -6,12 +6,13 @@ import {
|
||||
MyNotificationHistoryDocument,
|
||||
SendTestMessengerMessageDocument,
|
||||
} from '~/composables/graphql/generated';
|
||||
import { buildMessengerBotStartUrl } from '~/composables/useMessengerBotLink';
|
||||
import { useMessengerStart } from '~/composables/useMessengerStart';
|
||||
|
||||
const selectedChannel = ref<'TELEGRAM' | 'MAX'>('TELEGRAM');
|
||||
const customMessage = ref('Тест канала уведомлений Fregat');
|
||||
const feedback = ref('');
|
||||
const config = useRuntimeConfig();
|
||||
const { openMessengerBot, pendingChannel } = useMessengerStart();
|
||||
|
||||
const meQuery = useQuery(MeDocument);
|
||||
const connectionsQuery = useQuery(MyMessengerConnectionsDocument);
|
||||
@@ -56,12 +57,24 @@ function buildBotConnectUrl(baseUrl: string) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return buildMessengerBotStartUrl(baseUrl, email);
|
||||
return baseUrl;
|
||||
}
|
||||
|
||||
const telegramConnectUrl = computed(() => buildBotConnectUrl(config.public.telegramBotUrl || ''));
|
||||
const maxConnectUrl = computed(() => buildBotConnectUrl(config.public.maxBotUrl || ''));
|
||||
|
||||
async function connectMessenger(channel: 'TELEGRAM' | 'MAX') {
|
||||
const baseUrl = channel === 'TELEGRAM' ? telegramConnectUrl.value : maxConnectUrl.value;
|
||||
if (!baseUrl) {
|
||||
return;
|
||||
}
|
||||
|
||||
await openMessengerBot({
|
||||
channel,
|
||||
baseUrl,
|
||||
});
|
||||
}
|
||||
|
||||
async function sendTest() {
|
||||
feedback.value = '';
|
||||
if (!activeConnection.value) {
|
||||
@@ -114,15 +127,20 @@ async function sendTest() {
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<a
|
||||
:href="telegramConnectUrl || undefined"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
<button
|
||||
class="btn btn-secondary"
|
||||
:class="{ 'btn-disabled pointer-events-none': !telegramConnectUrl }"
|
||||
:disabled="pendingChannel === 'TELEGRAM' || !telegramConnectUrl"
|
||||
@click="connectMessenger('TELEGRAM')"
|
||||
>
|
||||
{{ telegramConnection ? 'Переподключить Telegram' : 'Подключить Telegram' }}
|
||||
</a>
|
||||
{{
|
||||
pendingChannel === 'TELEGRAM'
|
||||
? 'Открываем Telegram…'
|
||||
: telegramConnection
|
||||
? 'Переподключить Telegram'
|
||||
: 'Подключить Telegram'
|
||||
}}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -139,15 +157,20 @@ async function sendTest() {
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<a
|
||||
:href="maxConnectUrl || undefined"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
<button
|
||||
class="btn btn-accent"
|
||||
:class="{ 'btn-disabled pointer-events-none': !maxConnectUrl }"
|
||||
:disabled="pendingChannel === 'MAX' || !maxConnectUrl"
|
||||
@click="connectMessenger('MAX')"
|
||||
>
|
||||
{{ maxConnection ? 'Переподключить Max' : 'Подключить Max' }}
|
||||
</a>
|
||||
{{
|
||||
pendingChannel === 'MAX'
|
||||
? 'Открываем Max…'
|
||||
: maxConnection
|
||||
? 'Переподключить Max'
|
||||
: 'Подключить Max'
|
||||
}}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user