chore: import upstream snapshot with attribution
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (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 / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (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 / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
import { ErrorExtractorId } from '@/tools/error-extractors'
|
||||
import type { TelegramCopyMessageParams, TelegramCopyMessageResponse } from '@/tools/telegram/types'
|
||||
import { telegramApiUrl } from '@/tools/telegram/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const telegramCopyMessageTool: ToolConfig<
|
||||
TelegramCopyMessageParams,
|
||||
TelegramCopyMessageResponse
|
||||
> = {
|
||||
id: 'telegram_copy_message',
|
||||
name: 'Telegram Copy Message',
|
||||
description:
|
||||
'Copy a message to another Telegram chat without a forward header through the Telegram Bot API.',
|
||||
version: '1.0.0',
|
||||
errorExtractor: ErrorExtractorId.TELEGRAM_DESCRIPTION,
|
||||
|
||||
params: {
|
||||
botToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Telegram Bot API Token',
|
||||
},
|
||||
chatId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Destination chat ID (numeric, can be negative for groups)',
|
||||
},
|
||||
fromChatId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Source chat ID the original message belongs to',
|
||||
},
|
||||
messageId: {
|
||||
type: 'number',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Identifier of the message to copy in the source chat',
|
||||
},
|
||||
caption: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'New caption for the copied media (keeps the original if omitted)',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params) => telegramApiUrl(params.botToken, 'copyMessage'),
|
||||
method: 'POST',
|
||||
headers: () => ({
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
body: (params) => {
|
||||
const body: Record<string, unknown> = {
|
||||
chat_id: params.chatId,
|
||||
from_chat_id: params.fromChatId,
|
||||
message_id: params.messageId,
|
||||
}
|
||||
if (params.caption) body.caption = params.caption
|
||||
return body
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!data.ok) {
|
||||
const errorMessage = data.description || data.error || 'Failed to copy message'
|
||||
throw new Error(errorMessage)
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
message: 'Message copied successfully',
|
||||
data: {
|
||||
message_id: data.result?.message_id,
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
message: { type: 'string', description: 'Success or error message' },
|
||||
data: {
|
||||
type: 'object',
|
||||
description: 'Copied message identifier',
|
||||
properties: {
|
||||
message_id: { type: 'number', description: 'Identifier of the new copied message' },
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
import { ErrorExtractorId } from '@/tools/error-extractors'
|
||||
import type {
|
||||
TelegramDeleteMessageParams,
|
||||
TelegramDeleteMessageResponse,
|
||||
} from '@/tools/telegram/types'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const telegramDeleteMessageTool: ToolConfig<
|
||||
TelegramDeleteMessageParams,
|
||||
TelegramDeleteMessageResponse
|
||||
> = {
|
||||
id: 'telegram_delete_message',
|
||||
name: 'Telegram Delete Message',
|
||||
description:
|
||||
'Delete messages in Telegram channels or chats through the Telegram Bot API. Requires the message ID of the message to delete.',
|
||||
version: '1.0.0',
|
||||
errorExtractor: ErrorExtractorId.TELEGRAM_DESCRIPTION,
|
||||
|
||||
params: {
|
||||
botToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Telegram Bot API Token',
|
||||
},
|
||||
chatId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Telegram chat ID (numeric, can be negative for groups)',
|
||||
},
|
||||
messageId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Telegram message ID (numeric identifier of the message to delete)',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: TelegramDeleteMessageParams) =>
|
||||
`https://api.telegram.org/bot${params.botToken}/deleteMessage`,
|
||||
method: 'POST',
|
||||
headers: () => ({
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
body: (params: TelegramDeleteMessageParams) => ({
|
||||
chat_id: params.chatId,
|
||||
message_id: params.messageId,
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!data.ok) {
|
||||
const errorMessage = data.description || data.error || 'Failed to delete message'
|
||||
throw new Error(errorMessage)
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
message: 'Message deleted successfully',
|
||||
data: {
|
||||
ok: data.ok,
|
||||
deleted: data.result,
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
message: { type: 'string', description: 'Success or error message' },
|
||||
data: {
|
||||
type: 'object',
|
||||
description: 'Delete operation result',
|
||||
properties: {
|
||||
ok: { type: 'boolean', description: 'API response success status' },
|
||||
deleted: {
|
||||
type: 'boolean',
|
||||
description: 'Whether the message was successfully deleted',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
import { ErrorExtractorId } from '@/tools/error-extractors'
|
||||
import type {
|
||||
TelegramEditMessageTextParams,
|
||||
TelegramMessage,
|
||||
TelegramSendMessageResponse,
|
||||
} from '@/tools/telegram/types'
|
||||
import { convertMarkdownToHTML, telegramApiUrl } from '@/tools/telegram/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const telegramEditMessageTextTool: ToolConfig<
|
||||
TelegramEditMessageTextParams,
|
||||
TelegramSendMessageResponse
|
||||
> = {
|
||||
id: 'telegram_edit_message_text',
|
||||
name: 'Telegram Edit Message Text',
|
||||
description:
|
||||
'Edit the text of an existing message in a Telegram chat or channel through the Telegram Bot API.',
|
||||
version: '1.0.0',
|
||||
errorExtractor: ErrorExtractorId.TELEGRAM_DESCRIPTION,
|
||||
|
||||
params: {
|
||||
botToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Telegram Bot API Token',
|
||||
},
|
||||
chatId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Telegram chat ID (numeric, can be negative for groups)',
|
||||
},
|
||||
messageId: {
|
||||
type: 'number',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Identifier of the message to edit',
|
||||
},
|
||||
text: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'New text of the message',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params) => telegramApiUrl(params.botToken, 'editMessageText'),
|
||||
method: 'POST',
|
||||
headers: () => ({
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
body: (params) => ({
|
||||
chat_id: params.chatId,
|
||||
message_id: params.messageId,
|
||||
text: convertMarkdownToHTML(params.text),
|
||||
parse_mode: 'HTML',
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!data.ok) {
|
||||
const errorMessage = data.description || data.error || 'Failed to edit message'
|
||||
throw new Error(errorMessage)
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
message: 'Message edited successfully',
|
||||
data: data.result as TelegramMessage,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
message: { type: 'string', description: 'Success or error message' },
|
||||
data: {
|
||||
type: 'object',
|
||||
description: 'Edited Telegram message data',
|
||||
properties: {
|
||||
message_id: { type: 'number', description: 'Unique Telegram message identifier' },
|
||||
date: { type: 'number', description: 'Unix timestamp when message was sent' },
|
||||
text: { type: 'string', description: 'Text content of the edited message' },
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
import { ErrorExtractorId } from '@/tools/error-extractors'
|
||||
import type {
|
||||
TelegramForwardMessageParams,
|
||||
TelegramMessage,
|
||||
TelegramSendMessageResponse,
|
||||
} from '@/tools/telegram/types'
|
||||
import { telegramApiUrl } from '@/tools/telegram/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const telegramForwardMessageTool: ToolConfig<
|
||||
TelegramForwardMessageParams,
|
||||
TelegramSendMessageResponse
|
||||
> = {
|
||||
id: 'telegram_forward_message',
|
||||
name: 'Telegram Forward Message',
|
||||
description: 'Forward a message from one Telegram chat to another through the Telegram Bot API.',
|
||||
version: '1.0.0',
|
||||
errorExtractor: ErrorExtractorId.TELEGRAM_DESCRIPTION,
|
||||
|
||||
params: {
|
||||
botToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Telegram Bot API Token',
|
||||
},
|
||||
chatId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Destination chat ID (numeric, can be negative for groups)',
|
||||
},
|
||||
fromChatId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Source chat ID the original message belongs to',
|
||||
},
|
||||
messageId: {
|
||||
type: 'number',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Identifier of the message to forward in the source chat',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params) => telegramApiUrl(params.botToken, 'forwardMessage'),
|
||||
method: 'POST',
|
||||
headers: () => ({
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
body: (params) => ({
|
||||
chat_id: params.chatId,
|
||||
from_chat_id: params.fromChatId,
|
||||
message_id: params.messageId,
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!data.ok) {
|
||||
const errorMessage = data.description || data.error || 'Failed to forward message'
|
||||
throw new Error(errorMessage)
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
message: 'Message forwarded successfully',
|
||||
data: data.result as TelegramMessage,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
message: { type: 'string', description: 'Success or error message' },
|
||||
data: {
|
||||
type: 'object',
|
||||
description: 'Forwarded Telegram message data',
|
||||
properties: {
|
||||
message_id: { type: 'number', description: 'Identifier of the forwarded message' },
|
||||
date: { type: 'number', description: 'Unix timestamp when message was sent' },
|
||||
text: { type: 'string', description: 'Text content of the forwarded message' },
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
import { ErrorExtractorId } from '@/tools/error-extractors'
|
||||
import type {
|
||||
TelegramChatFullInfo,
|
||||
TelegramGetChatParams,
|
||||
TelegramGetChatResponse,
|
||||
} from '@/tools/telegram/types'
|
||||
import { telegramApiUrl } from '@/tools/telegram/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const telegramGetChatTool: ToolConfig<TelegramGetChatParams, TelegramGetChatResponse> = {
|
||||
id: 'telegram_get_chat',
|
||||
name: 'Telegram Get Chat',
|
||||
description: 'Get up-to-date information about a Telegram chat through the Telegram Bot API.',
|
||||
version: '1.0.0',
|
||||
errorExtractor: ErrorExtractorId.TELEGRAM_DESCRIPTION,
|
||||
|
||||
params: {
|
||||
botToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Telegram Bot API Token',
|
||||
},
|
||||
chatId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Telegram chat ID or @username (numeric, can be negative for groups)',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params) => telegramApiUrl(params.botToken, 'getChat'),
|
||||
method: 'POST',
|
||||
headers: () => ({
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
body: (params) => ({
|
||||
chat_id: params.chatId,
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!data.ok) {
|
||||
const errorMessage = data.description || data.error || 'Failed to get chat'
|
||||
throw new Error(errorMessage)
|
||||
}
|
||||
|
||||
const result = data.result
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
message: 'Chat info retrieved successfully',
|
||||
data: {
|
||||
id: result.id,
|
||||
type: result.type,
|
||||
title: result.title ?? null,
|
||||
username: result.username ?? null,
|
||||
first_name: result.first_name ?? null,
|
||||
last_name: result.last_name ?? null,
|
||||
description: result.description ?? null,
|
||||
bio: result.bio ?? null,
|
||||
invite_link: result.invite_link ?? null,
|
||||
linked_chat_id: result.linked_chat_id ?? null,
|
||||
} as TelegramChatFullInfo,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
message: { type: 'string', description: 'Success or error message' },
|
||||
data: {
|
||||
type: 'object',
|
||||
description: 'Telegram chat information',
|
||||
properties: {
|
||||
id: { type: 'number', description: 'Unique chat identifier' },
|
||||
type: { type: 'string', description: 'Chat type (private, group, supergroup, channel)' },
|
||||
title: { type: 'string', description: 'Chat title for groups and channels' },
|
||||
username: { type: 'string', description: 'Chat username, if available' },
|
||||
first_name: { type: 'string', description: 'First name for private chats' },
|
||||
last_name: { type: 'string', description: 'Last name for private chats' },
|
||||
description: { type: 'string', description: 'Chat description' },
|
||||
bio: { type: 'string', description: 'Bio of the other party in a private chat' },
|
||||
invite_link: { type: 'string', description: 'Primary invite link for the chat' },
|
||||
linked_chat_id: { type: 'number', description: 'Linked discussion or channel chat ID' },
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
import { ErrorExtractorId } from '@/tools/error-extractors'
|
||||
import type {
|
||||
TelegramChatMember,
|
||||
TelegramGetChatMemberParams,
|
||||
TelegramGetChatMemberResponse,
|
||||
} from '@/tools/telegram/types'
|
||||
import { telegramApiUrl } from '@/tools/telegram/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const telegramGetChatMemberTool: ToolConfig<
|
||||
TelegramGetChatMemberParams,
|
||||
TelegramGetChatMemberResponse
|
||||
> = {
|
||||
id: 'telegram_get_chat_member',
|
||||
name: 'Telegram Get Chat Member',
|
||||
description: 'Get information about a member of a Telegram chat through the Telegram Bot API.',
|
||||
version: '1.0.0',
|
||||
errorExtractor: ErrorExtractorId.TELEGRAM_DESCRIPTION,
|
||||
|
||||
params: {
|
||||
botToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Telegram Bot API Token',
|
||||
},
|
||||
chatId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Telegram chat ID or @username (numeric, can be negative for groups)',
|
||||
},
|
||||
userId: {
|
||||
type: 'number',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Unique identifier of the target user',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params) => telegramApiUrl(params.botToken, 'getChatMember'),
|
||||
method: 'POST',
|
||||
headers: () => ({
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
body: (params) => ({
|
||||
chat_id: params.chatId,
|
||||
user_id: params.userId,
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!data.ok) {
|
||||
const errorMessage = data.description || data.error || 'Failed to get chat member'
|
||||
throw new Error(errorMessage)
|
||||
}
|
||||
|
||||
const result = data.result
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
message: 'Chat member retrieved successfully',
|
||||
data: {
|
||||
status: result.status,
|
||||
user: result.user,
|
||||
} as TelegramChatMember,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
message: { type: 'string', description: 'Success or error message' },
|
||||
data: {
|
||||
type: 'object',
|
||||
description: 'Telegram chat member information',
|
||||
properties: {
|
||||
status: {
|
||||
type: 'string',
|
||||
description: "Member's status (creator, administrator, member, restricted, left, kicked)",
|
||||
},
|
||||
user: {
|
||||
type: 'object',
|
||||
description: 'Information about the user',
|
||||
properties: {
|
||||
id: { type: 'number', description: 'Unique user identifier' },
|
||||
is_bot: { type: 'boolean', description: 'Whether the user is a bot' },
|
||||
first_name: { type: 'string', description: "User's first name" },
|
||||
last_name: { type: 'string', description: "User's last name" },
|
||||
username: { type: 'string', description: "User's username" },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { telegramCopyMessageTool } from '@/tools/telegram/copy_message'
|
||||
import { telegramDeleteMessageTool } from '@/tools/telegram/delete_message'
|
||||
import { telegramEditMessageTextTool } from '@/tools/telegram/edit_message_text'
|
||||
import { telegramForwardMessageTool } from '@/tools/telegram/forward_message'
|
||||
import { telegramGetChatTool } from '@/tools/telegram/get_chat'
|
||||
import { telegramGetChatMemberTool } from '@/tools/telegram/get_chat_member'
|
||||
import { telegramMessageTool } from '@/tools/telegram/message'
|
||||
import { telegramPinMessageTool } from '@/tools/telegram/pin_message'
|
||||
import { telegramSendAnimationTool } from '@/tools/telegram/send_animation'
|
||||
import { telegramSendAudioTool } from '@/tools/telegram/send_audio'
|
||||
import { telegramSendChatActionTool } from '@/tools/telegram/send_chat_action'
|
||||
import { telegramSendContactTool } from '@/tools/telegram/send_contact'
|
||||
import { telegramSendDocumentTool } from '@/tools/telegram/send_document'
|
||||
import { telegramSendLocationTool } from '@/tools/telegram/send_location'
|
||||
import { telegramSendPhotoTool } from '@/tools/telegram/send_photo'
|
||||
import { telegramSendPollTool } from '@/tools/telegram/send_poll'
|
||||
import { telegramSendVideoTool } from '@/tools/telegram/send_video'
|
||||
import { telegramSetMessageReactionTool } from '@/tools/telegram/set_message_reaction'
|
||||
import { telegramUnpinMessageTool } from '@/tools/telegram/unpin_message'
|
||||
|
||||
export {
|
||||
telegramCopyMessageTool,
|
||||
telegramDeleteMessageTool,
|
||||
telegramEditMessageTextTool,
|
||||
telegramForwardMessageTool,
|
||||
telegramGetChatTool,
|
||||
telegramGetChatMemberTool,
|
||||
telegramMessageTool,
|
||||
telegramPinMessageTool,
|
||||
telegramSendAnimationTool,
|
||||
telegramSendAudioTool,
|
||||
telegramSendChatActionTool,
|
||||
telegramSendContactTool,
|
||||
telegramSendDocumentTool,
|
||||
telegramSendLocationTool,
|
||||
telegramSendPhotoTool,
|
||||
telegramSendPollTool,
|
||||
telegramSendVideoTool,
|
||||
telegramSetMessageReactionTool,
|
||||
telegramUnpinMessageTool,
|
||||
}
|
||||
|
||||
export * from './types'
|
||||
@@ -0,0 +1,128 @@
|
||||
import { ErrorExtractorId } from '@/tools/error-extractors'
|
||||
import type {
|
||||
TelegramMessage,
|
||||
TelegramSendMessageParams,
|
||||
TelegramSendMessageResponse,
|
||||
} from '@/tools/telegram/types'
|
||||
import { convertMarkdownToHTML } from '@/tools/telegram/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const telegramMessageTool: ToolConfig<
|
||||
TelegramSendMessageParams,
|
||||
TelegramSendMessageResponse
|
||||
> = {
|
||||
id: 'telegram_message',
|
||||
name: 'Telegram Send Message',
|
||||
description:
|
||||
'Send messages to Telegram channels or users through the Telegram Bot API. Enables direct communication and notifications with message tracking and chat confirmation.',
|
||||
version: '1.0.0',
|
||||
errorExtractor: ErrorExtractorId.TELEGRAM_DESCRIPTION,
|
||||
|
||||
params: {
|
||||
botToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Telegram Bot API Token',
|
||||
},
|
||||
chatId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Telegram chat ID (numeric, can be negative for groups)',
|
||||
},
|
||||
text: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Message text to send',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: TelegramSendMessageParams) =>
|
||||
`https://api.telegram.org/bot${params.botToken}/sendMessage`,
|
||||
method: 'POST',
|
||||
headers: () => ({
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
body: (params: TelegramSendMessageParams) => ({
|
||||
chat_id: params.chatId,
|
||||
text: convertMarkdownToHTML(params.text),
|
||||
parse_mode: 'HTML',
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!data.ok) {
|
||||
const errorMessage = data.description || data.error || 'Failed to send message'
|
||||
throw new Error(errorMessage)
|
||||
}
|
||||
|
||||
const result = data.result as TelegramMessage
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
message: 'Message sent successfully',
|
||||
data: result,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
message: { type: 'string', description: 'Success or error message' },
|
||||
data: {
|
||||
type: 'object',
|
||||
description: 'Telegram message data',
|
||||
properties: {
|
||||
message_id: {
|
||||
type: 'number',
|
||||
description: 'Unique Telegram message identifier',
|
||||
},
|
||||
from: {
|
||||
type: 'object',
|
||||
description: 'Chat information',
|
||||
properties: {
|
||||
id: { type: 'number', description: 'Chat ID' },
|
||||
is_bot: {
|
||||
type: 'boolean',
|
||||
description: 'Whether the chat is a bot or not',
|
||||
},
|
||||
first_name: {
|
||||
type: 'string',
|
||||
description: 'Chat username (if available)',
|
||||
},
|
||||
username: {
|
||||
type: 'string',
|
||||
description: 'Chat title (for groups and channels)',
|
||||
},
|
||||
},
|
||||
},
|
||||
chat: {
|
||||
type: 'object',
|
||||
description: 'Information about the bot that sent the message',
|
||||
properties: {
|
||||
id: { type: 'number', description: 'Bot user ID' },
|
||||
first_name: { type: 'string', description: 'Bot first name' },
|
||||
username: { type: 'string', description: 'Bot username' },
|
||||
type: {
|
||||
type: 'string',
|
||||
description: 'chat type private or channel',
|
||||
},
|
||||
},
|
||||
},
|
||||
date: {
|
||||
type: 'number',
|
||||
description: 'Unix timestamp when message was sent',
|
||||
},
|
||||
text: {
|
||||
type: 'string',
|
||||
description: 'Text content of the sent message',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
import { ErrorExtractorId } from '@/tools/error-extractors'
|
||||
import type { TelegramBooleanResponse, TelegramPinMessageParams } from '@/tools/telegram/types'
|
||||
import { telegramApiUrl } from '@/tools/telegram/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const telegramPinMessageTool: ToolConfig<TelegramPinMessageParams, TelegramBooleanResponse> =
|
||||
{
|
||||
id: 'telegram_pin_message',
|
||||
name: 'Telegram Pin Message',
|
||||
description: 'Pin a message in a Telegram chat through the Telegram Bot API.',
|
||||
version: '1.0.0',
|
||||
errorExtractor: ErrorExtractorId.TELEGRAM_DESCRIPTION,
|
||||
|
||||
params: {
|
||||
botToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Telegram Bot API Token',
|
||||
},
|
||||
chatId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Telegram chat ID (numeric, can be negative for groups)',
|
||||
},
|
||||
messageId: {
|
||||
type: 'number',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Identifier of the message to pin',
|
||||
},
|
||||
disableNotification: {
|
||||
type: 'boolean',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Pass true to pin silently without notifying chat members',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params) => telegramApiUrl(params.botToken, 'pinChatMessage'),
|
||||
method: 'POST',
|
||||
headers: () => ({
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
body: (params) => {
|
||||
const body: Record<string, unknown> = {
|
||||
chat_id: params.chatId,
|
||||
message_id: params.messageId,
|
||||
}
|
||||
if (params.disableNotification !== undefined) {
|
||||
body.disable_notification = params.disableNotification
|
||||
}
|
||||
return body
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!data.ok) {
|
||||
const errorMessage = data.description || data.error || 'Failed to pin message'
|
||||
throw new Error(errorMessage)
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
message: 'Message pinned successfully',
|
||||
data: {
|
||||
ok: data.ok,
|
||||
result: data.result,
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
message: { type: 'string', description: 'Success or error message' },
|
||||
data: {
|
||||
type: 'object',
|
||||
description: 'Pin operation result',
|
||||
properties: {
|
||||
ok: { type: 'boolean', description: 'API response success status' },
|
||||
result: { type: 'boolean', description: 'Whether the message was pinned' },
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,279 @@
|
||||
import { ErrorExtractorId } from '@/tools/error-extractors'
|
||||
import type {
|
||||
TelegramMedia,
|
||||
TelegramSendAnimationParams,
|
||||
TelegramSendMediaResponse,
|
||||
} from '@/tools/telegram/types'
|
||||
import { convertMarkdownToHTML } from '@/tools/telegram/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const telegramSendAnimationTool: ToolConfig<
|
||||
TelegramSendAnimationParams,
|
||||
TelegramSendMediaResponse
|
||||
> = {
|
||||
id: 'telegram_send_animation',
|
||||
name: 'Telegram Send Animation',
|
||||
description: 'Send animations (GIFs) to Telegram channels or users through the Telegram Bot API.',
|
||||
version: '1.0.0',
|
||||
errorExtractor: ErrorExtractorId.TELEGRAM_DESCRIPTION,
|
||||
|
||||
params: {
|
||||
botToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Telegram Bot API Token',
|
||||
},
|
||||
chatId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Telegram chat ID (numeric, can be negative for groups)',
|
||||
},
|
||||
animation: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Animation to send. Pass a file_id or HTTP URL',
|
||||
},
|
||||
caption: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Animation caption (optional)',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: TelegramSendAnimationParams) =>
|
||||
`https://api.telegram.org/bot${params.botToken}/sendAnimation`,
|
||||
method: 'POST',
|
||||
headers: () => ({
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
body: (params: TelegramSendAnimationParams) => {
|
||||
const body: Record<string, any> = {
|
||||
chat_id: params.chatId,
|
||||
animation: params.animation,
|
||||
}
|
||||
|
||||
if (params.caption) {
|
||||
body.caption = convertMarkdownToHTML(params.caption)
|
||||
body.parse_mode = 'HTML'
|
||||
}
|
||||
|
||||
return body
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!data.ok) {
|
||||
const errorMessage = data.description || data.error || 'Failed to send animation'
|
||||
throw new Error(errorMessage)
|
||||
}
|
||||
|
||||
const result = data.result as TelegramMedia
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
message: 'Animation sent successfully',
|
||||
data: result,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
message: { type: 'string', description: 'Success or error message' },
|
||||
data: {
|
||||
type: 'object',
|
||||
description: 'Telegram message data including optional media',
|
||||
properties: {
|
||||
message_id: {
|
||||
type: 'number',
|
||||
description: 'Unique Telegram message identifier',
|
||||
},
|
||||
from: {
|
||||
type: 'object',
|
||||
description: 'Information about the sender',
|
||||
properties: {
|
||||
id: { type: 'number', description: 'Sender ID' },
|
||||
is_bot: {
|
||||
type: 'boolean',
|
||||
description: 'Whether the chat is a bot or not',
|
||||
},
|
||||
first_name: {
|
||||
type: 'string',
|
||||
description: "Sender's first name (if available)",
|
||||
},
|
||||
username: {
|
||||
type: 'string',
|
||||
description: "Sender's username (if available)",
|
||||
},
|
||||
},
|
||||
},
|
||||
chat: {
|
||||
type: 'object',
|
||||
description: 'Information about the chat where message was sent',
|
||||
properties: {
|
||||
id: { type: 'number', description: 'Chat ID' },
|
||||
first_name: {
|
||||
type: 'string',
|
||||
description: 'Chat first name (if private chat)',
|
||||
},
|
||||
username: {
|
||||
type: 'string',
|
||||
description: 'Chat username (for private or channels)',
|
||||
},
|
||||
type: {
|
||||
type: 'string',
|
||||
description: 'Type of chat (private, group, supergroup, or channel)',
|
||||
},
|
||||
},
|
||||
},
|
||||
date: {
|
||||
type: 'number',
|
||||
description: 'Unix timestamp when the message was sent',
|
||||
},
|
||||
text: {
|
||||
type: 'string',
|
||||
description: 'Text content of the sent message (if applicable)',
|
||||
},
|
||||
format: {
|
||||
type: 'object',
|
||||
description: 'Media format information (for videos, GIFs, etc.)',
|
||||
properties: {
|
||||
file_name: { type: 'string', description: 'Media file name' },
|
||||
mime_type: { type: 'string', description: 'Media MIME type' },
|
||||
duration: {
|
||||
type: 'number',
|
||||
description: 'Duration of media in seconds',
|
||||
},
|
||||
width: { type: 'number', description: 'Media width in pixels' },
|
||||
height: { type: 'number', description: 'Media height in pixels' },
|
||||
thumbnail: {
|
||||
type: 'object',
|
||||
description: 'Thumbnail image details',
|
||||
properties: {
|
||||
file_id: { type: 'string', description: 'Thumbnail file ID' },
|
||||
file_unique_id: {
|
||||
type: 'string',
|
||||
description: 'Unique thumbnail file identifier',
|
||||
},
|
||||
file_size: {
|
||||
type: 'number',
|
||||
description: 'Thumbnail file size in bytes',
|
||||
},
|
||||
width: {
|
||||
type: 'number',
|
||||
description: 'Thumbnail width in pixels',
|
||||
},
|
||||
height: {
|
||||
type: 'number',
|
||||
description: 'Thumbnail height in pixels',
|
||||
},
|
||||
},
|
||||
},
|
||||
thumb: {
|
||||
type: 'object',
|
||||
description: 'Secondary thumbnail details (duplicate of thumbnail)',
|
||||
properties: {
|
||||
file_id: { type: 'string', description: 'Thumbnail file ID' },
|
||||
file_unique_id: {
|
||||
type: 'string',
|
||||
description: 'Unique thumbnail file identifier',
|
||||
},
|
||||
file_size: {
|
||||
type: 'number',
|
||||
description: 'Thumbnail file size in bytes',
|
||||
},
|
||||
width: {
|
||||
type: 'number',
|
||||
description: 'Thumbnail width in pixels',
|
||||
},
|
||||
height: {
|
||||
type: 'number',
|
||||
description: 'Thumbnail height in pixels',
|
||||
},
|
||||
},
|
||||
},
|
||||
file_id: { type: 'string', description: 'Media file ID' },
|
||||
file_unique_id: {
|
||||
type: 'string',
|
||||
description: 'Unique media file identifier',
|
||||
},
|
||||
file_size: {
|
||||
type: 'number',
|
||||
description: 'Size of media file in bytes',
|
||||
},
|
||||
},
|
||||
},
|
||||
document: {
|
||||
type: 'object',
|
||||
description: 'Document file details if the message contains a document',
|
||||
properties: {
|
||||
file_name: { type: 'string', description: 'Document file name' },
|
||||
mime_type: { type: 'string', description: 'Document MIME type' },
|
||||
thumbnail: {
|
||||
type: 'object',
|
||||
description: 'Document thumbnail information',
|
||||
properties: {
|
||||
file_id: { type: 'string', description: 'Thumbnail file ID' },
|
||||
file_unique_id: {
|
||||
type: 'string',
|
||||
description: 'Unique thumbnail file identifier',
|
||||
},
|
||||
file_size: {
|
||||
type: 'number',
|
||||
description: 'Thumbnail file size in bytes',
|
||||
},
|
||||
width: {
|
||||
type: 'number',
|
||||
description: 'Thumbnail width in pixels',
|
||||
},
|
||||
height: {
|
||||
type: 'number',
|
||||
description: 'Thumbnail height in pixels',
|
||||
},
|
||||
},
|
||||
},
|
||||
thumb: {
|
||||
type: 'object',
|
||||
description: 'Duplicate thumbnail info (used for compatibility)',
|
||||
properties: {
|
||||
file_id: { type: 'string', description: 'Thumbnail file ID' },
|
||||
file_unique_id: {
|
||||
type: 'string',
|
||||
description: 'Unique thumbnail file identifier',
|
||||
},
|
||||
file_size: {
|
||||
type: 'number',
|
||||
description: 'Thumbnail file size in bytes',
|
||||
},
|
||||
width: {
|
||||
type: 'number',
|
||||
description: 'Thumbnail width in pixels',
|
||||
},
|
||||
height: {
|
||||
type: 'number',
|
||||
description: 'Thumbnail height in pixels',
|
||||
},
|
||||
},
|
||||
},
|
||||
file_id: { type: 'string', description: 'Document file ID' },
|
||||
file_unique_id: {
|
||||
type: 'string',
|
||||
description: 'Unique document file identifier',
|
||||
},
|
||||
file_size: {
|
||||
type: 'number',
|
||||
description: 'Size of document file in bytes',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
import { ErrorExtractorId } from '@/tools/error-extractors'
|
||||
import type {
|
||||
TelegramAudio,
|
||||
TelegramSendAudioParams,
|
||||
TelegramSendAudioResponse,
|
||||
} from '@/tools/telegram/types'
|
||||
import { convertMarkdownToHTML } from '@/tools/telegram/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const telegramSendAudioTool: ToolConfig<TelegramSendAudioParams, TelegramSendAudioResponse> =
|
||||
{
|
||||
id: 'telegram_send_audio',
|
||||
name: 'Telegram Send Audio',
|
||||
description: 'Send audio files to Telegram channels or users through the Telegram Bot API.',
|
||||
version: '1.0.0',
|
||||
errorExtractor: ErrorExtractorId.TELEGRAM_DESCRIPTION,
|
||||
|
||||
params: {
|
||||
botToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Telegram Bot API Token',
|
||||
},
|
||||
chatId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Telegram chat ID (numeric, can be negative for groups)',
|
||||
},
|
||||
audio: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Audio file to send. Pass a file_id or HTTP URL',
|
||||
},
|
||||
caption: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Audio caption (optional)',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: TelegramSendAudioParams) =>
|
||||
`https://api.telegram.org/bot${params.botToken}/sendAudio`,
|
||||
method: 'POST',
|
||||
headers: () => ({
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
body: (params: TelegramSendAudioParams) => {
|
||||
const body: Record<string, any> = {
|
||||
chat_id: params.chatId,
|
||||
audio: params.audio,
|
||||
}
|
||||
|
||||
if (params.caption) {
|
||||
body.caption = convertMarkdownToHTML(params.caption)
|
||||
body.parse_mode = 'HTML'
|
||||
}
|
||||
|
||||
return body
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!data.ok) {
|
||||
const errorMessage = data.description || data.error || 'Failed to send audio'
|
||||
throw new Error(errorMessage)
|
||||
}
|
||||
|
||||
const result = data.result as TelegramAudio
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
message: 'Audio sent successfully',
|
||||
data: result,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
message: { type: 'string', description: 'Success or error message' },
|
||||
data: {
|
||||
type: 'object',
|
||||
description: 'Telegram message data including voice/audio information',
|
||||
properties: {
|
||||
message_id: {
|
||||
type: 'number',
|
||||
description: 'Unique Telegram message identifier',
|
||||
},
|
||||
from: {
|
||||
type: 'object',
|
||||
description: 'Information about the sender',
|
||||
properties: {
|
||||
id: { type: 'number', description: 'Sender ID' },
|
||||
is_bot: {
|
||||
type: 'boolean',
|
||||
description: 'Whether the chat is a bot or not',
|
||||
},
|
||||
first_name: {
|
||||
type: 'string',
|
||||
description: "Sender's first name (if available)",
|
||||
},
|
||||
username: {
|
||||
type: 'string',
|
||||
description: "Sender's username (if available)",
|
||||
},
|
||||
},
|
||||
},
|
||||
chat: {
|
||||
type: 'object',
|
||||
description: 'Information about the chat where the message was sent',
|
||||
properties: {
|
||||
id: { type: 'number', description: 'Chat ID' },
|
||||
first_name: {
|
||||
type: 'string',
|
||||
description: 'Chat first name (if private chat)',
|
||||
},
|
||||
username: {
|
||||
type: 'string',
|
||||
description: 'Chat username (for private or channels)',
|
||||
},
|
||||
type: {
|
||||
type: 'string',
|
||||
description: 'Type of chat (private, group, supergroup, or channel)',
|
||||
},
|
||||
},
|
||||
},
|
||||
date: {
|
||||
type: 'number',
|
||||
description: 'Unix timestamp when the message was sent',
|
||||
},
|
||||
text: {
|
||||
type: 'string',
|
||||
description: 'Text content of the sent message (if applicable)',
|
||||
},
|
||||
audio: {
|
||||
type: 'object',
|
||||
description: 'Audio file details',
|
||||
properties: {
|
||||
duration: {
|
||||
type: 'number',
|
||||
description: 'Duration of the audio in seconds',
|
||||
},
|
||||
performer: {
|
||||
type: 'string',
|
||||
description: 'Performer of the audio',
|
||||
},
|
||||
title: {
|
||||
type: 'string',
|
||||
description: 'Title of the audio',
|
||||
},
|
||||
file_name: {
|
||||
type: 'string',
|
||||
description: 'Original filename of the audio',
|
||||
},
|
||||
mime_type: {
|
||||
type: 'string',
|
||||
description: 'MIME type of the audio file',
|
||||
},
|
||||
file_id: {
|
||||
type: 'string',
|
||||
description: 'Unique file identifier for this audio',
|
||||
},
|
||||
file_unique_id: {
|
||||
type: 'string',
|
||||
description: 'Unique identifier across different bots for this file',
|
||||
},
|
||||
file_size: {
|
||||
type: 'number',
|
||||
description: 'Size of the audio file in bytes',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import { ErrorExtractorId } from '@/tools/error-extractors'
|
||||
import type { TelegramBooleanResponse, TelegramSendChatActionParams } from '@/tools/telegram/types'
|
||||
import { telegramApiUrl } from '@/tools/telegram/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const telegramSendChatActionTool: ToolConfig<
|
||||
TelegramSendChatActionParams,
|
||||
TelegramBooleanResponse
|
||||
> = {
|
||||
id: 'telegram_send_chat_action',
|
||||
name: 'Telegram Send Chat Action',
|
||||
description:
|
||||
'Show a status action such as a typing indicator in a Telegram chat through the Telegram Bot API.',
|
||||
version: '1.0.0',
|
||||
errorExtractor: ErrorExtractorId.TELEGRAM_DESCRIPTION,
|
||||
|
||||
params: {
|
||||
botToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Telegram Bot API Token',
|
||||
},
|
||||
chatId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Telegram chat ID (numeric, can be negative for groups)',
|
||||
},
|
||||
action: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description:
|
||||
'Type of action to broadcast (e.g. typing, upload_photo, record_video, upload_document, find_location)',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params) => telegramApiUrl(params.botToken, 'sendChatAction'),
|
||||
method: 'POST',
|
||||
headers: () => ({
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
body: (params) => ({
|
||||
chat_id: params.chatId,
|
||||
action: params.action,
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!data.ok) {
|
||||
const errorMessage = data.description || data.error || 'Failed to send chat action'
|
||||
throw new Error(errorMessage)
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
message: 'Chat action sent successfully',
|
||||
data: {
|
||||
ok: data.ok,
|
||||
result: data.result,
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
message: { type: 'string', description: 'Success or error message' },
|
||||
data: {
|
||||
type: 'object',
|
||||
description: 'Chat action result',
|
||||
properties: {
|
||||
ok: { type: 'boolean', description: 'API response success status' },
|
||||
result: { type: 'boolean', description: 'Whether the action was broadcast' },
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
import { ErrorExtractorId } from '@/tools/error-extractors'
|
||||
import type {
|
||||
TelegramMessage,
|
||||
TelegramSendContactParams,
|
||||
TelegramSendMessageResponse,
|
||||
} from '@/tools/telegram/types'
|
||||
import { telegramApiUrl } from '@/tools/telegram/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const telegramSendContactTool: ToolConfig<
|
||||
TelegramSendContactParams,
|
||||
TelegramSendMessageResponse
|
||||
> = {
|
||||
id: 'telegram_send_contact',
|
||||
name: 'Telegram Send Contact',
|
||||
description: 'Send a phone contact to a Telegram chat through the Telegram Bot API.',
|
||||
version: '1.0.0',
|
||||
errorExtractor: ErrorExtractorId.TELEGRAM_DESCRIPTION,
|
||||
|
||||
params: {
|
||||
botToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Telegram Bot API Token',
|
||||
},
|
||||
chatId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Telegram chat ID (numeric, can be negative for groups)',
|
||||
},
|
||||
phoneNumber: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: "Contact's phone number",
|
||||
},
|
||||
firstName: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: "Contact's first name",
|
||||
},
|
||||
lastName: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: "Contact's last name",
|
||||
},
|
||||
vcard: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Additional data about the contact in the form of a vCard',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params) => telegramApiUrl(params.botToken, 'sendContact'),
|
||||
method: 'POST',
|
||||
headers: () => ({
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
body: (params) => {
|
||||
const body: Record<string, unknown> = {
|
||||
chat_id: params.chatId,
|
||||
phone_number: params.phoneNumber,
|
||||
first_name: params.firstName,
|
||||
}
|
||||
if (params.lastName) body.last_name = params.lastName
|
||||
if (params.vcard) body.vcard = params.vcard
|
||||
return body
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!data.ok) {
|
||||
const errorMessage = data.description || data.error || 'Failed to send contact'
|
||||
throw new Error(errorMessage)
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
message: 'Contact sent successfully',
|
||||
data: data.result as TelegramMessage,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
message: { type: 'string', description: 'Success or error message' },
|
||||
data: {
|
||||
type: 'object',
|
||||
description: 'Telegram message data for the sent contact',
|
||||
properties: {
|
||||
message_id: { type: 'number', description: 'Unique Telegram message identifier' },
|
||||
date: { type: 'number', description: 'Unix timestamp when message was sent' },
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
import type {
|
||||
TelegramSendDocumentParams,
|
||||
TelegramSendDocumentResponse,
|
||||
} from '@/tools/telegram/types'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const telegramSendDocumentTool: ToolConfig<
|
||||
TelegramSendDocumentParams,
|
||||
TelegramSendDocumentResponse
|
||||
> = {
|
||||
id: 'telegram_send_document',
|
||||
name: 'Telegram Send Document',
|
||||
description:
|
||||
'Send documents (PDF, ZIP, DOC, etc.) to Telegram channels or users through the Telegram Bot API.',
|
||||
version: '1.0.0',
|
||||
|
||||
params: {
|
||||
botToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Telegram Bot API Token',
|
||||
},
|
||||
chatId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Telegram chat ID (numeric, can be negative for groups)',
|
||||
},
|
||||
files: {
|
||||
type: 'file[]',
|
||||
required: false,
|
||||
visibility: 'user-only',
|
||||
description: 'Document file to send (PDF, ZIP, DOC, etc.). Max size: 50MB',
|
||||
},
|
||||
caption: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Document caption (optional)',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: '/api/tools/telegram/send-document',
|
||||
method: 'POST',
|
||||
headers: () => ({
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
body: (params: TelegramSendDocumentParams) => {
|
||||
let normalizedFiles: unknown[] | null = null
|
||||
if (params.files) {
|
||||
normalizedFiles = Array.isArray(params.files) ? params.files : [params.files]
|
||||
}
|
||||
|
||||
return {
|
||||
botToken: params.botToken,
|
||||
chatId: params.chatId,
|
||||
files: normalizedFiles,
|
||||
caption: params.caption,
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
if (!data.success) {
|
||||
throw new Error(data.error || 'Failed to send Telegram document')
|
||||
}
|
||||
return {
|
||||
success: true,
|
||||
output: data.output,
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
message: { type: 'string', description: 'Success or error message' },
|
||||
files: { type: 'file[]', description: 'Files attached to the message' },
|
||||
data: {
|
||||
type: 'object',
|
||||
description: 'Telegram message data including document',
|
||||
properties: {
|
||||
message_id: {
|
||||
type: 'number',
|
||||
description: 'Unique Telegram message identifier',
|
||||
},
|
||||
from: {
|
||||
type: 'object',
|
||||
description: 'Information about the sender',
|
||||
properties: {
|
||||
id: { type: 'number', description: 'Sender ID' },
|
||||
is_bot: {
|
||||
type: 'boolean',
|
||||
description: 'Whether the chat is a bot or not',
|
||||
},
|
||||
first_name: {
|
||||
type: 'string',
|
||||
description: "Sender's first name (if available)",
|
||||
},
|
||||
username: {
|
||||
type: 'string',
|
||||
description: "Sender's username (if available)",
|
||||
},
|
||||
},
|
||||
},
|
||||
chat: {
|
||||
type: 'object',
|
||||
description: 'Information about the chat where message was sent',
|
||||
properties: {
|
||||
id: { type: 'number', description: 'Chat ID' },
|
||||
first_name: {
|
||||
type: 'string',
|
||||
description: 'Chat first name (if private chat)',
|
||||
},
|
||||
username: {
|
||||
type: 'string',
|
||||
description: 'Chat username (for private or channels)',
|
||||
},
|
||||
type: {
|
||||
type: 'string',
|
||||
description: 'Type of chat (private, group, supergroup, or channel)',
|
||||
},
|
||||
},
|
||||
},
|
||||
date: {
|
||||
type: 'number',
|
||||
description: 'Unix timestamp when the message was sent',
|
||||
},
|
||||
document: {
|
||||
type: 'object',
|
||||
description: 'Document file details',
|
||||
properties: {
|
||||
file_name: { type: 'string', description: 'Document file name' },
|
||||
mime_type: { type: 'string', description: 'Document MIME type' },
|
||||
file_id: { type: 'string', description: 'Document file ID' },
|
||||
file_unique_id: {
|
||||
type: 'string',
|
||||
description: 'Unique document file identifier',
|
||||
},
|
||||
file_size: {
|
||||
type: 'number',
|
||||
description: 'Size of document file in bytes',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
import { ErrorExtractorId } from '@/tools/error-extractors'
|
||||
import type {
|
||||
TelegramMessage,
|
||||
TelegramSendLocationParams,
|
||||
TelegramSendMessageResponse,
|
||||
} from '@/tools/telegram/types'
|
||||
import { telegramApiUrl } from '@/tools/telegram/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const telegramSendLocationTool: ToolConfig<
|
||||
TelegramSendLocationParams,
|
||||
TelegramSendMessageResponse
|
||||
> = {
|
||||
id: 'telegram_send_location',
|
||||
name: 'Telegram Send Location',
|
||||
description: 'Send a point on the map to a Telegram chat through the Telegram Bot API.',
|
||||
version: '1.0.0',
|
||||
errorExtractor: ErrorExtractorId.TELEGRAM_DESCRIPTION,
|
||||
|
||||
params: {
|
||||
botToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Telegram Bot API Token',
|
||||
},
|
||||
chatId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Telegram chat ID (numeric, can be negative for groups)',
|
||||
},
|
||||
latitude: {
|
||||
type: 'number',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Latitude of the location',
|
||||
},
|
||||
longitude: {
|
||||
type: 'number',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Longitude of the location',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params) => telegramApiUrl(params.botToken, 'sendLocation'),
|
||||
method: 'POST',
|
||||
headers: () => ({
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
body: (params) => ({
|
||||
chat_id: params.chatId,
|
||||
latitude: params.latitude,
|
||||
longitude: params.longitude,
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!data.ok) {
|
||||
const errorMessage = data.description || data.error || 'Failed to send location'
|
||||
throw new Error(errorMessage)
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
message: 'Location sent successfully',
|
||||
data: data.result as TelegramMessage,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
message: { type: 'string', description: 'Success or error message' },
|
||||
data: {
|
||||
type: 'object',
|
||||
description: 'Telegram message data for the sent location',
|
||||
properties: {
|
||||
message_id: { type: 'number', description: 'Unique Telegram message identifier' },
|
||||
date: { type: 'number', description: 'Unix timestamp when message was sent' },
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
import { ErrorExtractorId } from '@/tools/error-extractors'
|
||||
import type {
|
||||
TelegramPhoto,
|
||||
TelegramSendPhotoParams,
|
||||
TelegramSendPhotoResponse,
|
||||
} from '@/tools/telegram/types'
|
||||
import { convertMarkdownToHTML } from '@/tools/telegram/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const telegramSendPhotoTool: ToolConfig<TelegramSendPhotoParams, TelegramSendPhotoResponse> =
|
||||
{
|
||||
id: 'telegram_send_photo',
|
||||
name: 'Telegram Send Photo',
|
||||
description: 'Send photos to Telegram channels or users through the Telegram Bot API.',
|
||||
version: '1.0.0',
|
||||
errorExtractor: ErrorExtractorId.TELEGRAM_DESCRIPTION,
|
||||
|
||||
params: {
|
||||
botToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Telegram Bot API Token',
|
||||
},
|
||||
chatId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Telegram chat ID (numeric, can be negative for groups)',
|
||||
},
|
||||
photo: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Photo to send. Pass a file_id or HTTP URL',
|
||||
},
|
||||
caption: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Photo caption (optional)',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: TelegramSendPhotoParams) =>
|
||||
`https://api.telegram.org/bot${params.botToken}/sendPhoto`,
|
||||
method: 'POST',
|
||||
headers: () => ({
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
body: (params: TelegramSendPhotoParams) => {
|
||||
const body: Record<string, any> = {
|
||||
chat_id: params.chatId,
|
||||
photo: params.photo,
|
||||
}
|
||||
|
||||
if (params.caption) {
|
||||
body.caption = convertMarkdownToHTML(params.caption)
|
||||
body.parse_mode = 'HTML'
|
||||
}
|
||||
|
||||
return body
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!data.ok) {
|
||||
const errorMessage = data.description || data.error || 'Failed to send photo'
|
||||
throw new Error(errorMessage)
|
||||
}
|
||||
|
||||
const result = data.result as TelegramPhoto
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
message: 'Photo sent successfully',
|
||||
data: result,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
message: { type: 'string', description: 'Success or error message' },
|
||||
data: {
|
||||
type: 'object',
|
||||
description: 'Telegram message data including optional photo(s)',
|
||||
properties: {
|
||||
message_id: {
|
||||
type: 'number',
|
||||
description: 'Unique Telegram message identifier',
|
||||
},
|
||||
from: {
|
||||
type: 'object',
|
||||
description: 'Chat information',
|
||||
properties: {
|
||||
id: { type: 'number', description: 'Chat ID' },
|
||||
is_bot: {
|
||||
type: 'boolean',
|
||||
description: 'Whether the chat is a bot or not',
|
||||
},
|
||||
first_name: {
|
||||
type: 'string',
|
||||
description: 'Chat username (if available)',
|
||||
},
|
||||
username: {
|
||||
type: 'string',
|
||||
description: 'Chat title (for groups and channels)',
|
||||
},
|
||||
},
|
||||
},
|
||||
chat: {
|
||||
type: 'object',
|
||||
description: 'Information about the bot that sent the message',
|
||||
properties: {
|
||||
id: { type: 'number', description: 'Bot user ID' },
|
||||
first_name: { type: 'string', description: 'Bot first name' },
|
||||
username: { type: 'string', description: 'Bot username' },
|
||||
type: {
|
||||
type: 'string',
|
||||
description: 'Chat type (private, group, supergroup, channel)',
|
||||
},
|
||||
},
|
||||
},
|
||||
date: {
|
||||
type: 'number',
|
||||
description: 'Unix timestamp when message was sent',
|
||||
},
|
||||
text: {
|
||||
type: 'string',
|
||||
description: 'Text content of the sent message (if applicable)',
|
||||
},
|
||||
photo: {
|
||||
type: 'array',
|
||||
description: 'List of photos included in the message',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
file_id: {
|
||||
type: 'string',
|
||||
description: 'Unique file ID of the photo',
|
||||
},
|
||||
file_unique_id: {
|
||||
type: 'string',
|
||||
description: 'Unique identifier for this file across different bots',
|
||||
},
|
||||
file_size: {
|
||||
type: 'number',
|
||||
description: 'Size of the photo file in bytes',
|
||||
},
|
||||
width: { type: 'number', description: 'Photo width in pixels' },
|
||||
height: { type: 'number', description: 'Photo height in pixels' },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
import { ErrorExtractorId } from '@/tools/error-extractors'
|
||||
import type {
|
||||
TelegramMessage,
|
||||
TelegramSendMessageResponse,
|
||||
TelegramSendPollParams,
|
||||
} from '@/tools/telegram/types'
|
||||
import { telegramApiUrl } from '@/tools/telegram/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
/**
|
||||
* Normalize poll options into a trimmed string array. Accepts an array, a JSON
|
||||
* array string, or a newline-separated string (the `json`-typed param can arrive
|
||||
* in any of these forms from block inputs or agent tool-calls).
|
||||
*/
|
||||
function normalizePollOptions(value: unknown): string[] {
|
||||
let items: unknown[] = []
|
||||
if (Array.isArray(value)) {
|
||||
items = value
|
||||
} else if (typeof value === 'string') {
|
||||
const trimmed = value.trim()
|
||||
try {
|
||||
const parsed = JSON.parse(trimmed)
|
||||
items = Array.isArray(parsed) ? parsed : trimmed.split('\n')
|
||||
} catch {
|
||||
items = trimmed.split('\n')
|
||||
}
|
||||
}
|
||||
return items.map((item) => String(item).trim()).filter(Boolean)
|
||||
}
|
||||
|
||||
export const telegramSendPollTool: ToolConfig<TelegramSendPollParams, TelegramSendMessageResponse> =
|
||||
{
|
||||
id: 'telegram_send_poll',
|
||||
name: 'Telegram Send Poll',
|
||||
description: 'Send a native poll to a Telegram chat through the Telegram Bot API.',
|
||||
version: '1.0.0',
|
||||
errorExtractor: ErrorExtractorId.TELEGRAM_DESCRIPTION,
|
||||
|
||||
params: {
|
||||
botToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Telegram Bot API Token',
|
||||
},
|
||||
chatId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Telegram chat ID (numeric, can be negative for groups)',
|
||||
},
|
||||
question: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Poll question (1-300 characters)',
|
||||
},
|
||||
options: {
|
||||
type: 'json',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'List of 2-10 answer options as text strings',
|
||||
},
|
||||
isAnonymous: {
|
||||
type: 'boolean',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Whether the poll needs to be anonymous (defaults to true)',
|
||||
},
|
||||
allowsMultipleAnswers: {
|
||||
type: 'boolean',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Whether the poll allows multiple answers',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params) => telegramApiUrl(params.botToken, 'sendPoll'),
|
||||
method: 'POST',
|
||||
headers: () => ({
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
body: (params) => {
|
||||
const optionList = normalizePollOptions(params.options)
|
||||
if (optionList.length < 2) {
|
||||
throw new Error('A poll requires at least 2 options')
|
||||
}
|
||||
const body: Record<string, unknown> = {
|
||||
chat_id: params.chatId,
|
||||
question: params.question,
|
||||
options: optionList.map((text) => ({ text })),
|
||||
}
|
||||
if (params.isAnonymous !== undefined) body.is_anonymous = params.isAnonymous
|
||||
if (params.allowsMultipleAnswers !== undefined) {
|
||||
body.allows_multiple_answers = params.allowsMultipleAnswers
|
||||
}
|
||||
return body
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!data.ok) {
|
||||
const errorMessage = data.description || data.error || 'Failed to send poll'
|
||||
throw new Error(errorMessage)
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
message: 'Poll sent successfully',
|
||||
data: data.result as TelegramMessage,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
message: { type: 'string', description: 'Success or error message' },
|
||||
data: {
|
||||
type: 'object',
|
||||
description: 'Telegram message data for the sent poll',
|
||||
properties: {
|
||||
message_id: { type: 'number', description: 'Unique Telegram message identifier' },
|
||||
date: { type: 'number', description: 'Unix timestamp when message was sent' },
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
import { ErrorExtractorId } from '@/tools/error-extractors'
|
||||
import type {
|
||||
TelegramMedia,
|
||||
TelegramSendMediaResponse,
|
||||
TelegramSendVideoParams,
|
||||
} from '@/tools/telegram/types'
|
||||
import { convertMarkdownToHTML } from '@/tools/telegram/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const telegramSendVideoTool: ToolConfig<TelegramSendVideoParams, TelegramSendMediaResponse> =
|
||||
{
|
||||
id: 'telegram_send_video',
|
||||
name: 'Telegram Send Video',
|
||||
description: 'Send videos to Telegram channels or users through the Telegram Bot API.',
|
||||
version: '1.0.0',
|
||||
errorExtractor: ErrorExtractorId.TELEGRAM_DESCRIPTION,
|
||||
|
||||
params: {
|
||||
botToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Telegram Bot API Token',
|
||||
},
|
||||
chatId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Telegram chat ID (numeric, can be negative for groups)',
|
||||
},
|
||||
video: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Video to send. Pass a file_id or HTTP URL',
|
||||
},
|
||||
caption: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Video caption (optional)',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: TelegramSendVideoParams) =>
|
||||
`https://api.telegram.org/bot${params.botToken}/sendVideo`,
|
||||
method: 'POST',
|
||||
headers: () => ({
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
body: (params: TelegramSendVideoParams) => {
|
||||
const body: Record<string, any> = {
|
||||
chat_id: params.chatId,
|
||||
video: params.video,
|
||||
}
|
||||
|
||||
if (params.caption) {
|
||||
body.caption = convertMarkdownToHTML(params.caption)
|
||||
body.parse_mode = 'HTML'
|
||||
}
|
||||
|
||||
return body
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!data.ok) {
|
||||
const errorMessage = data.description || data.error || 'Failed to send video'
|
||||
throw new Error(errorMessage)
|
||||
}
|
||||
|
||||
const result = data.result as TelegramMedia
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
message: 'Video sent successfully',
|
||||
data: result,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
message: { type: 'string', description: 'Success or error message' },
|
||||
data: {
|
||||
type: 'object',
|
||||
description: 'Telegram message data including optional media',
|
||||
properties: {
|
||||
message_id: {
|
||||
type: 'number',
|
||||
description: 'Unique Telegram message identifier',
|
||||
},
|
||||
from: {
|
||||
type: 'object',
|
||||
description: 'Information about the sender',
|
||||
properties: {
|
||||
id: { type: 'number', description: 'Sender ID' },
|
||||
is_bot: {
|
||||
type: 'boolean',
|
||||
description: 'Whether the chat is a bot or not',
|
||||
},
|
||||
first_name: {
|
||||
type: 'string',
|
||||
description: "Sender's first name (if available)",
|
||||
},
|
||||
username: {
|
||||
type: 'string',
|
||||
description: "Sender's username (if available)",
|
||||
},
|
||||
},
|
||||
},
|
||||
chat: {
|
||||
type: 'object',
|
||||
description: 'Information about the chat where message was sent',
|
||||
properties: {
|
||||
id: { type: 'number', description: 'Chat ID' },
|
||||
first_name: {
|
||||
type: 'string',
|
||||
description: 'Chat first name (if private chat)',
|
||||
},
|
||||
username: {
|
||||
type: 'string',
|
||||
description: 'Chat username (for private or channels)',
|
||||
},
|
||||
type: {
|
||||
type: 'string',
|
||||
description: 'Type of chat (private, group, supergroup, or channel)',
|
||||
},
|
||||
},
|
||||
},
|
||||
date: {
|
||||
type: 'number',
|
||||
description: 'Unix timestamp when the message was sent',
|
||||
},
|
||||
text: {
|
||||
type: 'string',
|
||||
description: 'Text content of the sent message (if applicable)',
|
||||
},
|
||||
format: {
|
||||
type: 'object',
|
||||
description: 'Media format information (for videos, GIFs, etc.)',
|
||||
properties: {
|
||||
file_name: { type: 'string', description: 'Media file name' },
|
||||
mime_type: { type: 'string', description: 'Media MIME type' },
|
||||
duration: {
|
||||
type: 'number',
|
||||
description: 'Duration of media in seconds',
|
||||
},
|
||||
width: { type: 'number', description: 'Media width in pixels' },
|
||||
height: { type: 'number', description: 'Media height in pixels' },
|
||||
thumbnail: {
|
||||
type: 'object',
|
||||
description: 'Thumbnail image details',
|
||||
properties: {
|
||||
file_id: { type: 'string', description: 'Thumbnail file ID' },
|
||||
file_unique_id: {
|
||||
type: 'string',
|
||||
description: 'Unique thumbnail file identifier',
|
||||
},
|
||||
file_size: {
|
||||
type: 'number',
|
||||
description: 'Thumbnail file size in bytes',
|
||||
},
|
||||
width: {
|
||||
type: 'number',
|
||||
description: 'Thumbnail width in pixels',
|
||||
},
|
||||
height: {
|
||||
type: 'number',
|
||||
description: 'Thumbnail height in pixels',
|
||||
},
|
||||
},
|
||||
},
|
||||
thumb: {
|
||||
type: 'object',
|
||||
description: 'Secondary thumbnail details (duplicate of thumbnail)',
|
||||
properties: {
|
||||
file_id: { type: 'string', description: 'Thumbnail file ID' },
|
||||
file_unique_id: {
|
||||
type: 'string',
|
||||
description: 'Unique thumbnail file identifier',
|
||||
},
|
||||
file_size: {
|
||||
type: 'number',
|
||||
description: 'Thumbnail file size in bytes',
|
||||
},
|
||||
width: {
|
||||
type: 'number',
|
||||
description: 'Thumbnail width in pixels',
|
||||
},
|
||||
height: {
|
||||
type: 'number',
|
||||
description: 'Thumbnail height in pixels',
|
||||
},
|
||||
},
|
||||
},
|
||||
file_id: { type: 'string', description: 'Media file ID' },
|
||||
file_unique_id: {
|
||||
type: 'string',
|
||||
description: 'Unique media file identifier',
|
||||
},
|
||||
file_size: {
|
||||
type: 'number',
|
||||
description: 'Size of media file in bytes',
|
||||
},
|
||||
},
|
||||
},
|
||||
document: {
|
||||
type: 'object',
|
||||
description: 'Document file details if the message contains a document',
|
||||
properties: {
|
||||
file_name: { type: 'string', description: 'Document file name' },
|
||||
mime_type: { type: 'string', description: 'Document MIME type' },
|
||||
thumbnail: {
|
||||
type: 'object',
|
||||
description: 'Document thumbnail information',
|
||||
properties: {
|
||||
file_id: { type: 'string', description: 'Thumbnail file ID' },
|
||||
file_unique_id: {
|
||||
type: 'string',
|
||||
description: 'Unique thumbnail file identifier',
|
||||
},
|
||||
file_size: {
|
||||
type: 'number',
|
||||
description: 'Thumbnail file size in bytes',
|
||||
},
|
||||
width: {
|
||||
type: 'number',
|
||||
description: 'Thumbnail width in pixels',
|
||||
},
|
||||
height: {
|
||||
type: 'number',
|
||||
description: 'Thumbnail height in pixels',
|
||||
},
|
||||
},
|
||||
},
|
||||
thumb: {
|
||||
type: 'object',
|
||||
description: 'Duplicate thumbnail info (used for compatibility)',
|
||||
properties: {
|
||||
file_id: { type: 'string', description: 'Thumbnail file ID' },
|
||||
file_unique_id: {
|
||||
type: 'string',
|
||||
description: 'Unique thumbnail file identifier',
|
||||
},
|
||||
file_size: {
|
||||
type: 'number',
|
||||
description: 'Thumbnail file size in bytes',
|
||||
},
|
||||
width: {
|
||||
type: 'number',
|
||||
description: 'Thumbnail width in pixels',
|
||||
},
|
||||
height: {
|
||||
type: 'number',
|
||||
description: 'Thumbnail height in pixels',
|
||||
},
|
||||
},
|
||||
},
|
||||
file_id: { type: 'string', description: 'Document file ID' },
|
||||
file_unique_id: {
|
||||
type: 'string',
|
||||
description: 'Unique document file identifier',
|
||||
},
|
||||
file_size: {
|
||||
type: 'number',
|
||||
description: 'Size of document file in bytes',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
import { ErrorExtractorId } from '@/tools/error-extractors'
|
||||
import type {
|
||||
TelegramBooleanResponse,
|
||||
TelegramSetMessageReactionParams,
|
||||
} from '@/tools/telegram/types'
|
||||
import { telegramApiUrl } from '@/tools/telegram/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const telegramSetMessageReactionTool: ToolConfig<
|
||||
TelegramSetMessageReactionParams,
|
||||
TelegramBooleanResponse
|
||||
> = {
|
||||
id: 'telegram_set_message_reaction',
|
||||
name: 'Telegram Set Message Reaction',
|
||||
description:
|
||||
'Set or remove an emoji reaction on a message in a Telegram chat through the Telegram Bot API.',
|
||||
version: '1.0.0',
|
||||
errorExtractor: ErrorExtractorId.TELEGRAM_DESCRIPTION,
|
||||
|
||||
params: {
|
||||
botToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Telegram Bot API Token',
|
||||
},
|
||||
chatId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Telegram chat ID (numeric, can be negative for groups)',
|
||||
},
|
||||
messageId: {
|
||||
type: 'number',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Identifier of the target message',
|
||||
},
|
||||
reaction: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Emoji to react with (leave empty to remove the reaction)',
|
||||
},
|
||||
isBig: {
|
||||
type: 'boolean',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Pass true to show the reaction with a big animation',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params) => telegramApiUrl(params.botToken, 'setMessageReaction'),
|
||||
method: 'POST',
|
||||
headers: () => ({
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
body: (params) => {
|
||||
const body: Record<string, unknown> = {
|
||||
chat_id: params.chatId,
|
||||
message_id: params.messageId,
|
||||
reaction: params.reaction ? [{ type: 'emoji', emoji: params.reaction }] : [],
|
||||
}
|
||||
if (params.isBig !== undefined) body.is_big = params.isBig
|
||||
return body
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!data.ok) {
|
||||
const errorMessage = data.description || data.error || 'Failed to set message reaction'
|
||||
throw new Error(errorMessage)
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
message: 'Message reaction set successfully',
|
||||
data: {
|
||||
ok: data.ok,
|
||||
result: data.result,
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
message: { type: 'string', description: 'Success or error message' },
|
||||
data: {
|
||||
type: 'object',
|
||||
description: 'Reaction operation result',
|
||||
properties: {
|
||||
ok: { type: 'boolean', description: 'API response success status' },
|
||||
result: { type: 'boolean', description: 'Whether the reaction was set' },
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,310 @@
|
||||
import type { UserFile } from '@/executor/types'
|
||||
import type { ToolFileData, ToolResponse } from '@/tools/types'
|
||||
|
||||
export interface TelegramMessage {
|
||||
message_id: number
|
||||
from: {
|
||||
id: number
|
||||
is_bot: boolean
|
||||
first_name?: string
|
||||
username?: string
|
||||
}
|
||||
chat?: {
|
||||
id: number
|
||||
first_name?: string
|
||||
username?: string
|
||||
type?: string
|
||||
}
|
||||
date: number
|
||||
text?: string
|
||||
}
|
||||
|
||||
export interface TelegramAudio extends TelegramMessage {
|
||||
voice: {
|
||||
duration: 2
|
||||
mime_type: string
|
||||
file_id: string
|
||||
file_unique_id: string
|
||||
file_size: number
|
||||
}
|
||||
}
|
||||
|
||||
export interface TelegramPhoto extends TelegramMessage {
|
||||
photo?: {
|
||||
file_id: string
|
||||
file_unique_id: string
|
||||
file_size: number
|
||||
width: number
|
||||
height: number
|
||||
}
|
||||
}
|
||||
|
||||
export interface TelegramMedia extends TelegramMessage {
|
||||
format?: {
|
||||
file_name: string
|
||||
mime_type: string
|
||||
duration: number
|
||||
width: number
|
||||
height: number
|
||||
thumbnail: {
|
||||
file_id: string
|
||||
file_unique_id: string
|
||||
file_size: number
|
||||
width: number
|
||||
height: number
|
||||
}
|
||||
thumb: {
|
||||
file_id: string
|
||||
file_unique_id: string
|
||||
file_size: number
|
||||
width: number
|
||||
height: number
|
||||
}
|
||||
file_id: string
|
||||
file_unique_id: string
|
||||
file_size: number
|
||||
}
|
||||
document?: {
|
||||
file_name: string
|
||||
mime_type: string
|
||||
thumbnail: {
|
||||
file_id: string
|
||||
file_unique_id: string
|
||||
file_size: number
|
||||
width: number
|
||||
height: number
|
||||
}
|
||||
thumb: {
|
||||
file_id: string
|
||||
file_unique_id: string
|
||||
file_size: number
|
||||
width: number
|
||||
height: number
|
||||
}
|
||||
file_id: string
|
||||
file_unique_id: string
|
||||
file_size: number
|
||||
}
|
||||
}
|
||||
|
||||
interface TelegramAuthParams {
|
||||
botToken: string
|
||||
chatId: string
|
||||
}
|
||||
|
||||
export interface TelegramSendMessageParams extends TelegramAuthParams {
|
||||
text: string
|
||||
}
|
||||
|
||||
export interface TelegramSendPhotoParams extends TelegramAuthParams {
|
||||
photo: string
|
||||
caption?: string
|
||||
}
|
||||
|
||||
export interface TelegramSendVideoParams extends TelegramAuthParams {
|
||||
video: string
|
||||
caption?: string
|
||||
}
|
||||
|
||||
export interface TelegramSendAudioParams extends TelegramAuthParams {
|
||||
audio: string
|
||||
caption?: string
|
||||
}
|
||||
|
||||
export interface TelegramSendAnimationParams extends TelegramAuthParams {
|
||||
animation: string
|
||||
caption?: string
|
||||
}
|
||||
|
||||
export interface TelegramSendDocumentParams extends TelegramAuthParams {
|
||||
files?: UserFile[]
|
||||
caption?: string
|
||||
}
|
||||
|
||||
export interface TelegramDeleteMessageParams extends TelegramAuthParams {
|
||||
messageId: number
|
||||
}
|
||||
|
||||
export interface TelegramEditMessageTextParams extends TelegramAuthParams {
|
||||
messageId: number
|
||||
text: string
|
||||
}
|
||||
|
||||
export interface TelegramForwardMessageParams extends TelegramAuthParams {
|
||||
fromChatId: string
|
||||
messageId: number
|
||||
}
|
||||
|
||||
export interface TelegramCopyMessageParams extends TelegramAuthParams {
|
||||
fromChatId: string
|
||||
messageId: number
|
||||
caption?: string
|
||||
}
|
||||
|
||||
export interface TelegramSendLocationParams extends TelegramAuthParams {
|
||||
latitude: number
|
||||
longitude: number
|
||||
}
|
||||
|
||||
export interface TelegramSendContactParams extends TelegramAuthParams {
|
||||
phoneNumber: string
|
||||
firstName: string
|
||||
lastName?: string
|
||||
vcard?: string
|
||||
}
|
||||
|
||||
export interface TelegramSendPollParams extends TelegramAuthParams {
|
||||
question: string
|
||||
options: string[]
|
||||
isAnonymous?: boolean
|
||||
allowsMultipleAnswers?: boolean
|
||||
}
|
||||
|
||||
export interface TelegramPinMessageParams extends TelegramAuthParams {
|
||||
messageId: number
|
||||
disableNotification?: boolean
|
||||
}
|
||||
|
||||
export interface TelegramUnpinMessageParams extends TelegramAuthParams {
|
||||
messageId?: number
|
||||
}
|
||||
|
||||
export interface TelegramSetMessageReactionParams extends TelegramAuthParams {
|
||||
messageId: number
|
||||
reaction?: string
|
||||
isBig?: boolean
|
||||
}
|
||||
|
||||
export interface TelegramSendChatActionParams extends TelegramAuthParams {
|
||||
action: string
|
||||
}
|
||||
|
||||
export type TelegramGetChatParams = TelegramAuthParams
|
||||
|
||||
export interface TelegramGetChatMemberParams extends TelegramAuthParams {
|
||||
userId: number
|
||||
}
|
||||
|
||||
export interface TelegramChatFullInfo {
|
||||
id: number
|
||||
type: string
|
||||
title?: string
|
||||
username?: string
|
||||
first_name?: string
|
||||
last_name?: string
|
||||
description?: string
|
||||
bio?: string
|
||||
invite_link?: string
|
||||
linked_chat_id?: number
|
||||
}
|
||||
|
||||
export interface TelegramUser {
|
||||
id: number
|
||||
is_bot: boolean
|
||||
first_name?: string
|
||||
last_name?: string
|
||||
username?: string
|
||||
}
|
||||
|
||||
export interface TelegramChatMember {
|
||||
status: string
|
||||
user: TelegramUser
|
||||
}
|
||||
|
||||
export interface TelegramSendMessageResponse extends ToolResponse {
|
||||
output: {
|
||||
message: string
|
||||
data?: TelegramMessage
|
||||
}
|
||||
}
|
||||
|
||||
export interface TelegramSendMediaResponse extends ToolResponse {
|
||||
output: {
|
||||
message: string
|
||||
data?: TelegramMedia
|
||||
}
|
||||
}
|
||||
|
||||
export interface TelegramSendAudioResponse extends ToolResponse {
|
||||
output: {
|
||||
message: string
|
||||
data?: TelegramAudio
|
||||
}
|
||||
}
|
||||
|
||||
export interface TelegramDeleteMessageResponse extends ToolResponse {
|
||||
output: {
|
||||
message: string
|
||||
data?: {
|
||||
ok: boolean
|
||||
deleted: boolean
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export interface TelegramSendPhotoResponse extends ToolResponse {
|
||||
output: {
|
||||
message: string
|
||||
data?: TelegramPhoto
|
||||
}
|
||||
}
|
||||
|
||||
export interface TelegramSendDocumentResponse extends ToolResponse {
|
||||
output: {
|
||||
message: string
|
||||
data?: TelegramMedia
|
||||
files?: ToolFileData[]
|
||||
}
|
||||
}
|
||||
|
||||
export interface TelegramCopyMessageResponse extends ToolResponse {
|
||||
output: {
|
||||
message: string
|
||||
data?: {
|
||||
message_id: number
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export interface TelegramBooleanResponse extends ToolResponse {
|
||||
output: {
|
||||
message: string
|
||||
data?: {
|
||||
ok: boolean
|
||||
result: boolean
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export interface TelegramGetChatResponse extends ToolResponse {
|
||||
output: {
|
||||
message: string
|
||||
data?: TelegramChatFullInfo
|
||||
}
|
||||
}
|
||||
|
||||
export interface TelegramGetChatMemberResponse extends ToolResponse {
|
||||
output: {
|
||||
message: string
|
||||
data?: TelegramChatMember
|
||||
}
|
||||
}
|
||||
|
||||
export type TelegramResponse =
|
||||
| TelegramSendMessageResponse
|
||||
| TelegramSendPhotoResponse
|
||||
| TelegramSendAudioResponse
|
||||
| TelegramSendMediaResponse
|
||||
| TelegramSendDocumentResponse
|
||||
| TelegramDeleteMessageResponse
|
||||
| TelegramCopyMessageResponse
|
||||
| TelegramBooleanResponse
|
||||
| TelegramGetChatResponse
|
||||
| TelegramGetChatMemberResponse
|
||||
|
||||
// Legacy type for backwards compatibility
|
||||
interface TelegramMessageParams {
|
||||
botToken: string
|
||||
chatId: string
|
||||
text: string
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
import { ErrorExtractorId } from '@/tools/error-extractors'
|
||||
import type { TelegramBooleanResponse, TelegramUnpinMessageParams } from '@/tools/telegram/types'
|
||||
import { telegramApiUrl } from '@/tools/telegram/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const telegramUnpinMessageTool: ToolConfig<
|
||||
TelegramUnpinMessageParams,
|
||||
TelegramBooleanResponse
|
||||
> = {
|
||||
id: 'telegram_unpin_message',
|
||||
name: 'Telegram Unpin Message',
|
||||
description:
|
||||
'Unpin a pinned message in a Telegram chat through the Telegram Bot API. Unpins the most recent pinned message when no message ID is given.',
|
||||
version: '1.0.0',
|
||||
errorExtractor: ErrorExtractorId.TELEGRAM_DESCRIPTION,
|
||||
|
||||
params: {
|
||||
botToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Telegram Bot API Token',
|
||||
},
|
||||
chatId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Telegram chat ID (numeric, can be negative for groups)',
|
||||
},
|
||||
messageId: {
|
||||
type: 'number',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Identifier of the message to unpin (omit to unpin the most recent one)',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params) => telegramApiUrl(params.botToken, 'unpinChatMessage'),
|
||||
method: 'POST',
|
||||
headers: () => ({
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
body: (params) => {
|
||||
const body: Record<string, unknown> = {
|
||||
chat_id: params.chatId,
|
||||
}
|
||||
if (params.messageId !== undefined) body.message_id = params.messageId
|
||||
return body
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!data.ok) {
|
||||
const errorMessage = data.description || data.error || 'Failed to unpin message'
|
||||
throw new Error(errorMessage)
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
message: 'Message unpinned successfully',
|
||||
data: {
|
||||
ok: data.ok,
|
||||
result: data.result,
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
message: { type: 'string', description: 'Success or error message' },
|
||||
data: {
|
||||
type: 'object',
|
||||
description: 'Unpin operation result',
|
||||
properties: {
|
||||
ok: { type: 'boolean', description: 'API response success status' },
|
||||
result: { type: 'boolean', description: 'Whether the message was unpinned' },
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Build a Telegram Bot API method URL for the given bot token.
|
||||
*/
|
||||
export function telegramApiUrl(botToken: string, method: string): string {
|
||||
return `https://api.telegram.org/bot${botToken}/${method}`
|
||||
}
|
||||
|
||||
export function convertMarkdownToHTML(text: string): string {
|
||||
return (
|
||||
text
|
||||
// Bold: **text** or __text__ -> <b>text</b>
|
||||
.replace(/\*\*(.*?)\*\*/g, '<b>$1</b>')
|
||||
.replace(/__(.*?)__/g, '<b>$1</b>')
|
||||
// Italic: *text* or _text_ -> <i>text</i>
|
||||
.replace(/\*(.*?)\*/g, '<i>$1</i>')
|
||||
.replace(/_(.*?)_/g, '<i>$1</i>')
|
||||
// Code: `text` -> <code>text</code>
|
||||
.replace(/`(.*?)`/g, '<code>$1</code>')
|
||||
// Links: [text](url) -> <a href="url">text</a>
|
||||
.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2">$1</a>')
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user