mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-22 19:11:33 +03:00
Add telegram template field (#2941)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
parent
2574918a32
commit
aac44d065c
@ -36,6 +36,7 @@
|
||||
"@hcengineering/contact": "^0.6.12",
|
||||
"@hcengineering/telegram": "^0.6.5",
|
||||
"@hcengineering/telegram-resources": "^0.6.0",
|
||||
"@hcengineering/templates": "^0.6.1",
|
||||
"@hcengineering/setting": "^0.6.4",
|
||||
"@hcengineering/ui": "^0.6.5"
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ import type {
|
||||
SharedTelegramMessages,
|
||||
TelegramMessage
|
||||
} from '@hcengineering/telegram'
|
||||
import templates from '@hcengineering/templates'
|
||||
import telegram from './plugin'
|
||||
import view from '@hcengineering/view'
|
||||
|
||||
@ -92,6 +93,28 @@ export function createModel (builder: Builder): void {
|
||||
presenter: telegram.component.MessagePresenter
|
||||
})
|
||||
|
||||
builder.createDoc(
|
||||
templates.class.TemplateField,
|
||||
core.space.Model,
|
||||
{
|
||||
label: telegram.string.Telegram,
|
||||
category: contact.templateFieldCategory.CurrentEmployee,
|
||||
func: telegram.function.GetCurrentEmployeeTG
|
||||
},
|
||||
telegram.templateField.CurrentEmployeeTelegram
|
||||
)
|
||||
|
||||
builder.createDoc(
|
||||
templates.class.TemplateField,
|
||||
core.space.Model,
|
||||
{
|
||||
label: telegram.string.Telegram,
|
||||
category: setting.templateFieldCategory.Integration,
|
||||
func: telegram.function.GetIntegrationOwnerTG
|
||||
},
|
||||
telegram.templateField.IntegrationOwnerTG
|
||||
)
|
||||
|
||||
builder.createDoc(
|
||||
activity.class.TxViewlet,
|
||||
core.space.Model,
|
||||
|
@ -15,11 +15,12 @@
|
||||
//
|
||||
|
||||
import { Ref } from '@hcengineering/core'
|
||||
import { IntlString, mergeIds } from '@hcengineering/platform'
|
||||
import { IntlString, Resource, mergeIds } from '@hcengineering/platform'
|
||||
import { telegramId } from '@hcengineering/telegram'
|
||||
import telegram from '@hcengineering/telegram-resources/src/plugin'
|
||||
import type { AnyComponent } from '@hcengineering/ui'
|
||||
import type { TxViewlet } from '@hcengineering/activity'
|
||||
import { TemplateFieldFunc } from '@hcengineering/templates'
|
||||
|
||||
export default mergeIds(telegramId, telegram, {
|
||||
string: {
|
||||
@ -36,6 +37,10 @@ export default mergeIds(telegramId, telegram, {
|
||||
TxMessage: '' as Ref<TxViewlet>,
|
||||
TxSharedCreate: '' as Ref<TxViewlet>
|
||||
},
|
||||
function: {
|
||||
GetCurrentEmployeeTG: '' as Resource<TemplateFieldFunc>,
|
||||
GetIntegrationOwnerTG: '' as Resource<TemplateFieldFunc>
|
||||
},
|
||||
activity: {
|
||||
TxMessage: '' as AnyComponent,
|
||||
TxSharedCreate: '' as AnyComponent
|
||||
|
@ -241,6 +241,8 @@ export interface PersonLabelTooltip {
|
||||
props?: any
|
||||
}
|
||||
|
||||
export * from './utils'
|
||||
|
||||
export default async (): Promise<Resources> => ({
|
||||
actionImpl: {
|
||||
KickEmployee: kickEmployee,
|
||||
|
@ -170,6 +170,16 @@ export async function getContactFirstName (provider: TemplateDataProvider): Prom
|
||||
}
|
||||
}
|
||||
|
||||
export async function getContactChannel (value: Contact, provider: Ref<ChannelProvider>): Promise<string | undefined> {
|
||||
if (value === undefined) return
|
||||
const client = getClient()
|
||||
const res = await client.findOne(contact.class.Channel, {
|
||||
attachedTo: value._id,
|
||||
provider
|
||||
})
|
||||
return res?.value ?? ''
|
||||
}
|
||||
|
||||
export async function getContactLink (doc: Doc): Promise<Location> {
|
||||
const loc = getCurrentLocation()
|
||||
loc.path.length = 2
|
||||
|
@ -24,6 +24,7 @@ import TxMessage from './components/activity/TxMessage.svelte'
|
||||
import IconTelegram from './components/icons/TelegramColor.svelte'
|
||||
import TxSharedCreate from './components/activity/TxSharedCreate.svelte'
|
||||
import { concatLink } from '@hcengineering/core'
|
||||
import { getCurrentEmployeeTG, getIntegrationOwnerTG } from './utils'
|
||||
|
||||
export default async (): Promise<Resources> => ({
|
||||
component: {
|
||||
@ -36,6 +37,10 @@ export default async (): Promise<Resources> => ({
|
||||
TxSharedCreate,
|
||||
TxMessage
|
||||
},
|
||||
function: {
|
||||
GetCurrentEmployeeTG: getCurrentEmployeeTG,
|
||||
GetIntegrationOwnerTG: getIntegrationOwnerTG
|
||||
},
|
||||
handler: {
|
||||
DisconnectHandler: async () => {
|
||||
const url = getMetadata(telegram.metadata.TelegramURL) ?? ''
|
||||
|
46
plugins/telegram-resources/src/utils.ts
Normal file
46
plugins/telegram-resources/src/utils.ts
Normal file
@ -0,0 +1,46 @@
|
||||
//
|
||||
// Copyright © 2023 Hardcore Engineering Inc.
|
||||
//
|
||||
// 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 { employeeByIdStore, getContactChannel } from '@hcengineering/contact-resources'
|
||||
import { Ref, getCurrentAccount } from '@hcengineering/core'
|
||||
import { getClient } from '@hcengineering/presentation'
|
||||
import contact, { EmployeeAccount } from '@hcengineering/contact'
|
||||
import { TemplateDataProvider } from '@hcengineering/templates'
|
||||
import { get } from 'svelte/store'
|
||||
import setting from '@hcengineering/setting'
|
||||
|
||||
export async function getCurrentEmployeeTG (): Promise<string | undefined> {
|
||||
const me = getCurrentAccount() as EmployeeAccount
|
||||
const client = getClient()
|
||||
const employee = await client.findOne(contact.class.Employee, { _id: me.employee })
|
||||
if (employee !== undefined) {
|
||||
return await getContactChannel(employee, contact.channelProvider.Telegram)
|
||||
}
|
||||
}
|
||||
|
||||
export async function getIntegrationOwnerTG (provider: TemplateDataProvider): Promise<string | undefined> {
|
||||
const value = provider.get(setting.class.Integration)
|
||||
if (value === undefined) return
|
||||
const client = getClient()
|
||||
const employeeAccount = await client.findOne(contact.class.EmployeeAccount, {
|
||||
_id: value.modifiedBy as Ref<EmployeeAccount>
|
||||
})
|
||||
if (employeeAccount !== undefined) {
|
||||
const employee = get(employeeByIdStore).get(employeeAccount.employee)
|
||||
if (employee !== undefined) {
|
||||
return await getContactChannel(employee, contact.channelProvider.Telegram)
|
||||
}
|
||||
}
|
||||
}
|
@ -30,6 +30,7 @@
|
||||
"@hcengineering/core": "^0.6.22",
|
||||
"@hcengineering/ui": "^0.6.5",
|
||||
"@hcengineering/contact": "^0.6.12",
|
||||
"@hcengineering/templates": "^0.6.1",
|
||||
"@hcengineering/setting": "^0.6.4"
|
||||
},
|
||||
"repository": "https://github.com/hcengineering/anticrm",
|
||||
|
@ -19,6 +19,7 @@ import type { Doc, Ref, Class, Space, AttachedDoc, Timestamp } from '@hcengineer
|
||||
import type { AnyComponent } from '@hcengineering/ui'
|
||||
import type { IntegrationType, Handler } from '@hcengineering/setting'
|
||||
import { Channel } from '@hcengineering/contact'
|
||||
import { TemplateField } from '@hcengineering/templates'
|
||||
|
||||
/**
|
||||
* @public
|
||||
@ -90,6 +91,10 @@ export default plugin(telegramId, {
|
||||
space: {
|
||||
Telegram: '' as Ref<Space>
|
||||
},
|
||||
templateField: {
|
||||
CurrentEmployeeTelegram: '' as Ref<TemplateField>,
|
||||
IntegrationOwnerTG: '' as Ref<TemplateField>
|
||||
},
|
||||
metadata: {
|
||||
TelegramURL: '' as Metadata<string>
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user