Telegram adjustments (#378)

Signed-off-by: Ilya Sumbatyants <ilya.sumb@gmail.com>
This commit is contained in:
Ilya Sumbatyants 2021-11-26 18:31:44 +07:00 committed by GitHub
parent 8c8e0f47c6
commit b34b736263
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 17 deletions

View File

@ -3,3 +3,5 @@ LOGIN_ENDPOINT=ws://localhost:3333
LOGIN_TOKEN_DEV=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6InJvc2FtdW5kQGhjLmVuZ2luZWVyaW5nIiwid29ya3NwYWNlIjoidHJ4NDAifQ.dYsCF2VRbuc-zmRt0yLAww1_--xtX4P1EqPFREEzCjQ
LOGIN_ENDPOINT_DEV=wss://transactor.hc.engineering/
TELEGRAM_URL=http://localhost:8086

View File

@ -49,7 +49,7 @@ export function configurePlatform() {
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)
if (process.env.CLIENT_TYPE === 'dev') {

View File

@ -13,11 +13,15 @@
// limitations under the License.
-->
<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 setting from '@anticrm/setting'
import type { Integration, IntegrationType } from '@anticrm/setting'
import PluginCard from './PluginCard.svelte'
const accountId = getMetadata(login.metadata.LoginEmail)
const typeQuery = createQuery()
const integrationQuery = createQuery()
@ -25,7 +29,7 @@
let integrationTypes: IntegrationType[] = []
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>
<div class="cards-container">

View File

@ -38,7 +38,9 @@
async function disconnect(): Promise<void> {
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>

View File

@ -16,7 +16,7 @@
<script lang="ts">
import { ReferenceInput } from '@anticrm/text-editor'
import { createQuery, getClient } from '@anticrm/presentation'
import { createQuery } from '@anticrm/presentation'
import telegram from '@anticrm/telegram'
import type { TelegramMessage } from '@anticrm/telegram'
import type { Contact, EmployeeAccount } from '@anticrm/contact'
@ -36,8 +36,8 @@
let messages: TelegramMessage[] = []
let accounts: EmployeeAccount[] = []
let enabled: boolean
const url = getMetadata(login.metadata.TelegramUrl) ?? ''
const client = getClient()
const messagesQuery = createQuery()
const accauntsQuery = createQuery()
const settingsQuery = createQuery()
@ -57,11 +57,17 @@
enabled = res.length > 0
})
function onMessage(event: CustomEvent) {
client.createDoc(telegram.class.Message, object.space, {
content: event.detail,
incoming: Boolean(Math.round(Math.random())),
...query
async function onMessage(event: CustomEvent) {
await fetch(url + '/send-msg', {
method: 'POST',
headers: {
Authorization: 'Bearer ' + getMetadata(login.metadata.LoginToken),
'Content-Type': 'application/json'
},
body: JSON.stringify({
to: contactString?.value ?? '',
msg: event.detail
})
})
}

View File

@ -28,25 +28,24 @@
let code: string = ''
let password: string = ''
let error: string | undefined = undefined
const url = getMetadata(login.metadata.TelegramUrl)
const url = getMetadata(login.metadata.TelegramUrl) ?? ''
async function requestCode(): Promise<void> {
dispatch('close', { value: phone }) //todo, remove after enable service
const res = await sendRequest('/auth', { phone: phone })
const res = await sendRequest('/signin', { phone })
if (res.next === 'code') {
requested = true
}
}
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') {
dispatch('close', { value: phone })
dispatch('close')
}
}
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') {
secondFactor = true
} else if (res.next === 'end') {
@ -72,7 +71,6 @@
if (res.err != null) {
throw new Error(res.err)
}
return res
}
function back() {