mirror of
https://github.com/hcengineering/platform.git
synced 2026-10-21 15:31:41 +02:00
* hulygram UI integration Signed-off-by: Alexey Aristov <aav@acm.org> wip Signed-off-by: Alexey Aristov <aav@acm.org> * consider AI robot suggestions Signed-off-by: Alexey Aristov <aav@acm.org> * add missing translations Signed-off-by: Alexey Aristov <aav@acm.org> * corrections after code review Signed-off-by: Alexey Aristov <aav@acm.org> * move api handling to the api.ts module Signed-off-by: Alexey Aristov <aav@acm.org> * account service: register hulygram service id Signed-off-by: Alexey Aristov <aav@acm.org> * correct source code formatting Signed-off-by: Alexey Aristov <aav@acm.org> * correct accounts tests (service name changed) Signed-off-by: Alexey Aristov <aav@acm.org> * minor change (for gh troubleshooting) Signed-off-by: Alexey Aristov <aav@acm.org> --------- Signed-off-by: Alexey Aristov <aav@acm.org>
54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
// Copyright © 2020, 2021 Anticrm Platform Contributors.
|
|
//
|
|
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License. You may
|
|
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
//
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
//
|
|
|
|
import { concatLink } from '@hcengineering/core'
|
|
import { getMetadata } from '@hcengineering/platform'
|
|
import telegram from './plugin'
|
|
import presentation from '@hcengineering/presentation'
|
|
|
|
export type Integration = { status: 'authorized' | 'wantcode' | 'wantpassword', number: string } | 'Loading' | 'Missing'
|
|
|
|
const url = getMetadata(telegram.metadata.TelegramURL) ?? ''
|
|
|
|
async function request (method: 'GET' | 'POST' | 'DELETE', path?: string, body?: any): Promise<any> {
|
|
const base = concatLink(url, 'api/integrations')
|
|
|
|
const response = await fetch(concatLink(base, path ?? ''), {
|
|
method,
|
|
headers: {
|
|
Authorization: 'Bearer ' + getMetadata(presentation.metadata.Token),
|
|
'Content-Type': 'application/json'
|
|
},
|
|
...(body !== undefined ? { body: JSON.stringify(body) } : {})
|
|
})
|
|
|
|
if (response.status === 200) {
|
|
return await response.json()
|
|
} else {
|
|
throw new Error(`Unexpected response: ${response.status}`)
|
|
}
|
|
}
|
|
|
|
export async function list (): Promise<Integration[]> {
|
|
return await request('GET')
|
|
}
|
|
|
|
export async function command (
|
|
phone: string,
|
|
command: 'start' | 'next' | 'cancel',
|
|
input?: string
|
|
): Promise<Integration> {
|
|
return await request('POST', phone, { command, input })
|
|
}
|