6bf8bebf51
CI / Test and Build (push) Failing after 1s
CI / Migrate Dev DB (push) Has been skipped
CI / Migrate DB (push) Has been skipped
CodeQL / Analyze actions (push) Has been cancelled
CodeQL / Analyze javascript-typescript (push) Has been cancelled
CI / Detect Version (push) Has been cancelled
CI / Detect Desktop Changes (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/cron.Dockerfile, ubuntu-latest, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build AMD64 (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/cron.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/db.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/pii.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/realtime.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-8vcpu-ubuntu-2404-arm, ./docker/app.Dockerfile, linux-arm64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
Helm Chart / Lint, test, and validate chart (push) Has been cancelled
Helm Chart / Chart version bumped (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
CI / Build Dev ECR (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core) (push) Has been cancelled
CI / Promote Images (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Check Desktop Signing Secrets (push) Has been cancelled
CI / Desktop Release (push) Has been cancelled
CI / Create Desktop Prerelease (push) Has been cancelled
CI / Desktop Prerelease Build (push) Has been cancelled
CI / Publish Desktop Prerelease (push) Has been cancelled
CI / Prune Desktop Prereleases (push) Has been cancelled
Helm Chart / Install on kind and run helm test (push) Has been cancelled
151 lines
4.4 KiB
TypeScript
151 lines
4.4 KiB
TypeScript
import type {
|
|
MicrosoftTeamsToolParams,
|
|
MicrosoftTeamsWriteResponse,
|
|
} from '@/tools/microsoft_teams/types'
|
|
import type { ToolConfig } from '@/tools/types'
|
|
|
|
export const writeChatTool: ToolConfig<MicrosoftTeamsToolParams, MicrosoftTeamsWriteResponse> = {
|
|
id: 'microsoft_teams_write_chat',
|
|
name: 'Write to Microsoft Teams Chat',
|
|
description: 'Write or update content in a Microsoft Teams chat',
|
|
version: '1.0',
|
|
errorExtractor: 'nested-error-object',
|
|
oauth: {
|
|
required: true,
|
|
provider: 'microsoft-teams',
|
|
},
|
|
params: {
|
|
accessToken: {
|
|
type: 'string',
|
|
required: true,
|
|
visibility: 'hidden',
|
|
description: 'The access token for the Microsoft Teams API',
|
|
},
|
|
chatId: {
|
|
type: 'string',
|
|
required: true,
|
|
visibility: 'user-or-llm',
|
|
description:
|
|
'The ID of the chat to write to (e.g., "19:abc123def456@thread.v2" - from chat listings)',
|
|
},
|
|
content: {
|
|
type: 'string',
|
|
required: true,
|
|
visibility: 'user-or-llm',
|
|
description:
|
|
'The content to write to the message (plain text or HTML formatted, supports @mentions)',
|
|
},
|
|
files: {
|
|
type: 'file[]',
|
|
required: false,
|
|
visibility: 'user-only',
|
|
description: 'Files to attach to the message',
|
|
},
|
|
},
|
|
|
|
outputs: {
|
|
success: { type: 'boolean', description: 'Teams chat message send success status' },
|
|
messageId: { type: 'string', description: 'Unique identifier for the sent message' },
|
|
chatId: { type: 'string', description: 'ID of the chat where message was sent' },
|
|
createdTime: { type: 'string', description: 'Timestamp when message was created' },
|
|
url: { type: 'string', description: 'Web URL to the message' },
|
|
updatedContent: { type: 'boolean', description: 'Whether content was successfully updated' },
|
|
files: { type: 'file[]', description: 'Files attached to the message' },
|
|
},
|
|
|
|
request: {
|
|
url: (params) => {
|
|
// Ensure chatId is valid
|
|
const chatId = params.chatId?.trim()
|
|
if (!chatId) {
|
|
throw new Error('Chat ID is required')
|
|
}
|
|
|
|
// If files are provided, use custom API route for attachment handling
|
|
if (params.files && params.files.length > 0) {
|
|
return '/api/tools/microsoft_teams/write_chat'
|
|
}
|
|
|
|
// If content contains mentions, use custom API route for mention resolution
|
|
const hasMentions = /<at>[^<]+<\/at>/i.test(params.content || '')
|
|
if (hasMentions) {
|
|
return '/api/tools/microsoft_teams/write_chat'
|
|
}
|
|
|
|
return `https://graph.microsoft.com/v1.0/chats/${encodeURIComponent(chatId)}/messages`
|
|
},
|
|
method: 'POST',
|
|
headers: (params) => {
|
|
// Validate access token
|
|
if (!params.accessToken) {
|
|
throw new Error('Access token is required')
|
|
}
|
|
|
|
return {
|
|
Authorization: `Bearer ${params.accessToken}`,
|
|
'Content-Type': 'application/json',
|
|
}
|
|
},
|
|
body: (params) => {
|
|
// Validate content
|
|
if (!params.content) {
|
|
throw new Error('Content is required')
|
|
}
|
|
|
|
// If using custom API route (with files or mentions), pass all params
|
|
const hasMentions = /<at>[^<]+<\/at>/i.test(params.content || '')
|
|
if (params.files && params.files.length > 0) {
|
|
return {
|
|
accessToken: params.accessToken,
|
|
chatId: params.chatId,
|
|
content: params.content,
|
|
files: params.files,
|
|
}
|
|
}
|
|
|
|
if (hasMentions) {
|
|
return {
|
|
accessToken: params.accessToken,
|
|
chatId: params.chatId,
|
|
content: params.content,
|
|
}
|
|
}
|
|
|
|
// Microsoft Teams API expects this specific format
|
|
const requestBody = {
|
|
body: {
|
|
contentType: 'text',
|
|
content: params.content,
|
|
},
|
|
}
|
|
|
|
return requestBody
|
|
},
|
|
},
|
|
transformResponse: async (response: Response, params?: MicrosoftTeamsToolParams) => {
|
|
const data = await response.json()
|
|
|
|
// Handle custom API route response format
|
|
if (data.success !== undefined && data.output) {
|
|
return data
|
|
}
|
|
|
|
// Handle direct Graph API response format
|
|
const metadata = {
|
|
messageId: data.id || '',
|
|
chatId: data.chatId || '',
|
|
content: data.body?.content || params?.content || '',
|
|
createdTime: data.createdDateTime || new Date().toISOString(),
|
|
url: data.webUrl || '',
|
|
}
|
|
|
|
return {
|
|
success: true,
|
|
output: {
|
|
updatedContent: true,
|
|
metadata,
|
|
},
|
|
}
|
|
},
|
|
}
|