mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-16 13:21:57 +00:00
Telegram adjustments (#378)
Signed-off-by: Ilya Sumbatyants <ilya.sumb@gmail.com>
This commit is contained in:
parent
8c8e0f47c6
commit
b34b736263
@ -3,3 +3,5 @@ LOGIN_ENDPOINT=ws://localhost:3333
|
|||||||
|
|
||||||
LOGIN_TOKEN_DEV=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6InJvc2FtdW5kQGhjLmVuZ2luZWVyaW5nIiwid29ya3NwYWNlIjoidHJ4NDAifQ.dYsCF2VRbuc-zmRt0yLAww1_--xtX4P1EqPFREEzCjQ
|
LOGIN_TOKEN_DEV=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6InJvc2FtdW5kQGhjLmVuZ2luZWVyaW5nIiwid29ya3NwYWNlIjoidHJ4NDAifQ.dYsCF2VRbuc-zmRt0yLAww1_--xtX4P1EqPFREEzCjQ
|
||||||
LOGIN_ENDPOINT_DEV=wss://transactor.hc.engineering/
|
LOGIN_ENDPOINT_DEV=wss://transactor.hc.engineering/
|
||||||
|
|
||||||
|
TELEGRAM_URL=http://localhost:8086
|
||||||
|
@ -49,7 +49,7 @@ export function configurePlatform() {
|
|||||||
setMetadata(login.metadata.UploadUrl, value.UPLOAD_URL)
|
setMetadata(login.metadata.UploadUrl, value.UPLOAD_URL)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
setMetadata(login.metadata.TelegramUrl, process.env.TELEGRAM_URL)
|
setMetadata(login.metadata.TelegramUrl, process.env.TELEGRAM_URL ?? 'http://localhost:8086')
|
||||||
setMetadata(login.metadata.OverrideEndpoint, process.env.LOGIN_ENDPOINT)
|
setMetadata(login.metadata.OverrideEndpoint, process.env.LOGIN_ENDPOINT)
|
||||||
|
|
||||||
if (process.env.CLIENT_TYPE === 'dev') {
|
if (process.env.CLIENT_TYPE === 'dev') {
|
||||||
|
@ -13,11 +13,15 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
-->
|
-->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import type { Ref, Space } from '@anticrm/core';
|
||||||
|
import { getMetadata } from '@anticrm/platform';
|
||||||
|
import login from '@anticrm/login'
|
||||||
import { createQuery } from '@anticrm/presentation'
|
import { createQuery } from '@anticrm/presentation'
|
||||||
import setting from '@anticrm/setting'
|
import setting from '@anticrm/setting'
|
||||||
import type { Integration, IntegrationType } from '@anticrm/setting'
|
import type { Integration, IntegrationType } from '@anticrm/setting'
|
||||||
import PluginCard from './PluginCard.svelte'
|
import PluginCard from './PluginCard.svelte'
|
||||||
|
|
||||||
|
const accountId = getMetadata(login.metadata.LoginEmail)
|
||||||
const typeQuery = createQuery()
|
const typeQuery = createQuery()
|
||||||
const integrationQuery = createQuery()
|
const integrationQuery = createQuery()
|
||||||
|
|
||||||
@ -25,7 +29,7 @@
|
|||||||
let integrationTypes: IntegrationType[] = []
|
let integrationTypes: IntegrationType[] = []
|
||||||
|
|
||||||
typeQuery.query(setting.class.IntegrationType, {}, (res) => (integrationTypes = res))
|
typeQuery.query(setting.class.IntegrationType, {}, (res) => (integrationTypes = res))
|
||||||
integrationQuery.query(setting.class.Integration, {}, (res) => (integrations = res))
|
integrationQuery.query(setting.class.Integration, { space: accountId as Ref<Space> }, (res) => (integrations = res))
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="cards-container">
|
<div class="cards-container">
|
||||||
|
@ -38,7 +38,9 @@
|
|||||||
|
|
||||||
async function disconnect(): Promise<void> {
|
async function disconnect(): Promise<void> {
|
||||||
if (integration !== undefined) {
|
if (integration !== undefined) {
|
||||||
await client.removeDoc(setting.class.Integration, accountId as Ref<Space>, integration._id)
|
// TODO: Need to call proper endpoint, so likely should not be here but in specific integration plugins
|
||||||
|
|
||||||
|
// await client.removeDoc(setting.class.Integration, accountId as Ref<Space>, integration._id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
|
||||||
import { ReferenceInput } from '@anticrm/text-editor'
|
import { ReferenceInput } from '@anticrm/text-editor'
|
||||||
import { createQuery, getClient } from '@anticrm/presentation'
|
import { createQuery } from '@anticrm/presentation'
|
||||||
import telegram from '@anticrm/telegram'
|
import telegram from '@anticrm/telegram'
|
||||||
import type { TelegramMessage } from '@anticrm/telegram'
|
import type { TelegramMessage } from '@anticrm/telegram'
|
||||||
import type { Contact, EmployeeAccount } from '@anticrm/contact'
|
import type { Contact, EmployeeAccount } from '@anticrm/contact'
|
||||||
@ -36,8 +36,8 @@
|
|||||||
let messages: TelegramMessage[] = []
|
let messages: TelegramMessage[] = []
|
||||||
let accounts: EmployeeAccount[] = []
|
let accounts: EmployeeAccount[] = []
|
||||||
let enabled: boolean
|
let enabled: boolean
|
||||||
|
const url = getMetadata(login.metadata.TelegramUrl) ?? ''
|
||||||
|
|
||||||
const client = getClient()
|
|
||||||
const messagesQuery = createQuery()
|
const messagesQuery = createQuery()
|
||||||
const accauntsQuery = createQuery()
|
const accauntsQuery = createQuery()
|
||||||
const settingsQuery = createQuery()
|
const settingsQuery = createQuery()
|
||||||
@ -57,11 +57,17 @@
|
|||||||
enabled = res.length > 0
|
enabled = res.length > 0
|
||||||
})
|
})
|
||||||
|
|
||||||
function onMessage(event: CustomEvent) {
|
async function onMessage(event: CustomEvent) {
|
||||||
client.createDoc(telegram.class.Message, object.space, {
|
await fetch(url + '/send-msg', {
|
||||||
content: event.detail,
|
method: 'POST',
|
||||||
incoming: Boolean(Math.round(Math.random())),
|
headers: {
|
||||||
...query
|
Authorization: 'Bearer ' + getMetadata(login.metadata.LoginToken),
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
to: contactString?.value ?? '',
|
||||||
|
msg: event.detail
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,25 +28,24 @@
|
|||||||
let code: string = ''
|
let code: string = ''
|
||||||
let password: string = ''
|
let password: string = ''
|
||||||
let error: string | undefined = undefined
|
let error: string | undefined = undefined
|
||||||
const url = getMetadata(login.metadata.TelegramUrl)
|
const url = getMetadata(login.metadata.TelegramUrl) ?? ''
|
||||||
|
|
||||||
async function requestCode(): Promise<void> {
|
async function requestCode(): Promise<void> {
|
||||||
dispatch('close', { value: phone }) //todo, remove after enable service
|
const res = await sendRequest('/signin', { phone })
|
||||||
const res = await sendRequest('/auth', { phone: phone })
|
|
||||||
if (res.next === 'code') {
|
if (res.next === 'code') {
|
||||||
requested = true
|
requested = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendPassword(): Promise<void> {
|
async function sendPassword(): Promise<void> {
|
||||||
const res = await sendRequest('/auth/pass', { pass: password })
|
const res = await sendRequest('/signin/pass', { phone, pass: password })
|
||||||
if (res.next === 'end') {
|
if (res.next === 'end') {
|
||||||
dispatch('close', { value: phone })
|
dispatch('close')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendCode(): Promise<void> {
|
async function sendCode(): Promise<void> {
|
||||||
const res = await sendRequest('/auth/code', { code: code })
|
const res = await sendRequest('/signin/code', { phone, code: code })
|
||||||
if (res.next === 'pass') {
|
if (res.next === 'pass') {
|
||||||
secondFactor = true
|
secondFactor = true
|
||||||
} else if (res.next === 'end') {
|
} else if (res.next === 'end') {
|
||||||
@ -72,7 +71,6 @@
|
|||||||
if (res.err != null) {
|
if (res.err != null) {
|
||||||
throw new Error(res.err)
|
throw new Error(res.err)
|
||||||
}
|
}
|
||||||
return res
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function back() {
|
function back() {
|
||||||
|
Loading…
Reference in New Issue
Block a user